Update P0959.md

syntax highlighting
This commit is contained in:
Marius Bancila 2018-02-28 21:48:04 +02:00 committed by GitHub
parent cc4eda9f99
commit 7f876e068b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,7 +35,7 @@ The proposed library, that should be available in a new header called `<uuid>` i
Creates a nil UUID that has all the bits set to 0 (i.e. `00000000-0000-0000-0000-000000000000`).
```
```cpp
uuid empty;
auto empty = uuid{};
```
@ -46,7 +46,7 @@ Conversion constructors from `std::string_view` and `std::wstring_view` allow to
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.
```
```cpp
uuid id1("47183823-2574-4bfd-b411-99ed177d3e43");
std::wstring str=L"47183823-2574-4bfd-b411-99ed177d3e43";
@ -57,7 +57,7 @@ uuid id2(str);
The conversion constructor that takes two forward iterators constructs an `uuid` with the content of the range \[first, last). It requires the range to have exactly 16 elements, otherwise the result is a nil `uuid`. This constructor follows the conventions of other containers in the standard library.
```
```cpp
std::array<uuid::value_type, 16> arr{{
0x47, 0x18, 0x38, 0x23,
0x25, 0x74,
@ -68,7 +68,7 @@ std::array<uuid::value_type, 16> arr{{
uuid id(std::begin(arr), std::end(arr));
```
```
```cpp
uuid::value_type arr[16] = {
0x47, 0x18, 0x38, 0x23,
0x25, 0x74,
@ -81,7 +81,7 @@ uuid id(std::begin(arr), std::end(arr));
### Size
Member function `size()` indicates the number of bytes in the UUID. Because this is a fixed size structure this function always returns 16.
```
```cpp
uuid id;
assert(id.size() == 16);
```
@ -89,7 +89,7 @@ assert(id.size() == 16);
### Nil
A nil UUID is a special UUID that has all the bits set to 0. Its canonical textual representation is `00000000-0000-0000-0000-000000000000`. Member function `nil()` indicates whether the `uuid` has all the bits set to 0. A nil uuid is created by the default constructor or by the string conversion constructors when failing to parse the input argument.
```
```cpp
uuid id;
assert(id.nil());
```
@ -98,7 +98,7 @@ assert(id.nil());
Constant and mutable iterators allow direct access to the underlaying `uuid` data. This enables both direct reading and writing of the `uuid` bits. The `uuid` class has both const and non-const `begin()` and `end()` members to return constant and mutable iterators to the first and the one-past-last element of the UUID data.
```
```cpp
std::array<uuid::value_type, 16> arr{{
0x47, 0x18, 0x38, 0x23,
0x25, 0x74,
@ -125,7 +125,7 @@ Because the internal representation may not be a straightforward array of bytes
Member functions `variant()` and `version()` allow checking the variant type of the uuid and respectively the version type. These are defined by two strongly typed enums called `uuid_variant` and `uuid_version`.
```
```cpp
uuid id("47183823-2574-4bfd-b411-99ed177d3e43");
assert(id.version() == uuid_version::random_number_based);
assert(id.variant() == uuid_variant::rfc);
@ -135,7 +135,7 @@ assert(id.variant() == uuid_variant::rfc);
Both member and non-member `swap()` functions are available to perform the swapping of `uuid` values.
```
```cpp
uuid empty;
uuid id("47183823-2574-4bfd-b411-99ed177d3e43");
@ -157,7 +157,7 @@ assert(!id.nil());
Non-member functions `to_string()` and `to_wstring()` return a string with the UUID formatted to the canonical textual representation `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`, where `x` is a lower case hexadecimal digit.
```
```cpp
uuid id("47183823-2574-4bfd-b411-99ed177d3e43");
assert(to_string(id) == "47183823-2574-4bfd-b411-99ed177d3e43");
assert(to_wstring(id) == L"47183823-2574-4bfd-b411-99ed177d3e43");
@ -167,7 +167,7 @@ assert(to_wstring(id) == L"47183823-2574-4bfd-b411-99ed177d3e43");
Non-member `operators ==` and `operator !=` are provided in order to test the equality/inequality of two `uuid` values.
```
```cpp
uuid empty;
uuid id("47183823-2574-4bfd-b411-99ed177d3e43");
@ -180,7 +180,7 @@ assert(empty != id);
Although it does not make sense to check whether a UUID is less or less or equal then another UUID, the overloading of this operator for `uuid` is necessary in order to be able to store `uuid` values in containers such as `std::set` that by default use `operator <` to compare keys.
```
```cpp
std::set<std::uuid> ids{
uuid{},
uuid("47183823-2574-4bfd-b411-99ed177d3e43")
@ -194,7 +194,7 @@ assert(ids.find(uuid{}) != ids.end());
A `std::hash<>` specialization for `uuid` is provided in order to enable the use of `uuid`s in associative unordered containers such as `std::unordered_set`.
```
```cpp
std::unordered_set<uuid> ids{
uuid{},
uuid("47183823-2574-4bfd-b411-99ed177d3e43"),
@ -208,7 +208,7 @@ assert(ids.find(uuid{}) != ids.end());
Several function objects, called generators, are provided in order to create different versions of UUIDs.
Examples for generating new UUIDs with the `basic_uuid_random_generator` class:
```
```cpp
{
basic_uuid_random_generator<std::mt19937> dgen;
auto id1 = dgen();
@ -249,7 +249,7 @@ Examples for generating new UUIDs with the `basic_uuid_random_generator` class:
}
```
Examples for generating new UUIDs with the `uuid_random_generator` type alias:
```
```cpp
uuid_random_generator dgen;
auto id1 = dgen();
assert(!id1.nil());
@ -258,7 +258,7 @@ assert(id1.version() == uuid_version::random_number_based);
assert(id1.variant() == uuid_variant::rfc);
```
Examples for genearting new UUIDs with the `uuid_name_generator` class:
```
```cpp
uuid_name_generator dgen(uuid{"415ccc2b-f5cf-4ec1-b544-45132a518cc8");
auto id1 = dgen("john");
assert(!id1.nil());
@ -296,7 +296,7 @@ Add a new header called `<uuid>`.
### `uuid_variant` enum
```
```cpp
namespace std {
enum class uuid_variant
{
@ -310,7 +310,7 @@ namespace std {
### `uuid_version` enum
```
```cpp
namespace std {
enum class uuid_version
{
@ -326,7 +326,7 @@ namespace std {
### `uuid` class
```
```cpp
namespace std {
struct uuid
{
@ -374,7 +374,7 @@ private:
### non-member functions
```
```cpp
namespace std {
inline bool operator== (uuid const& lhs, uuid const& rhs) noexcept;
inline bool operator!= (uuid const& lhs, uuid const& rhs) noexcept;
@ -392,7 +392,7 @@ namespace std {
### Generators
`basic_uuid_random_generator<T>` is a class template for generating random or pseudo-random UUIDs (version 4, i.e. `uuid_version::random_number_based`). The type template parameter represents a function object that implements both the [`RandomNumberEngine`](http://en.cppreference.com/w/cpp/concept/UniformRandomBitGenerator) and [`UniformRandomBitGenerator`](http://en.cppreference.com/w/cpp/concept/RandomNumberEngine) concepts. `basic_uuid_random_generator` can be either default constructed or constructed with a reference or pointer to a an objects that satisfies the `UniformRandomNumberGenerator` requirements.
```
```cpp
template <typename UniformRandomNumberGenerator>
class basic_uuid_random_generator
{
@ -407,11 +407,11 @@ public:
};
```
A type alias `uuid_random_generator` is provided for convenience as `std::mt19937` is probably the preferred choice of a pseudo-random number generator engine in most cases.
```
```cpp
using uuid_random_generator = basic_uuid_random_generator<std::mt19937>;
```
`uuid_name_generator` is a function object that generates new UUIDs from a name. It has to be initialized with another UUID and has overloaded `operator()` for both `std::string_view` and `std::wstring_view`.
```
```cpp
class uuid_name_generator
{
public:
@ -426,7 +426,7 @@ public:
### Specialization
The template specializations of `std::hash` for the `uuid` class allow users to obtain hashes of UUIDs.
```
```cpp
namespace std {
template <>
struct hash<uuid>