简介
• Class pair<> and class tuple<>
• Smart pointer classes (class shared_ptr<> and class unique_ptr)
• Numeric limits
• Type traits and type utilities
• Auxiliary functions (for example, min(), max(), and swap())
• Class ratio<>
• Clocks and timers
• Some important C functions
pairs

1,具有成员模板构造函数(当pair类型不同但可以隐式类型转换时调用)
2,pair的成员的类型的拷贝构造函数必须是常量引用
tuples
扩展pair,使得tuple支持多个元素

1,使用get<0>(t)等获取每个元素
2,赋值操作时右操作数必须显式的为tuple类型,不支持隐式转换
tuple_size<tupletype>::value返回tuple的元素个数
tuple_element<index, tupletype>::type返回tuple的第index个元素的类型
tuple_cat()将多个tuple组合为一个整体
shared_ptr
多个指针共享同一资源,当最后一个指针销毁时会将资源释放。



1,weak_ptr的的拷贝和赋值不会增加或减少对应的shared_ptr的引用计数
2,使用lock()函数获取weak_ptr绑定的shared_ptr



数值极限<limits>



类型萃取<type_traits>
A type trait provides a way to deal with the properties of a type. It is a template, which at compile time yields a specific type or value based on one or more passed template arguments, which are usually types.





引用转换
std::reference_wrapper<>定义在<functional>,将参数转化为引用类型来适用函数模板std::vector<std::reference_wrapper<MyClass>> coll; // OK
比较辅助函数
定义在<algorithm>

std::swap函数定义在<utility>
编译时分数计算类
ratio<>定义在<ratio>
例如ratio<3, 5>表示五分之三,类成员num,den分别表示分子和分母

例如std::ratio_add<std::ratio<2, 7>, std::ratio<2,6>>::type为std::ratio<13, 21>

例如std::nano,等价于std::ratio<1, 1000000000LL>
网友评论