19 static_assert(std::is_integral_v<T>,
"Expecting tagged_id to be an integral");
20 static_assert(Max < std::numeric_limits<T>::max(),
"Max must be at least one less than the maximum value of T");
25 constexpr static type max = Max;
26 constexpr static type invalid = max + 1;
28 constexpr static type mask = make_mask(invalid);
34 constexpr explicit tagged_id(
signed long long rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
35 constexpr explicit tagged_id(
signed long rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
36 constexpr explicit tagged_id(
signed int rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
37 constexpr explicit tagged_id(
signed short rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
38 constexpr explicit tagged_id(
signed char rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
39 constexpr explicit tagged_id(
unsigned long long rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
40 constexpr explicit tagged_id(
unsigned long rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
41 constexpr explicit tagged_id(
unsigned int rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
42 constexpr explicit tagged_id(
unsigned short rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
43 constexpr explicit tagged_id(
unsigned char rhs) noexcept : value(numeric_cast<type>(rhs)) { tt_assume(value <= invalid); }
45 constexpr tagged_id &operator=(
signed long long rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
46 constexpr tagged_id &operator=(
signed long rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
47 constexpr tagged_id &operator=(
signed int rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
48 constexpr tagged_id &operator=(
signed short rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
49 constexpr tagged_id &operator=(
signed char rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
50 constexpr tagged_id &operator=(
unsigned long long rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
51 constexpr tagged_id &operator=(
unsigned long rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
52 constexpr tagged_id &operator=(
unsigned int rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
53 constexpr tagged_id &operator=(
unsigned short rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
54 constexpr tagged_id &operator=(
unsigned char rhs)
noexcept { value = numeric_cast<type>(rhs); tt_assume(value <= invalid);
return *
this; }
56 constexpr tagged_id() noexcept : value(invalid) {}
62 constexpr operator signed long long ()
const noexcept {
return numeric_cast<signed long long>(value); }
63 constexpr operator signed long ()
const noexcept {
return numeric_cast<signed long>(value); }
64 constexpr operator signed int ()
const noexcept {
return numeric_cast<signed int>(value); }
65 constexpr operator signed short ()
const noexcept {
return numeric_cast<signed short>(value); }
66 constexpr operator signed char ()
const noexcept {
return numeric_cast<signed char>(value); }
67 constexpr operator unsigned long long ()
const noexcept {
return numeric_cast<unsigned long long>(value); }
68 constexpr operator unsigned long ()
const noexcept {
return numeric_cast<unsigned long>(value); }
69 constexpr operator unsigned int ()
const noexcept {
return numeric_cast<unsigned int>(value); }
70 constexpr operator unsigned short ()
const noexcept {
return numeric_cast<unsigned short>(value); }
71 constexpr operator unsigned char ()
const noexcept {
return numeric_cast<unsigned char>(value); }
73 constexpr operator bool ()
const noexcept {
return value <= max; }
75 [[nodiscard]]
constexpr size_t hash()
const noexcept {
return std::hash<type>{}(value); }
77 [[nodiscard]]
constexpr friend bool operator==(
tagged_id const &lhs,
tagged_id const &rhs)
noexcept {
return lhs.value == rhs.value; }
78 [[nodiscard]]
constexpr friend bool operator!=(
tagged_id const &lhs,
tagged_id const &rhs)
noexcept {
return lhs.value != rhs.value; }
79 [[nodiscard]]
constexpr friend bool operator<(
tagged_id const &lhs,
tagged_id const &rhs)
noexcept {
return lhs.value < rhs.value; }
80 [[nodiscard]]
constexpr friend bool operator>(
tagged_id const &lhs,
tagged_id const &rhs)
noexcept {
return lhs.value > rhs.value; }
81 [[nodiscard]]
constexpr friend bool operator<=(
tagged_id const &lhs,
tagged_id const &rhs)
noexcept {
return lhs.value <= rhs.value; }
82 [[nodiscard]]
constexpr friend bool operator>=(
tagged_id const &lhs,
tagged_id const &rhs)
noexcept {
return lhs.value >= rhs.value; }
84 template<
typename O> [[nodiscard]]
constexpr friend bool operator==(
tagged_id const &lhs, O
const &rhs)
noexcept {
return lhs ==
tagged_id{rhs}; }
85 template<
typename O> [[nodiscard]]
constexpr friend bool operator!=(
tagged_id const &lhs, O
const &rhs)
noexcept {
return lhs !=
tagged_id{rhs}; }
86 template<
typename O> [[nodiscard]]
constexpr friend bool operator<(
tagged_id const &lhs, O
const &rhs)
noexcept {
return lhs <
tagged_id{rhs}; }
87 template<
typename O> [[nodiscard]]
constexpr friend bool operator>(
tagged_id const &lhs, O
const &rhs)
noexcept {
return lhs >
tagged_id{rhs}; }
88 template<
typename O> [[nodiscard]]
constexpr friend bool operator<=(
tagged_id const &lhs, O
const &rhs)
noexcept {
return lhs <=
tagged_id{rhs}; }
89 template<
typename O> [[nodiscard]]
constexpr friend bool operator>=(
tagged_id const &lhs, O
const &rhs)
noexcept {
return lhs >=
tagged_id{rhs}; }
90 template<
typename O> [[nodiscard]]
constexpr friend bool operator==(O
const &lhs,
tagged_id const &rhs)
noexcept {
return tagged_id{lhs} == rhs; }
91 template<
typename O> [[nodiscard]]
constexpr friend bool operator!=(O
const &lhs,
tagged_id const &rhs)
noexcept {
return tagged_id{lhs} != rhs; }
92 template<
typename O> [[nodiscard]]
constexpr friend bool operator<(O
const &lhs,
tagged_id const &rhs)
noexcept {
return tagged_id{lhs} < rhs; }
93 template<
typename O> [[nodiscard]]
constexpr friend bool operator>(O
const &lhs,
tagged_id const &rhs)
noexcept {
return tagged_id{lhs} > rhs; }
94 template<
typename O> [[nodiscard]]
constexpr friend bool operator<=(O
const &lhs,
tagged_id const &rhs)
noexcept {
return tagged_id{lhs} <= rhs; }
95 template<
typename O> [[nodiscard]]
constexpr friend bool operator>=(O
const &lhs,
tagged_id const &rhs)
noexcept {
return tagged_id{lhs} >= rhs; }
102 return lhs << to_string(rhs);