stuff...
This commit is contained in:
@@ -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{};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user