template <class T>
class NoDestructor
Defined at line 39 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
The NoDestructor
<
> class wraps another object type, preventing its destructor
from running.
The typical use-case of this is to allow static variables to be defined while
avoiding their destructors from being called at program exit:
Object
&
MyFunction() {
// Allocate `Object` lazily on first access, in a thread-safe manner (since C++11).
static fbl::NoDestructor
<Object
> object(args);
// Use the allocated object.
object->foo = 1;
object->Bar();
// Because the object is allocated from static storage, it is safe
// to return references to the object from the function.
return *object;
}
Without the `fbl::NoDestructor
<
>` above, the destructor of Object will be
called at an unclear time a program termination.
In contrast, using `fbl::NoDestructor` results in the object surviving
until program exit, avoiding potential ordering issues during program
shutdown and reducing code bloat.
Public Methods
template <typename... Args>
void NoDestructor<T> (Args &&... args)
Construct the underlying object "T".
Defined at line 43 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
void NoDestructor<T> (const NoDestructor<T> & other)
Disable copy/move construction from fbl::NoDestructor.
Defined at line 48 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
NoDestructor<T> & operator= (const NoDestructor<T> & other)
Defined at line 49 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
void NoDestructor<T> (const T & value)
Allow copy/move construction from "T".
Defined at line 52 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
void NoDestructor<T> (T && value)
Defined at line 55 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
T * get ()
Get the internal object.
Defined at line 60 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
const T * get ()
Defined at line 61 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
T & operator* ()
Pointer syntax.
Defined at line 64 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
T * operator-> ()
Defined at line 65 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
const T & operator* ()
Defined at line 66 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h
const T * operator-> ()
Defined at line 67 of file ../../zircon/system/ulib/fbl/include/fbl/no_destructor.h