// 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 struct PtrOrValue { Optional 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 PtrOrValue makePtrOrValue(const T *t) { return PtrOrValue(t); } template PtrOrValue makePtrOrValue(const T &t) { return PtrOrValue(t); } } // namespace