assign
- assign重载‘+’=和‘,’实现连续赋值
- assign不仅支持所有8个STL标准容器(vector、string、deque、list、set、multiset、map、multimap)。也对stl中的容器适配器提供了适当的支持,包括queue和priority_queue
- 演示样例代码:
int testAssign()
{
using namespace boost::assign;
vector<int> v;
v += 1, 2, 3, 4, 5, 6 * 6;
set<string> s;
s += "cpp", "java", "c#", "python";
map<int, string> m;
m += make_pair(1, "one"), make_pair(2, "two");
vector<int> v1;
push_back(v)(1)(2)(3)(4)(5);
return 0;
}
uuid
- 生成各种各样的uuid
- 在用string_generator时。须要加入宏定义_SCL_SECURE_NO_WARNINGS;
- 在使用cout << uuid 和 to_string(uuid)时。须要包括uuid_io.hpp
- 应用实例:
int testUuid()
{
boost::uuids::string_generator sgen;
boost::uuids::uuid u = sgen("01234567-89ab-cdef-0123-456789abcdef");
string str = to_string(u);
cout << "u : " << u << endl;
cout << "str : " << str << endl;
using namespace boost::uuids::detail;
sha1 sha;
char *szMsg = "a short message";
sha.process_byte(0x10);
sha.process_bytes(szMsg, strlen(szMsg));
sha.process_block(szMsg, szMsg + strlen(szMsg));
unsigned int digest[5];
sha.get_digest(digest);
for (int i = 0; i < 5; ++i)
{
cout << hex << digest[i];
}
return 0;
}