mirror of
https://github.com/boostorg/uuid.git
synced 2026-01-19 04:42:16 +00:00
Remove 'POD Efficiencies' example as it's no longer relevant
This commit is contained in:
@@ -59,70 +59,6 @@ assert(o1 != o3);
|
||||
assert(o2 != o3);
|
||||
----
|
||||
|
||||
== POD Efficiencies
|
||||
|
||||
This library implements a UUID as a POD allowing a UUID to be used in the most efficient ways, including using `memcpy`, and aggregate initializers.
|
||||
A drawback is that a POD can not have any constructors, and thus declaring a UUID will not initialize it to a value generated by one of the defined mechanisms.
|
||||
But a class based on a UUID can be defined that does initialize itself to a value generated by one of the defined mechanisms.
|
||||
|
||||
[source,c++]
|
||||
----
|
||||
// example using memcpy and aggregate initializers
|
||||
// example of a class uuid see boost/libs/uuid/test/test_uuid_class.cpp
|
||||
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <cstring>
|
||||
|
||||
{ // example using memcpy
|
||||
unsigned char uuid_data[16];
|
||||
// fill uuid_data
|
||||
|
||||
boost::uuids::uuid u;
|
||||
|
||||
std::memcpy(&u.data, uuid_data, 16);
|
||||
}
|
||||
|
||||
{ // example using aggregate initializers
|
||||
boost::uuids::uuid u =
|
||||
{{ 0x12 ,0x34, 0x56, 0x78
|
||||
, 0x90, 0xab
|
||||
, 0xcd, 0xef
|
||||
, 0x12, 0x34
|
||||
, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef
|
||||
}};
|
||||
}
|
||||
|
||||
// example of creating a uuid class that
|
||||
// initializes the uuid in the constructor
|
||||
// using a defined mechanism
|
||||
|
||||
class uuid_class : public boost::uuids::uuid
|
||||
{
|
||||
public:
|
||||
uuid_class()
|
||||
: boost::uuids::uuid(boost::uuids::random_generator()())
|
||||
{}
|
||||
|
||||
explicit uuid_class(boost::uuids::uuid const& u)
|
||||
: boost::uuids::uuid(u)
|
||||
{}
|
||||
|
||||
operator boost::uuids::uuid() {
|
||||
return static_cast<boost::uuids::uuid&>(*this);
|
||||
}
|
||||
|
||||
operator boost::uuids::uuid() const {
|
||||
return static_cast<boost::uuids::uuid const&>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
uuid_class u1;
|
||||
uuid_class u2;
|
||||
|
||||
assert(u1 != u2);
|
||||
----
|
||||
|
||||
== Byte Extraction
|
||||
|
||||
It is sometimes useful to get at the 16 bytes of a `uuid` directly. Typical use is as follows:
|
||||
|
||||
Reference in New Issue
Block a user