diff --git a/src/hack/patterns/singleton.hpp b/src/hack/patterns/singleton.hpp new file mode 100644 index 0000000..b15c6ae --- /dev/null +++ b/src/hack/patterns/singleton.hpp @@ -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 + struct singleton : public no_move, no_copy + { + static T& instance() + { + static T t; + return t; + } + }; +}