30 std::uniform_int_distribution<std::uint8_t> dist(0, std::numeric_limits<std::uint8_t>::max());
33 for (
auto &el : buf.
b8) {
37 buf.
b8[7] &= (std::uint8_t) 0b00101111;
38 buf.
b8[9] &= (std::uint8_t) 0b10011111;
51 std::default_random_engine engine {r()};
61 [[nodiscard]] std::string
string()
const {
64 result.reserve(
sizeof(
uuid_t) * 2 + 4);
66 auto hex = util::hex(*
this,
true);
67 auto hex_view = hex.to_string_view();
69 std::string_view slices[] = {
70 hex_view.substr(0, 8),
71 hex_view.substr(8, 4),
72 hex_view.substr(12, 4),
73 hex_view.substr(16, 4)
75 auto last_slice = hex_view.substr(20, 12);
77 for (
auto &slice : slices) {
78 std::copy(std::begin(slice), std::end(slice), std::back_inserter(result));
80 result.push_back(
'-');
83 std::copy(std::begin(last_slice), std::end(last_slice), std::back_inserter(result));
UUID utilities.
Definition uuid.h:13
UUID value exposed through multiple integer views.
Definition uuid.h:17
std::string string() const
Format the UUID using canonical text form.
Definition uuid.h:61
constexpr bool operator<(const uuid_t &other) const
Order UUID values by their 64-bit word representation.
Definition uuid.h:104
std::uint16_t b16[8]
UUID viewed as 16-bit words.
Definition uuid.h:19
static uuid_t generate()
Generate a UUID value.
Definition uuid.h:48
constexpr bool operator>(const uuid_t &other) const
Order UUID values by their 64-bit word representation.
Definition uuid.h:114
std::uint64_t b64[2]
UUID viewed as 64-bit words.
Definition uuid.h:21
std::uint8_t b8[16]
UUID bytes.
Definition uuid.h:18
static uuid_t generate(std::default_random_engine &engine)
Generate a UUID value.
Definition uuid.h:29
std::uint32_t b32[4]
UUID viewed as 32-bit words.
Definition uuid.h:20
constexpr bool operator==(const uuid_t &other) const
Compare two UUID values for equality.
Definition uuid.h:94