theCore C++ embedded framework
ecl::safe_storage< T > Struct Template Reference

Safe storage wrapper to avoid static initialization fiasco. More...

#include </home/travis/build/forGGe/theCore/lib/utils/export/ecl/utils.hpp>

Public Member Functions

template<class ... Args>
void init (Args &&...args)
 Initializes storage. More...
 
void deinit ()
 Deinitializes storage. More...
 
T & get ()
 Gets reference to the stored object. More...
 
const T & get () const
 Gets const reference to the stored object. More...
 

Data Fields

std::aligned_storage_t< sizeof(T), alignof(T)> m_stor
 Storage for the T object. More...
 

Detailed Description

template<class T>
struct ecl::safe_storage< T >

Safe storage wrapper to avoid static initialization fiasco.

Template Parameters
Tnon-POD type to protect against implicit constructor call during static initialization

Member Function Documentation

◆ init()

template<class T>
template<class ... Args>
void ecl::safe_storage< T >::init ( Args &&...  args)
inline

Initializes storage.

Template Parameters
ArgsTypes of the constructor args.
Parameters
argsT's ctor arguments.
Precondition
Storage not yet initialized, i.e. ctor wasn't called yet or storage was deinitialized earlier.
Postcondition
Storage initialized and object is ready to work.
Note
Violating pre-conditions leads to undefined behaviour.

◆ deinit()

template<class T>
void ecl::safe_storage< T >::deinit ( )
inline

Deinitializes storage.

Precondition
Storage is initialized.
Postcondition
Storage is deinitialized and stored object is destructed.
Note
Violating pre-conditions leads to undefined behaviour.

◆ get() [1/2]

template<class T>
T& ecl::safe_storage< T >::get ( )
inline

Gets reference to the stored object.

Precondition
Storage initialized, i.e. init() was called once.

◆ get() [2/2]

template<class T>
const T& ecl::safe_storage< T >::get ( ) const
inline

Gets const reference to the stored object.

Precondition
Storage initialized, i.e. init() was called once.

Field Documentation

◆ m_stor

template<class T>
std::aligned_storage_t<sizeof(T), alignof(T)> ecl::safe_storage< T >::m_stor

Storage for the T object.


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