From f5c6b75621af9ef07d74a2bbca1ae7ef4b8fff85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mart=C3=ADn?= Date: Thu, 4 Jul 2024 10:53:37 +0200 Subject: [PATCH] Remove optional semantics from identifier --- include/tl/identifier.h | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/include/tl/identifier.h b/include/tl/identifier.h index 6a1a4af..c742e64 100644 --- a/include/tl/identifier.h +++ b/include/tl/identifier.h @@ -7,46 +7,43 @@ namespace tl { -template +template struct identifier { using underlying_type = T; - constexpr identifier() noexcept = default; + identifier() = delete; explicit constexpr identifier(T value) noexcept : m_value(std::move(value)) {} constexpr T value() const noexcept { return m_value; } - constexpr bool is_valid() const noexcept { return m_value != invalid_value; } - //inline static identifier invalid() noexcept { return identifier(); } - - auto operator<=>(const identifier& other) const noexcept { return m_value <=> other.value(); } + auto operator<=>(const identifier& other) const noexcept { return m_value <=> other.value(); } auto operator<=>(const T& other) const noexcept { return m_value <=> other; } - bool operator==(const identifier& other) const noexcept { return m_value == other.value(); } + bool operator==(const identifier& other) const noexcept { return m_value == other.value(); } bool operator==(const T& other) const noexcept { return m_value == other; } private: - T m_value = invalid_value; + T m_value; }; } -#define TL_DECLARE_INTEGRAL_ID(NAME, TYPE, INVALID_VALUE) \ +#define TL_DECLARE_INTEGRAL_ID(NAME, TYPE) \ struct NAME##_tag {};\ -using NAME = tl::identifier; +using NAME = tl::identifier; -template -struct std::formatter> +template +struct std::formatter> { constexpr auto parse(format_parse_context& ctx) noexcept { return ctx.begin(); } - auto format(const tl::identifier& id, std::format_context& ctx) const + auto format(const tl::identifier& id, std::format_context& ctx) const { return format_to(ctx.out(), "{}", id.value()); } }; -template -struct eastl::hash> +template +struct eastl::hash> { - size_t operator()(tl::identifier const& id) const + size_t operator()(tl::identifier const& id) const { return hash()(id.value()); }