From 3f559432babb4bc53181881a71085c0473e9ea33 Mon Sep 17 00:00:00 2001 From: chatlanin Date: Sat, 5 Apr 2025 14:24:38 +0300 Subject: [PATCH] add identificato pattern --- bin/main.cpp | 11 +++++++++++ src/hack/patterns/identificator.hpp | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/hack/patterns/identificator.hpp diff --git a/bin/main.cpp b/bin/main.cpp index d3fa687..16dedaa 100644 --- a/bin/main.cpp +++ b/bin/main.cpp @@ -7,6 +7,7 @@ #include "hack/math/max.hpp" #include "hack/patterns/ring_buffer.hpp" +#include "hack/patterns/identificator.hpp" auto main(int argc, char *argv[]) -> int { @@ -25,6 +26,16 @@ auto main(int argc, char *argv[]) -> int hack::log()(v); } + // patterns::identificator + { + struct a : public hack::patterns::identificator<> + {} aa; + a bb; + a cc; + a dd; + hack::log()(aa.m_id, bb.m_id, cc.m_id, dd.m_id); + } + // range::sort { std::vector v { 4, 4, 6, 1, 4, 3, 2 }; diff --git a/src/hack/patterns/identificator.hpp b/src/hack/patterns/identificator.hpp new file mode 100644 index 0000000..1e48383 --- /dev/null +++ b/src/hack/patterns/identificator.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace hack::patterns +{ + template + class identificator + { + public: + identificator() { m_id = m_counter; ++m_counter; } + + public: + T m_id; + + private: + static inline T m_counter = 0; + }; +}