singleton: add swap modifier

This commit is contained in:
Danny Robson 2019-05-01 12:31:08 +10:00
parent c01aa64b32
commit ed8db05fed

View File

@ -49,6 +49,22 @@ namespace cruft {
}
/// Swap the stored object pointer for the provided one and return
/// the old value.
///
/// Useful for bypassing `instantiate` by initialising the pointer
/// to a pre-existing object.
///
/// The caller to swap must free any resources associated with the
/// prior value and arrange for the new object to be safely destructed
/// in the future.
static SelfT*
swap (SelfT *next)
{
return std::exchange (instance, next);
}
/// returns a reference to sole instantiated value
///
/// `instantiate` must have already been called before `get` is called.