array
dynamic_bitset
- test:第n位是否为1
- any:如果存在1,返回true
- none:不存在1,返回true
- count:容器中所有值为1的元素的数量
- set:置全部或特定的位置值为1或0
- reset:置全部或特定位置的值为0
- flip:反转全部或特定位置的值
- find_first:从0位开始查找,返回第一个值为1的位置
- find_next(pos):从pos开始查找,返回第一个值为1的位置,找不到返回npos
- to_ulong:转成一个unsigned long
- 一些集合操作
1 2 3 4 5 6 7 8 9 10 |
dynamic_bitset<> db1(); dynamic_bitset<> db2(10); dynamic_bitset<> db3(0x16, BOOST_BINARY(10101)); dynamic_bitset<> db4(string("0100")); db2.resize(10, true); db2.resize(5); db2[0] &= 1; db2[1] ^= 1; |
unordered
- boost库的一个完全符合C++标准的散列容器实现,包括无序集合unordered_set和无序映射unordered_map。
unordered_set
1 2 3 4 5 6 |
unordered_set<int> a = {1, 2, 3, 4, 5}; a.insert(8); a.insert(33); a.erase(33); |
unordered_map
- 都与标准库的类似。
bitmap
- set_of
- multiset_of
- unordered_multiset_of
- list_of
- vector_of
- unconstrained_set_of
- unordered_set_of
1 2 3 4 5 6 7 |
bitmap<int string> bm; bm.left.insert(make_pair(1, "111")); bm.left.insert(make_pair(2, "222")); bm.right.insert(make_pair("string", 10)); bm.right.insert(make_pair("bimap", 20)); |
circular_buffer
- 实现了循环缓冲区的数据结构。
- full:判断缓冲区是否已满
- linearize:把缓冲区线性化成一个连续的普通数组
- is_linearized:检测缓冲区是否已成线性化
- rotate:从指定的迭代器位置旋转整个缓冲区
1 |
circular_buffer<int> cb(5); // 空间为5的缓冲区 |
circular_buffer_space_optimized
tuple
- 元组。
pair
- 二元组
tuple
- pair的泛化
make_pair
1 2 3 4 5 6 |
make_tuple(2, 3.0); int i; double d; string s; tie(i, d, s) = make_pair(1, 2.0, "string"); |
any
- 能够容纳任意类型。
1 2 3 4 5 6 |
any a(100); a = string("test"); a = vector<vector<int>>(); any b = make_ptr_any<vector<int>>(new vector<int>); |
variant
- 与any类似,是一种可变类型。已入C++17.
1 2 3 |
variant<int, float, string> v; v = "123"; std::cout << v << std::endl; |
multi_array
- 多维容器。
- reshape改变多维数组的形状。改变各个维度的大小。总维数和元素数量不变。
- 切片实现。
1 2 3 |
multi_array<int, 3> ma; // 相当于int ma[x][y][z]; |
property_tree
- 保存多个属性值的树形数据结构。
- xml、json、ini、info等格式·
1 2 3 4 5 6 7 8 9 |
<conf> <gui>1</gui> <theme>matrix</theme> <urls> <url>www.baidu.com</url> <url>www.bb.com</url> </urls> <clock_style>24</clock_style> </conf> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
ptree pt; read_xml("conf.xml", pt); pt.get<string>("conf.theme"); pt.get<int>("conf.clock_style"); pt.get<int>("conf.no_prop", 100);// 不存在就返回100 // 对于有多个子节点的 auto child = pt.get_child("conf.urls"); for(auto& x : child) { std::cout << x.second.get_value<string>() << std::endl; } // 写信息 pt.put("conf.theme", "matrix reloaded"); pt.put("conf.clock_style", 12); pt.put("conf.urls.url", "www.aa.com"); // 添加 pt.add("conf.urls.url", "www.qq.com"); |
foreach
1 2 3 4 5 |
vector<int> v = (list_of(1), 2, 3, 4, 5); BOOST_FOREACH(auto x, v) { std::cout << x << std::endl; } |
minmax
- 返回由小值和大值组成的tuple。
minmax_element
- 从一个序列的区间查找第一次出现的最大值和最小值,返回pair
clamp
- 判断一个值是否夹在另外一对值之间。
clamp_range
- 迭代器版本。
hex/unhex
- 十六进制的编码和解码。
math.constants
- pi
- e
- root_two
- root_three
- ln_two
integer_traits
- 整数特征类。继承自std::numeric_limits。
1 2 3 4 5 |
using namespace std; cout << integer_traits<int>::const_max << endl; cout << integer_traits<long>::const_min << endl; cout << integer_traits<long>::is_signed << endl; |
cstdint
rational
- 有理数(分数)。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
rational<int> a; // 0 rational<int> b(20); // 20 rational<int> c(31415, 10000); // 3.1415 // 分子 c.numerator(); // 分母 c.denominator(); //最大公约数 gcd(); // 最小公倍数 lcm(); |
ratio
- 单位。
crc
- 循环冗余校验码。
1 2 3 4 5 6 7 8 9 |
crc_32_type crc32; std::cout << hex; std::cout << crc32.checksum() << std::endl; crc32.process_byte('a'); std::cout << crc32.checksum() << std::endl; crc32.process_bytes("1234567890", 10); std::cout << crc32.checksum() << std::endl; |
random
- 很多伪随机数分布器。
1 2 3 4 5 6 7 8 |
// 随机数发生器mt19937 mt19937 rng(time(0)); random::uniform_int_distribution<> ui(0, 255); for (size_t i = 0; i < 10; ++i) { std::cout << ui(rng) << std::endl; } |
system
- 封装了操作系统底层的错误代码和错误信息。
chrono
- 时间处理库。
cpu_timer
- 微妙级别的计时。
filesystem
- 跨平台操作目录,文件的库,收入了C++17.
program_options
- 命令行参数解析配置选项。
声明:本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ COM组件_303/07
- ♥ 深入理解C++11:C++11新特性解析与应用 一12/21
- ♥ STL_stack05/19
- ♥ 编译器扩展语法:一07/06
- ♥ breakpad记述:Windows07/27
- ♥ C++_运算符优先级&&相关性12/15