flatten 20260225
This commit is contained in:
70
tjp/core/containers/PtrOrValue.hpp
Executable file
70
tjp/core/containers/PtrOrValue.hpp
Executable file
@@ -0,0 +1,70 @@
|
||||
// License: Modified MIT (NON-AI)
|
||||
// See the LICENSE file in the root directory for license information.
|
||||
// Copyright 2025 Timothy Prepscius
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "PtrOrValue.h"
|
||||
|
||||
namespace tjp::core {
|
||||
|
||||
template<typename T>
|
||||
struct PtrOrValue {
|
||||
Optional<T> v;
|
||||
const T *p = nullptr;
|
||||
|
||||
const T *get() const {
|
||||
return v ?
|
||||
&*v :
|
||||
p;
|
||||
}
|
||||
|
||||
PtrOrValue(const T &v_) :
|
||||
v(v_) {}
|
||||
|
||||
PtrOrValue(T &&v_) :
|
||||
v(std::move(v_)) {}
|
||||
|
||||
PtrOrValue(const T *p_) :
|
||||
p(p_)
|
||||
{}
|
||||
|
||||
PtrOrValue(const PtrOrValue &rhs) :
|
||||
v(rhs.v),
|
||||
p(rhs.p)
|
||||
{}
|
||||
|
||||
PtrOrValue(PtrOrValue &&rhs) :
|
||||
v(std::move(rhs.v)),
|
||||
p(std::move(rhs.p))
|
||||
{}
|
||||
|
||||
auto *operator ->() const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
|
||||
const T &operator *() const
|
||||
{
|
||||
return *get();
|
||||
}
|
||||
|
||||
operator const T&() const
|
||||
{
|
||||
return *get();
|
||||
}
|
||||
} ;
|
||||
|
||||
template<typename T>
|
||||
PtrOrValue<T> makePtrOrValue(const T *t)
|
||||
{
|
||||
return PtrOrValue<T>(t);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
PtrOrValue<T> makePtrOrValue(const T &t)
|
||||
{
|
||||
return PtrOrValue<T>(t);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user