From d6c3a1ab7f2ed179885a7e300a93c5908bd23537 Mon Sep 17 00:00:00 2001 From: mariusbancila Date: Mon, 18 Dec 2017 16:12:48 +0200 Subject: [PATCH] array constructors --- paper.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/paper.md b/paper.md index 2a4dd52..5ed029a 100644 --- a/paper.md +++ b/paper.md @@ -14,7 +14,60 @@ This proposal is a pure library extension. It does not require changes to any st ## III. Design Decisions +The proposed library, that should be available in a new header called `` in the namespace `std::uuids`, provides: +* a class called `uuid` that represents a universally unique identifier +* strongly type enums `uuid_variant` and `uuid_version` to represent the possible variant and version types of a UUID +* a `make_uuid` function to generate a new UUID +* comparison operators `==`, `!=`, `<` +* `std::swap<>` specialization for `uuid` +* `std::hash<>` specialization for `uuid` +### Default constructor + +Creates a nil UUID that has all the bits set to 0 (i.e. 00000000-0000-0000-0000-000000000000). + +``` +uuid empty; +auto empty = uuid{}; +``` + +### string constructors + +Conversion constructors from `std::string` and `std::wstring` allow to create `uuid` instances from a string. + +The input argument must have the form `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` where `x` is a hexadecimal digit. Should the argument be of a different format a nil UUID would be created. + +``` +uuid id1("47183823-2574-4bfd-b411-99ed177d3e43"); + +std::wstring str=L"47183823-2574-4bfd-b411-99ed177d3e43"; +uuid id2(str); +``` + +### array constructors + +The conversion constructor from `std::array` enables the construction of a `uuid` from an array of bytes. + +``` +std::array arr{ + 0x47, 0x18, 0x38, 0x23, + 0x25, 0x74, + 0x4b, 0xfd, + 0xb4, 0x11, + 0x99, 0xed, 0x17, 0x7d, 0x3e, 0x43}; +uuid id(arr); +``` + +A conversion constructor from `uint8_t*` also exists to construct `uuid`s from C-like arrays. This requires the input buffer to have at least 16 bytes. The behavior when the buffer does not have 16 bytes is undefined. +``` +uint8_t arr[16] = { + 0x47, 0x18, 0x38, 0x23, + 0x25, 0x74, + 0x4b, 0xfd, + 0xb4, 0x11, + 0x99, 0xed, 0x17, 0x7d, 0x3e, 0x43}; +uuid id(arr); +``` ## IV. Technical Specifications