singleton: add swap modifier
This commit is contained in:
parent
c01aa64b32
commit
ed8db05fed
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user