Created
June 17, 2014 20:13
-
-
Save ThePhD/6193bb87ee7d0678b7f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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