C++ std::pair, std::tuple
来源:互联网 发布:千兆端口无线路由器 编辑:程序博客网 时间:2024/05/09 17:55
std::pair 定义于<utility>
template <class T1, class T2> struct pair;
Pair of values
This class couples together a pair of values, which may be of different types (T1 and T2). The individual values can be accessed through its public members first and second.std::tuple 定义于<tuple>
Tuple library
Tuples are objects that pack elements of -possibly- different types together in a single object, just like pairobjects do for pairs of elements, but generalized for any number of elements.Conceptually, they are similar to plain old data structures (C-like structs) but instead of having named data members, its elements are accessed by their order in the tuple.The selection of particular elements within a tuple is done at the template-instantiation level, and thus, it must be specified at compile-time, with helper functions such as get and tie.The tuple class is closely related to the pair class (defined in header <utility>): Tuples can be constructed from pairs, and pairs can be treated as tuples for certain purposes.array containers also have certain tuple-like functionalities.#include <iostream>#include <tuple>#include <string>#include <utility>#include <stdexcept>std::tuple<double, char, std::string> get_student(int id) { if (id == 0) return std::make_tuple(98.5, 'A', "qsa"); if (id == 1) return std::make_tuple(77.0, 'B', "bb"); throw std::invalid_argument("error !");}int main() { auto student = get_student(0); std::cout << "score " << std::get<0>(student) << " level " << std::get<1>(student) << " name " << std::get<2>(student) << std::endl; double score; char level; std::string name; std::tie(score, level, name) = get_student(1); std::cout << "score " << score << " level " << level << " name " << name << std::endl; std::pair<int, char> mypair(100, 'A'); auto coll = std::tuple_cat(student, mypair); std::cout << std::get<0>(coll) << std::endl; std::cout << std::get<1>(coll) << std::endl; std::cout << std::get<2>(coll) << std::endl; std::cout << std::get<3>(coll) << std::endl; std::cout << std::get<4>(coll) << std::endl;}
- C++ std::pair, std::tuple
- std::pair
- std::pair<>
- Boost源码剖析之:增强的std::pair--Tuple Types
- std::pair 与 std::make_pair
- std::pair 与 std::make_pair
- std::pair, std::copy, std::lower_bound, std::back_insert使用
- 扩展std::pair
- C++ std::pair
- C++ std::pair
- C++ std::pair
- (15) C++ std::pair
- C++ STL std::pair
- C++ std::pair<>
- C++ std::pair
- std::pair的使用
- 遍历std::tuple
- std::set 和 std::pair 搭配使用
- 程序员修炼之道:从小工到专家(奋斗的小鸟)_PDF 电子书
- OCP-1Z0-052-V8.02-172题
- 编写安全代码:不要在头文件中定义变量
- Qt5.1.1环境搭建
- 软件开发这点事儿:软件开发工具手册(奋斗的小鸟)_PDF 电子书
- C++ std::pair, std::tuple
- 找重量不一样的硬币
- 面试经验
- APDU命令集
- 修改代码的艺术(奋斗的小鸟)_PDF 电子书
- 语音知识回顾和总结---短时频域性质
- 最小C基础库
- Django学习整理
- 黑马程序员——简单画板的制作