7#include "../macros.hpp"
20hi_export_module(hikogui.utility.tagged_id);
22hi_export
namespace hi::inline
v1 {
26template<
typename Derived, std::
unsigned_
integral T, T Empty>
27std::atomic<T> tagged_id_counter = Empty == 0 ? T{1} : T{0};
38template<
typename Derived, std::
unsigned_
integral T, T Empty>
41 using derived_type = Derived;
43 constexpr static value_type empty_value = Empty;
45 constexpr tagged_id()
noexcept =
default;
46 constexpr tagged_id(tagged_id
const& other)
noexcept =
default;
47 constexpr tagged_id(tagged_id&& other)
noexcept =
default;
48 constexpr tagged_id& operator=(tagged_id
const& other)
noexcept =
default;
49 constexpr tagged_id& operator=(tagged_id&& other)
noexcept =
default;
50 constexpr tagged_id(std::nullopt_t) noexcept : _v(empty_value) {}
52 constexpr tagged_id(value_type rhs) : _v(rhs) {
53 if (rhs == empty_value) {
60 [[nodiscard]]
static tagged_id
make()
62 return detail::tagged_id_counter<derived_type, value_type, empty_value>.fetch_add(1, std::memory_order::relaxed);
65 constexpr tagged_id& operator=(value_type rhs)
67 if (rhs == empty_value) {
75 constexpr tagged_id& operator=(std::nullopt_t)
noexcept
81 [[nodiscard]]
constexpr bool empty() const noexcept
83 return _v == empty_value;
86 constexpr explicit operator bool() const noexcept
91 [[nodiscard]]
constexpr value_type value()
const
93 if (_v == empty_value) {
94 throw std::overflow_error(
"Dereferencing an empty identifier");
99 constexpr explicit operator value_type()
const
104 [[nodiscard]]
constexpr value_type
operator*()
const
109 [[nodiscard]]
constexpr friend auto operator<=>(tagged_id
const&, tagged_id
const &)
noexcept =
default;
110 [[nodiscard]]
constexpr friend bool operator==(tagged_id
const&, tagged_id
const &)
noexcept =
default;
113 value_type _v = empty_value;
118hi_export
template<
typename Derived, std::
unsigned_
integral T, T Empty>
120 [[nodiscard]]
constexpr std::size_t operator()(hi::tagged_id<Derived, T, Empty>
const& rhs)
const noexcept
Utilities for throwing exceptions and terminating the application.
The HikoGUI namespace.
Definition array_generic.hpp:21
constexpr matrix2 operator*(matrix2 const &lhs, matrix2 const &rhs) noexcept
Matrix/Matrix multiplication.
Definition transform.hpp:69
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
A tagged identifier.
Definition tagged_id.hpp:39
static tagged_id make()
Make a new unique identifier.
Definition tagged_id.hpp:60