Template Class Singleton

Inheritance Relationships

Derived Types

Class Documentation

template<class Type>
class Singleton

CE::State::Singleton (Compile Time Safe) For simple singleton creation.

You can keep inheriting these all you want, it will always be the same instance they point to. Uses static_assert verifying constructibility - requires public constructor(s) initialize(args…) accepts exactly one successful explicit initialization; repeated calls reject. Configure argument-bearing instances on their owner thread before starting producers. get(args…) remains a compatibility accessor: the first successful construction wins and later arguments are ignored. get() constructs a default-constructible Type, otherwise it only retrieves a published instance. A failed constructor publishes nothing and permits retry. Nonconstructing reads never wait for construction. Construction/publication is synchronized; Type’s later operations require its own thread-safety contract. Returned pointers/references borrow process-lifetime storage, not ownership. Quiesce all callers before static destruction; neither get_existing() nor a successful read pins an instance against teardown.

Subclassed by CE::Memory::Manager< 2.0, 4096 >, CE::Memory::Manager< 1.0, 0 >, CE::Memory::Manager< 4.0, 4096 >, CE::Memory::Manager< 1.29, sizeof(T) *64 >

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.

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.