Возможные реализации для решения конкретных задач на С++

Singleton

Шаблон одиночка (Singleton)

template <typename T>
concept NotAbstractClass = is_class_v<T> && !is_abstract_v<T>;


template <typename T>
concept CopyConstructible = requires(T t)
{
	T(t);
};


template <typename T>
concept Assignable = requires(T t1, T t2)
{
	t1 = t2;
};


template <typename T>
concept OnlyObject = NotAbstractClass<T> && !CopyConstructible<T> && !Assignable<T>;
# include <iostream>
# include <memory>

using namespace std;

int main()
{
	decltype(auto) d1 = Singleton<Sun>::instance(1, 2.);
	decltype(auto) d2 = Singleton<Sun>::instance();

	d2.f();
}

Last updated

Was this helpful?