add identificato pattern

This commit is contained in:
2025-04-05 14:24:38 +03:00
parent ab0334300e
commit 3f559432ba
2 changed files with 30 additions and 0 deletions

View File

@@ -7,6 +7,7 @@
#include "hack/math/max.hpp" #include "hack/math/max.hpp"
#include "hack/patterns/ring_buffer.hpp" #include "hack/patterns/ring_buffer.hpp"
#include "hack/patterns/identificator.hpp"
auto main(int argc, char *argv[]) -> int auto main(int argc, char *argv[]) -> int
{ {
@@ -25,6 +26,16 @@ auto main(int argc, char *argv[]) -> int
hack::log()(v); 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 // range::sort
{ {
std::vector<int> v { 4, 4, 6, 1, 4, 3, 2 }; std::vector<int> v { 4, 4, 6, 1, 4, 3, 2 };

View File

@@ -0,0 +1,19 @@
#pragma once
#include <cstddef>
namespace hack::patterns
{
template<typename T = std::size_t>
class identificator
{
public:
identificator() { m_id = m_counter; ++m_counter; }
public:
T m_id;
private:
static inline T m_counter = 0;
};
}