Skip to content

Instantly share code, notes, and snippets.

@ThePhD
Created June 17, 2014 20:13
Show Gist options
  • Save ThePhD/6193bb87ee7d0678b7f0 to your computer and use it in GitHub Desktop.
Save ThePhD/6193bb87ee7d0678b7f0 to your computer and use it in GitHub Desktop.
bool present;
struct storage_t {
T& ref;
} storage;
template <typename... Tn>
void place( Tn&&... argn ) {
assert( !present );
unchecked_place( std::forward<Tn>( argn )... );
}
template <typename... Tn>
void unchecked_place( Tn&&... argn ) {
new ( std::addressof( storage ) ) storage_t( std::forward<Tn>( argn )... );
present = true;
}
void destroy( ) {
assert( present );
unchecked_destroy( );
}
void unchecked_destroy( ) {
storage.~storage_t( );
present = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment