13#include "CoreMinimal.h"
43 template <
typename Other>
46 using FunctionStorage = std::conditional_t<CCopyConstructible<T>, TFunction<T()>, TUniqueFunction<T()>>;
48 template <CDefaultInitializable = T>
51 template <CCopyConstructible = T>
52 TValueThunk(T
const& value) : Storage(value), bIsSet(true) {};
54 template <CConvertibleTo<T> Other, CCopyConstructible = T>
56 : bIsSet(other.bIsSet)
57 , Options(other.Options)
58 , Function(other.Function)
60 if (other.bIsSet) Storage = other.Storage;
63 template <CMoveConstructible = T>
66 template <CMoveConstructible = T>
68 : bIsSet(other.bIsSet)
69 , Options(MoveTemp(other.Options))
70 , Function(MoveTemp(other.Function))
72 if (other.bIsSet) Storage = MoveTemp(other.Storage);
75 template <CFunctorObject Functor>
76 requires CConvertibleTo<TFunction_ReturnDecay<Functor>, T>
79 , Function(
FWD(value))
85 if (Function && (!Options.
Memoize || !bIsSet))
94 T&
Get() { Evaluate();
return Storage; }
97 T
const&
Get()
const { Evaluate();
return Storage; }
100 T&&
Steal() && { Evaluate();
return MoveTemp(Storage); }
111 operator T& () {
return Get(); }
112 operator T
const& ()
const {
return Get(); }
113 operator T&& () && {
return Steal(); }
115 bool IsSet()
const {
return bIsSet; }
117 template <CFunctorObject Functor>
118 requires CConvertibleTo<TFunction_ReturnDecay<Functor>, T>
126 template <CConvertibleTo<T> Other>
127 requires (!CIsTemplate<Other, TValueThunk>)
137 mutable T Storage {};
138 mutable bool bIsSet =
false;
139 FValueThunkOptions Options {};
This header exists because STL headers in Android doesn't define STL concepts (other than same_as whi...
#define FWD(...)
Shorten forwarding expression with this macro so one may not need to specify explicit type.
This namespace provides templating utilities and introspection into template instantiations.
Options for value thunks.
bool Memoize
If Memoize is true and associated value thunk is functional, cache the result of the first invocation...
Either a singular value of T, or a function returning T. It's very similar to TAttribute,...
T && StealLast() &&
Move a cached/last result without calling the optional functor.
std::conditional_t< CCopyConstructible< T >, TFunction< T()>, TUniqueFunction< T()> > FunctionStorage
T & Get()
Evaluate the optional functor and get the cached result.
TValueThunk & operator=(Functor &&value)
T const & Get() const
Evaluate the optional functor and get the cached result.
TValueThunk(T const &value)
TValueThunk(TValueThunk< Other > const &other)
TValueThunk(Functor &&value, FValueThunkOptions const &options={})
TValueThunk(TValueThunk &&other)
T && Steal() &&
Evaluate the optional functor and move the cached result.
T const & GetLast() const
Get a cached/last result without calling the optional functor.
T & GetLast()
Get a cached/last result without calling the optional functor.