Template Class FriendSingleton
Defined in File singleton.h
Class Documentation
-
template<class Type>
class FriendSingleton CE::State::FriendSingleton (Compile Time Unsafe) For true singleton creation.
i.e. instantiation is private/protected Type must friend CE::State::FriendSingleton<Type> so construction is accessible in this template’s context. Deletion by std::unique_ptr still requires an accessible destructor. The initialization, publication, retry, borrowed-lifetime, and operation contracts are the same as CE::State::Singleton.
Example usage: class Foo : public CE::State::FriendSingleton<Foo> { friend class CE::State::FriendSingleton<Foo>; Foo() = default; // private constructor, can’t be instantiated public: // interface };
Public Static Functions
-
static inline Type *get_existing() noexcept
Declaration:
[[nodiscard]]Observes a published instance without constructing or waiting.
- Returns:
Borrowed pointer or null when no instance is published, including construction in progress. Reads are synchronized; the pointer does not pin storage against process teardown. Later operations obey Type’s own thread contract. Quiesce users before static destruction.
-
template<typename ...Args>
static inline Type &initialize(Args&&... args) Performs exactly one successful explicit initialization.
- Template Parameters:
Args – Constructor argument types; must permit construction in this template’s access context.
- Parameters:
args – Perfect-forwarded only to the winning construction.
- Throws:
CE::Exceptions::bad_request – When another successful construction already won. Constructor failures publish nothing and allow retry. Concurrent construction is serialized; constructors must not recursively initialize/get the same singleton.
- Returns:
Borrowed process-lifetime instance, not an owning reference.
-
template<typename ...Args>
static inline Type &get(Args&&... args) Retrieves the instance, constructing it once when these arguments allow it.
See also
- Template Parameters:
Args – Candidate constructor argument types.
- Parameters:
args – Forwarded on the first successful constructible call; later argument values are ignored.
- Throws:
CE::Exceptions::failed_operation – When no instance is published and construction is unavailable. A default-constructible Type can be constructed by get(); otherwise an argument-free get only observes publication and need not wait for construction in progress. Constructor failures propagate without publication and permit retry. Recursive construction of this same singleton is unsupported.
- Returns:
Borrowed process-lifetime instance. Access does not establish Type’s operation thread safety.
Protected Functions
-
FriendSingleton() = default
Allows a derived singleton wrapper to construct its base without creating Type.
Type must befriend FriendSingleton<Type> for inaccessible construction. The default unique_ptr deleter still requires an accessible Type destructor. This protected constructor performs no publication or allocation.
-
static inline Type *get_existing() noexcept