This commit is contained in:
ZY4N
2025-03-28 13:09:34 +01:00
parent 6f60cc11c8
commit d18b40a7fc
34 changed files with 393 additions and 272 deletions

View File

@@ -1,25 +1,31 @@
#pragma once
#include <atomic>
namespace ztu
{
template<class Parent, typename IndexType, int uuid = 0>
class id_type_for
template<typename Index, int ID>
class id_type
{
friend Parent;
explicit constexpr id_type(Index index) : index{ index } {}
using index_type = IndexType;
static constexpr id_type next()
{
static std::atomic<Index> next_index{ 1 };
return id_type{ next_index.fetch_add(1, std::memory_order_seq_cst) };
}
explicit constexpr id_type_for(index_type index) : index{ index } {}
index_type index{};
Index index{};
public:
constexpr id_type_for() = default;
constexpr auto operator<=>(const id_type_for&) const = default;
constexpr id_type() = default;
constexpr auto operator<=>(const id_type&) const = default;
constexpr operator bool() const
{
return index == index_type{};
return index == Index{};
}
};
}