簡介
? 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>