struct
#include <muu/uuid.h>
uuid A 128-bit universally-unique identifier (UUID).
Public types
-
using constants = muu::
constants<uuid> - Static constants for this type.
Public static functions
- static auto compare(const uuid& lhs, const uuid& rhs) -> int32_t constexpr noexcept
- Returns the lexicographical ordering of two UUID's.
- static auto generate() -> uuid noexcept
- Creates a new UUID using the platform's UUID generator.
-
static auto parse(std::
string_view str) -> std:: optional<uuid> constexpr noexcept - Attempts to parse a UUID from a UTF-8 string.
-
static auto parse(std::
u8string_view str) -> std:: optional<uuid> constexpr noexcept - Attempts to parse a UUID from a UTF-8 string.
-
static auto parse(std::
u16string_view str) -> std:: optional<uuid> constexpr noexcept - Attempts to parse a UUID from a UTF-16 string.
-
static auto parse(std::
u32string_view str) -> std:: optional<uuid> constexpr noexcept - Attempts to parse a UUID from a UTF-32 string.
-
static auto parse(std::
wstring_view str) -> std:: optional<uuid> constexpr noexcept - Attempts to parse a UUID from a wide string.
Constructors, destructors, conversion operators
- operator bool() const explicit constexpr noexcept
- Returns true if this UUID has non-zero value.
- operator uint128_t() const explicit constexpr noexcept
- Converts a UUID directly into a 128-bit integer.
- uuid() defaulted noexcept
- Default constructor. Leaves the UUID uninitialized.
- uuid(uint32_t time_low, uint16_t time_mid, uint16_t time_high_and_version, uint8_t clock_seq_high_and_reserved, uint8_t clock_seq_low, uint64_t node) constexpr noexcept
- Creates a UUID from it's raw integral components, as per RFC 4122.
- uuid(uint32_t time_low, uint16_t time_mid, uint16_t time_high_and_version, uint16_t clock_seq, uint64_t node) constexpr noexcept
- Creats a UUID from it's raw integral components, as per RFC 4122.
-
uuid(std::
nullptr_t) constexpr noexcept - Explicitly constructs a null UUID.
-
uuid(uint128_
t val) constexpr noexcept - Constructs a UUID directly from a 128-bit integer.
- uuid(const uuid& name_space, const void* name_data, size_t name_size) noexcept
- Constructs a version-5 named UUID by hashing some binary data.
-
uuid(const uuid& name_space,
std::
string_view name) noexcept - Constructs a version-5 named UUID by hashing a string.
-
uuid(const uuid& name_space,
std::
u8string_view name) noexcept - Constructs a version-5 named UUID by hashing a string.
Public functions
- auto clock_seq_high_and_reserved() const -> uint8_t constexpr noexcept
- Returns the value of the 'clock-seq-high-and-reserved' field.
- auto clock_seq_low() const -> uint8_t constexpr noexcept
- Returns the value of the 'clock-seq-low' field.
- auto node() const -> uint64_t constexpr noexcept
- Returns the value of the 'node' field.
- auto time_high_and_version() const -> uint16_t constexpr noexcept
- Returns the value of the 'time-high-and-version' field.
- auto time_low() const -> uint32_t constexpr noexcept
- Returns the value of the 'time-low' field.
- auto time_mid() const -> uint16_t constexpr noexcept
- Returns the value of the 'time-mid' field.
-
auto variant() const -> uuid_
variant constexpr noexcept - Returns the UUID's variant.
-
auto version() const -> uuid_
version constexpr noexcept - Returns the UUID's version.
Public variables
- impl::uuid_bytes bytes
- The raw bytes in the UUID.
Friends
- auto operator!=(const uuid& lhs, const uuid& rhs) -> bool constexpr noexcept
- Returns true if two UUIDs are not equal.
- auto operator<(const uuid& lhs, const uuid& rhs) -> bool constexpr noexcept
- Returns true if the LHS UUID is ordered lower than the RHS UUID.
-
template <typename Char>auto operator<<(std::
basic_ostream<Char, std:: char_traits<Char>>& lhs, const uuid& rhs) -> std:: basic_ostream<Char, std:: char_traits<Char>>& - Writes a UUID to a text stream.
- auto operator<=(const uuid& lhs, const uuid& rhs) -> bool constexpr noexcept
- Returns true if the LHS UUID is ordered lower than or equal to the RHS UUID.
- auto operator==(const uuid& lhs, const uuid& rhs) -> bool constexpr noexcept
- Returns true if two UUIDs are equal.
- auto operator>(const uuid& lhs, const uuid& rhs) -> bool constexpr noexcept
- Returns true if the LHS UUID is ordered higher than the RHS UUID.
- auto operator>=(const uuid& lhs, const uuid& rhs) -> bool constexpr noexcept
- Returns true if the LHS UUID is ordered higher than or equal to the RHS UUID.
Function documentation
muu:: uuid:: uuid(uint32_t time_low,
uint16_t time_mid,
uint16_t time_high_and_version,
uint8_t clock_seq_high_and_reserved,
uint8_t clock_seq_low,
uint64_t node) constexpr noexcept
Creates a UUID from it's raw integral components, as per RFC 4122.
Parameters | |
---|---|
time_low | The 'time-low' field. |
time_mid | The 'time-middle' field. |
time_high_and_version | The 'time-high-and-version' field. |
clock_seq_high_and_reserved | The 'clock-seq-high-and-reserved' field. |
clock_seq_low | The 'clock-seq-low' field. |
node | The 'node' field. The highest 2 bytes are ignored (the 'node' field of a UUID is a 48-bit unsigned int). |
muu:: uuid:: uuid(uint32_t time_low,
uint16_t time_mid,
uint16_t time_high_and_version,
uint16_t clock_seq,
uint64_t node) constexpr noexcept
Creats a UUID from it's raw integral components, as per RFC 4122.
Parameters | |
---|---|
time_low | The 'time-low' field. |
time_mid | The 'time-middle' field. |
time_high_and_version | The 'time-high-and-version' field. |
clock_seq | The 'clock-seq-high-and-reserved' (MSB) and 'clock-seq-low' (LSB) fields. |
node | The 'node' field. The highest 2 bytes are ignored (the 'node' field of a UUID is a 48-bit unsigned int). |
muu:: uuid:: uuid(const uuid& name_space,
const void* name_data,
size_t name_size) noexcept
Constructs a version-5 named UUID by hashing some binary data.
Parameters | |
---|---|
name_space | The 'name space' the ID will belong to. |
name_data | The 'name' data to hash. |
name_size | Size of the name data in bytes. |
UUIDs generated by this constructor are deterministic; the same namespace and name will always produce the same UUID.
muu:: uuid:: uuid(const uuid& name_space,
std:: string_view name) noexcept
Constructs a version-5 named UUID by hashing a string.
Parameters | |
---|---|
name_space | The 'namespace' for the id. |
name | The 'name' of the ID. |
UUIDs generated by this constructor are deterministic; the same namespace and name will always produce the same UUID.
muu:: uuid:: uuid(const uuid& name_space,
std:: u8string_view name) noexcept
Constructs a version-5 named UUID by hashing a string.
Parameters | |
---|---|
name_space | The 'namespace' for the id. |
name | The 'name' of the ID. |
UUIDs generated by this constructor are deterministic; the same namespace and name will always produce the same UUID.
uuid operator""_uuid(const char* str, size_t len) consteval noexcept
Constructs a uuid from a string literal using uuid::
const uuid id = "{06B35EFD-A532-4410-ADD1-C8C536C31A84}"_uuid;
Variable documentation
impl::uuid_bytes muu:: uuid:: bytes
The raw bytes in the UUID.
The byte layout of the UUID is always the same regardless of the target platform:[ 0]
time_low - most significant byte[ 1]
...[ 2]
...[ 3]
time_low - least significant byte[ 4]
time_mid - most significante byte[ 5]
time_mid - least significante byte[ 6]
time_high_and_version - most significante byte[ 7]
time_high_and_version - least significante byte[ 8]
clock_seq_high_and_reserved[ 9]
clock_seq_low[10]
node - most significant byte[11]
...[12]
...[13]
...[14]
...[15]
node - least significant byte
Relevant excerpt from the UUID RFC:
In the absence of explicit application or presentation protocol specification to the contrary, a UUID is encoded as a 128-bit object, as follows: The fields are encoded as 16 octets, with the sizes and order of the fields defined above, and with each field encoded with the Most Significant Byte first (known as network byte order). Note that the field names, particularly for multiplexed fields, follow historical practice. 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | time_low | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | time_mid | time_high_and_version | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |clk_seq_hi_res | clk_seq_low | node (0-1) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | node (2-5) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+