value-object, where the value construction is delayed until first needed (can be handy to avoid c++ include/initializer deadly embrace) More...
#include <LazyInitialized.h>
Public Member Functions | |
LazyInitialized ()=delete | |
nonvirtual constexpr | operator const T () const |
nonvirtual const T | operator() () const |
nonvirtual T * | operator-> () |
value-object, where the value construction is delayed until first needed (can be handy to avoid c++ include/initializer deadly embrace)
Also can be used to 'lazy initialize' facilities that might be costly to setup, but might never be used.
Can be used to initialize a static constant object - declared at file scope - dependent on another file-scope data object, without incurring the pain of static initialization problems (before main). Often this is not needed, if you just make the dependent objects constexpr. But sometimes you cannot do that.
LazyInitialized<T> acts mostly like a T (as much as I could figure out how to).
This object (at least the magic init part) - is fully internally synchronized (though other operations of T itself are in general not).
This object CAN be constructed before main, and accessed before main (after constructed) - but its up to caller to assure the 'oneTimeGetter' is safe to call when called.
So if you have a type T, with method m(), and variable of type T t. Your starter code might be: T t; t.m (); When you replace 'T t' with ConstantProperty<T> t; you must call t().m(); OR you must call t->m();
Definition at line 99 of file LazyInitialized.h.
|
delete |
oneTimeGetter is a function (can be a lambda()) which computes the given value. It is called just once, and LAZILY, the first time the given VirtualConstant value is required.
LazyInitialized (ONE TIME GETTER) - is the normal way to use LazyInitialized LazyInitialized (T) - somewhat pointless, but you can do it.... copy-constructible
|
constexpr |
A LazyInitialized can be automatically assigned to its underlying base type. Due to how conversion operators work, this won't always be helpful (like with overloading or multiple levels of conversions). But when it works (80% of the time) - its helpful.
Definition at line 57 of file LazyInitialized.inl.
const T Stroika::Foundation::Execution::LazyInitialized< T >::operator() | ( | ) | const |
Just use the function syntax, and you get back the initialized value.
Definition at line 62 of file LazyInitialized.inl.
T * Stroika::Foundation::Execution::LazyInitialized< T >::operator-> | ( | ) |
Just use the operator-> syntax, and you get back the wrapper objects value (initializing if needed).
Definition at line 67 of file LazyInitialized.inl.