1#ifndef LIBSBX_MATH_UUID_HPP_
2#define LIBSBX_MATH_UUID_HPP_
4#if defined(SBX_MATH_UUID_USE_V4)
10#include <fmt/format.h>
12#include <range/v3/all.hpp>
16#include <libsbx/math/random.hpp>
20struct invalid_uuid_exception : std::runtime_error {
22 invalid_uuid_exception(std::string_view uuid)
23 : std::runtime_error{fmt::format(
"String '{}' is not a valid uuid", uuid)} { }
29 friend struct fmt::formatter<sbx::math::uuid>;
30 friend struct std::hash<sbx::math::uuid>;
32 struct null_uui_tag { };
38 using value_type = std::uint64_t;
41 : _value{random::next<value_type>()} {
79 static auto null() -> uuid {
80 return uuid{null_uui_tag{}};
83 auto operator==(
const uuid& other)
const noexcept ->
bool {
84 return _value == other._value;
95 operator value_type()
const {
112struct fmt::formatter<sbx::math::uuid> {
114 template<
typename ParseContext>
115 constexpr auto parse(ParseContext& context) ->
decltype(context.begin()) {
116 return context.begin();
119 template<
typename FormatContext>
120 auto format(
const sbx::math::uuid& uuid, FormatContext& context) ->
decltype(context.out()) {
121 return fmt::format_to(context.out(),
"{}",
static_cast<sbx::math::uuid::value_type
>(uuid));
141struct std::hash<sbx::math::uuid> {
142 auto operator()(
const sbx::math::uuid& uuid)
const noexcept -> std::size_t {
143 return static_cast<sbx::math::uuid::value_type
>(uuid);
152#include <fmt/format.h>
154#include <libsbx/math/random.hpp>
158template<std::
unsigned_
integral Type>
162 friend struct std::hash<sbx::math::basic_uuid<Type>>;
166 using value_type = Type;
169 : _value{random::next<value_type>()} { }
175 constexpr auto operator==(
const basic_uuid& other)
const noexcept ->
bool {
176 return _value == other._value;
179 constexpr auto operator<(
const basic_uuid& other)
const noexcept ->
bool {
180 return _value < other._value;
183 constexpr auto value()
const noexcept -> value_type {
200template<std::
unsigned_
integral Type>
201struct fmt::formatter<sbx::math::basic_uuid<Type>> {
203 template<
typename ParseContext>
204 constexpr auto parse(ParseContext& context) ->
decltype(context.begin()) {
205 return context.begin();
208 template<
typename FormatContext>
210 return fmt::format_to(context.out(),
"{}", uuid._value);
215template<std::
unsigned_
integral Type>
216struct std::hash<sbx::math::basic_uuid<Type>> {