add identificato pattern
This commit is contained in:
11
bin/main.cpp
11
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<int> v { 4, 4, 6, 1, 4, 3, 2 };
|
||||
|
||||
19
src/hack/patterns/identificator.hpp
Normal file
19
src/hack/patterns/identificator.hpp
Normal 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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user