Boost UUID learning notes

Source: Internet
Author: User

# Include <vector>
# Include <iostream>
# Include <boost/UUID. HPP>
# Include <boost/UUID/uuid_generators.hpp>
# Include <boost/UUID/uuid_io.hpp>
Using namespace boost: uuids;
Using namespace STD;
Int main ()
{
//-------------------------
// Some STD function applications
//-------------------------
Vector <unsigned int> V (16, 7 );
Uuid u;
STD: Copy (V. Begin (), V. End (), u. Begin (); // copy a sequence to another sequence (from begin to end)
STD: fill_n (U. Data + 2, 6, 8); // assign the six values after the second serial number of the array to 8
Cout <"/n u first print:" <u <Endl;
STD: memset (U. Data, 0, U. Size (); // set all elements in the array to zero.
Cout <"UUID is empty:" <u. is_nil () <Endl; // whether all data is zero
Cout <"U second print:" <u <Endl; // output again
//--------------------------
// Compare UUID (Lexicographic Order 1 ~ 9, ~ Z sorting)
//--------------------------
UUID u1, U2;
STD: fill_n (u1.begin (), u1.size (), 0xab); // starting from the first bit, after which the size () bit is assigned to 0xab
STD: fill_n (u2.begin (), u2.size (), 0x10 );
Cout <"uuid1:" <U1 <Endl <"uuid2:" <U2 <Endl;
(U1> = u2 )? Cout <"uuid1 is Max equal to uuid2/N": cout <"uid2 is Max to uuid1/N ";
//--------------------------
// Several UUID generators, all of which are function objects
//--------------------------
// First:
// Nil generator (generate a completely zero/invalid UUID/is_nil)
UUID niluuid1 = nil_generator (); // The first bracket is the constructor, and the second is the call of the overload operator ())
UUID niluuid2 = nil_uuid (); // Inline Function
Cout <"niluid1:" <niluid1 <Endl;
Cout <"niluid2:" <niluid2 <Endl;
// Second:
// String generator (but a string range specified by the C array, String, wstring, or iterator)
String_generator sgen;
UUID struuid1 = sgen ("0123456789abcdef0123456789uvwxyz"); // if there is no separator, uvwxyz will become ffffff
UUID struuid2 = sgen ("01234567-89ab-cdef-0123-456789abcdef"); // The separator must be separated.
UUID struuid3 = sgen (L "{01234567-89ab-cdef-0123-456789abcdef}"); // use "{}" to include no hexadecimal characters {}
Cout <"struuid1 value:" <struuid1 <Endl;
Cout <"struuid2 value:" <struuid2 <Endl;
Cout <"struuid3 value:" <struuid3 <Endl;
// The third type:
// Name generator (the parameter can be a character other than hexadecimal characters)
UUID baseuuid = sgen (L "{01234567-89ab-cdef-0123-456789abcdef }");
Name_generator ngen (baseuuid); // construct the name generator. A reference UUID is required,
// As long as the benchmark UUID remains unchanged, the same string always produces the same UUID
UUID nameuuid1 = ngen ("Ajiaxi"); // generates a uuid for Ajiaxi. The version is the shal algorithm.
UUID nameuuid2 = ngen ("Link"); // generate a uuid for the link
Cout <"nameuuid1 value:" <nameuuid1 <Endl;
Cout <"nameuuid2 value:" <nameuuid2 <Endl;
// Category 4:
// Random generator (use boost: Random to generate random seeds)
Random_generator rgen;
UUID ranuuid = rgen (); // generate a random UUID
Cout <"ranuuid value:" <ranuuid <Endl;
Getchar ();
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.