2#ifndef LIBSBX_MATH_UUID_HPP_
3#define LIBSBX_MATH_UUID_HPP_
10#include <libsbx/math/random.hpp>
14template<std::
unsigned_
integral Type>
19 using value_type = Type;
22 : _value{random::next<value_type>(1u)} { }
28 static constexpr auto from_value(
const value_type value) ->
basic_uuid {
36 constexpr auto operator==(
const basic_uuid& other)
const noexcept ->
bool {
37 return _value == other._value;
40 constexpr auto operator<(
const basic_uuid& other)
const noexcept ->
bool {
41 return _value < other._value;
44 constexpr auto value()
const noexcept -> value_type {
61template<std::
unsigned_
integral Type>
62struct fmt::formatter<sbx::math::basic_uuid<Type>> {
64 template<
typename ParseContext>
65 constexpr auto parse(ParseContext& context) ->
decltype(context.begin()) {
66 return context.begin();
69 template<
typename FormatContext>
71 static constexpr auto width =
sizeof(Type) * 2;
74 return fmt::format_to(context.out(),
"[nil]");
77 return fmt::format_to(context.out(),
"{:0{}x}", uuid.value(), width);
81template<std::
unsigned_
integral Type>
82struct YAML::convert<sbx::math::basic_uuid<Type>> {
85 return Node{rhs.value()};
89 if (!
node.IsScalar()) {
100template<std::
unsigned_
integral Type>
102 return out << YAML::convert<sbx::math::basic_uuid<Type>>::encode(vector);
105template<std::
unsigned_
integral Type>
106struct std::hash<sbx::math::basic_uuid<Type>> {