add singleton pattern

This commit is contained in:
chatlanin 2025-01-13 21:34:48 +03:00
parent 25c7bb059c
commit 096ef69938

View File

@ -0,0 +1,28 @@
#pragma once
namespace hack::patterns
{
struct no_copy
{
no_copy() = default;
no_copy(const no_copy&&) = delete;
no_copy operator=(const no_copy&&) = delete;
};
struct no_move
{
no_move() = default;
no_move(no_move&&) = delete;
no_move operator=(no_move&&) = delete;
};
template<typename T>
struct singleton : public no_move, no_copy
{
static T& instance()
{
static T t;
return t;
}
};
}