dReal4
never_destroyed< T > Class Template Reference

Wraps an underlying type T such that its storage is a direct member field of this object (i.e., without any indirection into the heap), but unlike most member fields T's destructor is never invoked. More...

#include </home/soonhokong/work/dreal4/third_party/com_github_robotlocomotion_drake/dreal/symbolic/never_destroyed.h>

Public Member Functions

 never_destroyed (const never_destroyed &)=delete
 
void operator= (const never_destroyed &)=delete
 
 never_destroyed (never_destroyed &&)=delete
 
void operator= (never_destroyed &&)=delete
 
template<typename... Args>
 never_destroyed (Args &&... args)
 Passes the constructor arguments along to T using perfect forwarding.
 
 ~never_destroyed ()=default
 Does nothing. Guaranteed!
 
T & access ()
 Returns the underlying T reference.
 
const T & access () const
 

Detailed Description

template<typename T>
class dreal::drake::never_destroyed< T >

Wraps an underlying type T such that its storage is a direct member field of this object (i.e., without any indirection into the heap), but unlike most member fields T's destructor is never invoked.

This is especially useful for function-local static variables that are not trivially destructable. We shouldn't call their destructor at program exit because of the "indeterminate order of ... destruction" as mentioned in cppguide's Static_and_Global_Variables section, but other solutions to this problem place the objects on the heap through an indirection.

Compared with other approaches, this mechanism more clearly describes the intent to readers, avoids "possible leak" warnings from memory-checking tools, and is probably slightly faster.


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