zoukankan      html  css  js  c++  java
  • boost uuid

    UUIDs are used by distributed systems that have to uniquely identify components. For example, Microsoft uses UUIDs to identify interfaces in the COM world. For new interfaces developed for COM, unique identifiers can be easily assigned.

    UUIDs are 128-bit numbers. Various methods exist to generate UUIDs. For example, a computer’s network address can be used to generate a UUID. The generators provided by Boost.Uuid are based on a random number generator to avoid generating UUIDs that can be traced back to the computer generating them.

    1. boost::uuids::random_generator

    #include <boost/uuid/uuid.hpp>
    #include <boost/uuid/uuid_generators.hpp>
    #include <boost/uuid/uuid_io.hpp>
    #include <iostream>
    
    using namespace boost::uuids;
    
    int main()
    {
      random_generator gen;
      uuid id = gen();
      std::cout << id << std::endl;
      std::cout << id.size() << std::endl;
      std::cout << std::boolalpha << id.is_nil() << std::endl;
      std::cout << id.variant() << std::endl;
      std::cout << id.version() << std::endl;
    return 0; }

    size() returns the size of a UUID in bytes. Because a UUID is always 128 bits, size() always returns 16. is_nil() returns true if the UUID is a nil UUID. variant() and version() specify the kind of UUID and how it was generated.

    2. conversion to strings

    #include <boost/uuid/uuid.hpp>
    #include <boost/uuid/uuid_generators.hpp>
    #include <boost/uuid/uuid_io.hpp>
    #include <boost/lexical_cast.hpp>
    #include <string>
    #include <iostream>
    
    using namespace boost::uuids;
    
    int main()
    {
      random_generator gen;
      uuid id = gen();
    
      std::string s = to_string(id);
      std::cout << s << std::endl;
    
      std::cout << boost::lexical_cast<std::string>(id) << std::endl;
    
      return 0;
    }

    uses boost::uuids::to_string() or boost::lexical_cast()

  • 相关阅读:
    P2617 Dynamic Rankings 动态主席树
    P4338 [ZJOI2018]历史 LCT+树形DP
    P3348 [ZJOI2016]大森林
    P3613 睡觉困难综合征 LCT+贪心+位运算
    SP16549 QTREE6
    P3703 [SDOI2017]树点涂色 LCT维护颜色+线段树维护dfs序+倍增LCA
    U19464 山村游历(Wander) LCT维护子树大小
    P4219 [BJOI2014]大融合 LCT维护子树大小
    P2542 [AHOI2005]航线规划 LCT维护双连通分量
    P3950 部落冲突
  • 原文地址:https://www.cnblogs.com/sssblog/p/11347449.html
Copyright © 2011-2022 走看看