Member variable style lazy setting of a value. More...
#include <LazyValue.hpp>
Public Member Functions | |
LazyValue (std::function< void(T &)> destruct_=std::function< void(T &)>()) | |
Create a lazy value. More... | |
~LazyValue () | |
Destroy the lazy value instance. More... | |
std::mutex & | getMutex () |
Get the internal mutex in order to synchronise on external code. More... | |
bool | isConstructed () const |
Returns true if the value has been constructed. More... | |
T & | operator() (std::function< T()> construct) |
Get the value, constructing it by calling the supplied function if necessary. More... | |
Member variable style lazy setting of a value.
This class can be used instead of static local variable style singleton initialisation when the variable needs to be a instance member of a class. If this is not the case, use static local variable style initialisation instead.
T | the variable type (must be default and copy/move constructable) |
|
inlineexplicit |
Create a lazy value.
destruct_ | function called in LazyValue's destructor if the construct function was previously called |
|
inline |
Destroy the lazy value instance.
|
inline |
Get the internal mutex in order to synchronise on external code.
Use with great care.
|
inline |
Returns true if the value has been constructed.
If the operator () is being concurrently run in other threads whilst this method is called, this method will not necessarily reflect any objective reality to whether the value has been constructed yet. This method should thus only be used when there is no possibility of the operator () being run in other threads, otherwise it will return a meaningless result.
|
inline |
Get the value, constructing it by calling the supplied function if necessary.