template <typename T>
rll::singleton struct

Singleton pattern trait.

Template parameters
T Class type.

Allows to use Singleton pattern in custom types and classes. Example declaration:

class TestSingleton : public rll::singleton<TestSingleton>
{
  friend struct rll::singleton<TestSingleton>;

 public:
  ~TestSingleton() = default;

  [[nodiscard]] auto add(int a, int b) const -> int { return a + b; }

 private:
  TestSingleton() = default;
};

Example usage:

TestSingleton::ref().add(1, 2);
TestSingleton::ref_mut().add(1, 2);
TestSingleton::ptr()->add(1, 2);
TestSingleton::ptr_mut()->add(1, 2);

Base classes

struct pin
Disallows copy and move operations for a type.

Public static functions

static auto ptr() →  T const* noexcept
Returns pointer to the singleton instance.
static auto ptr_mut() →  T* noexcept
Returns mutable pointer to the singleton instance.
static auto ref() →  T const& noexcept
Returns constant reference to the singleton instance.
static auto ref_mut() →  T& noexcept
Returns mutable reference to the singleton instance.

Constructors, destructors, conversion operators

singleton() defaulted

Function documentation

template <typename T>
static T const* rll::singleton::ptr() noexcept

Returns pointer to the singleton instance.

Returns Pointer to the singleton instance.

template <typename T>
static T* rll::singleton::ptr_mut() noexcept

Returns mutable pointer to the singleton instance.

Returns Mutable pointer to the singleton instance.

template <typename T>
static T const& rll::singleton::ref() noexcept

Returns constant reference to the singleton instance.

Returns Constant reference to the singleton instance.

template <typename T>
static T& rll::singleton::ref_mut() noexcept

Returns mutable reference to the singleton instance.

Returns Mutable reference to the singleton instance.