Public Member Functions | List of all members
LazyValue< T > Class Template Reference

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...
 

Detailed Description

template<typename T>
class Balau::Concurrent::LazyValue< T >

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.

Template Parameters
Tthe variable type (must be default and copy/move constructable)

Constructor & Destructor Documentation

◆ LazyValue()

LazyValue ( std::function< void(T &)>  destruct_ = std::function<void (T &)>())
inlineexplicit

Create a lazy value.

Parameters
destruct_function called in LazyValue's destructor if the construct function was previously called

◆ ~LazyValue()

~LazyValue ( )
inline

Destroy the lazy value instance.

Member Function Documentation

◆ getMutex()

std::mutex& getMutex ( )
inline

Get the internal mutex in order to synchronise on external code.

Use with great care.

Returns
the internal mutex

◆ isConstructed()

bool isConstructed ( ) const
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.

Returns
true if the value has been constructed

◆ operator()()

T& operator() ( std::function< T()>  construct)
inline

Get the value, constructing it by calling the supplied function if necessary.

Returns
the value

The documentation for this class was generated from the following file: