52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "tl/detail/prologue.h"
|
|
#include "tl/hash_map.h"
|
|
#include <compare>
|
|
|
|
namespace tl
|
|
{
|
|
|
|
template<typename T, typename Tag>
|
|
struct identifier
|
|
{
|
|
using underlying_type = T;
|
|
|
|
identifier() = delete;
|
|
explicit constexpr identifier(T value) noexcept : m_value(std::move(value)) {}
|
|
|
|
constexpr T value() const noexcept { return m_value; }
|
|
auto operator<=>(const identifier<T, Tag>& other) const noexcept { return m_value <=> other.value(); }
|
|
auto operator<=>(const T& other) const noexcept { return m_value <=> other; }
|
|
bool operator==(const identifier<T, Tag>& other) const noexcept { return m_value == other.value(); }
|
|
bool operator==(const T& other) const noexcept { return m_value == other; }
|
|
|
|
private:
|
|
T m_value;
|
|
};
|
|
}
|
|
|
|
#define TL_DECLARE_INTEGRAL_ID(NAME, TYPE) \
|
|
struct NAME##_tag {};\
|
|
using NAME = tl::identifier<TYPE, NAME##_tag>;
|
|
|
|
template <typename T, typename Tag>
|
|
struct std::formatter<tl::identifier<T, Tag>>
|
|
{
|
|
constexpr auto parse(format_parse_context& ctx) noexcept { return ctx.begin(); }
|
|
auto format(const tl::identifier<T, Tag>& id, std::format_context& ctx) const
|
|
{
|
|
return format_to(ctx.out(), "{}", id.value());
|
|
}
|
|
};
|
|
|
|
template<typename T, typename Tag>
|
|
struct eastl::hash<tl::identifier<T, Tag>>
|
|
{
|
|
size_t operator()(tl::identifier<T, Tag> const& id) const
|
|
{
|
|
return hash<T>()(id.value());
|
|
}
|
|
};
|
|
|