boost中的实用工具assign和uuid
2016-03-24 22:04
423 查看
assign
assign重载‘+’=和‘,’实现连续赋值assign不仅支持全部8个STL标准容器(vector、string、deque、list、set、multiset、map、multimap),也对stl中的容器适配器提供了适当的支持,包括queue和priority_queue
示例代码:
int testAssign() { using namespace boost::assign; // overload operator '+=' & ',' 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"); // overload '()' 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; }
相关文章推荐
- Patchwork & Quilting(拼布和绗缝)
- Patchwork & Quilting(拼布和绗缝)
- poj2478 Farey Sequence (欧拉函数)
- android控件 —— QuickContacBadge
- easyui datagrid 添加href 泛型
- QuickSort快排详细解释
- codeforces301A. Yaroslav and Sequence
- Ubuntu Nagios Quickstart
- Fedora Nagios Quickstart
- openSUSE Nagios Quickstart
- Translation:How to build Tesseract 3.03 with Visual Studio 2013 (翻译《VS2013 建立tesseract3.03工程》)
- VirtualBox Guest Additions install on Ubuntu and RHEL
- QuickSort快排详细解释
- LightOJ 1073 DNA Sequence (状压DP+字符串比较)
- LeetCode#103. Binary Tree Zigzag Level Order Traversal My Submissions Question
- LeetCode#102. Binary Tree Level Order Traversal My Submissions Question
- Yet Another Number Sequence——[矩阵快速幂]
- apue chapter 4 文件和目录
- 关于JavaSE ProcessBuilder的使用细节
- 187. Repeated DNA Sequences | Java最短代码实现