c++ tuple的操作
来源:互联网 发布:我的世界 知乎 编辑:程序博客网 时间:2024/06/07 00:00
tuple(不定数值组)的操作
1.初始化 见Init()//class tuple<>构造函数是
explicit的,因此不支持隐式转换
2.其他tuple的特性 见special
3.tuple的输出 见output()等
#include<iostream>#include<tuple>using namespace std;void Init(){ //常规初始化 tuple<int, double, string> t1(3, 3.14, "Wh");//... //用pair初始化tuple pair<int, double> p(2, 3); tuple<int, double> t2(p); //other int a = 3; double b = 3.14; //tie()更多见 tieIntuple() tuple<int&, double&> p3 = tie(a, b); auto p4 = make_tuple(ref(a), ref(b));}void tieIntuple(){ int a = 4; double b = 4.2; //tie返回的类型是tuple<int&,double&> tuple<int, double> p1 = tie(a, b); tuple<int&, double&> p2 = tie(a, b); --a; b = 5.3; cout << get<0>(p1) << ends << get<1>(p1) << endl; cout << get<0>(p2) << ends << get<1>(p2) << endl; //通过tie()得到特定位置的值 double d = 0.0; tie(ignore, d) = p2; cout << d << endl;}void special(){ //得到类型个数 cout << tuple_size < tuple<int, double, double>>::value; //得到指定位置类型 tuple_element<1, tuple<int, double, double>>::type d = 3.14; cout << d << endl; //将多个tuple串接成一个tuple auto tp = tuple_cat(make_tuple(3.22, 3), tie(d));}template<int Index,int Max,typename ...Args>struct PRINT_TUPLE{ static void print(ostream& os, const tuple<Args...>& t) { os << get<Index>(t) << (Index + 1 == Max ? "" : ","); PRINT_TUPLE<Index + 1, Max, Args...>::print(os, t); }};template<int Max,typename ...Args>struct PRINT_TUPLE<Max, Max, Args...>{ //无实例调用必须声明为静态方法 static void print(ostream& os,const tuple<Args...>& t) { }};template<typename ...Args>ostream& operator <<(ostream& os, const tuple<Args...>& t){ os << "["; PRINT_TUPLE<0, sizeof...(Args), Args...>::print(os, t); return os << "]";}void output(){ tuple<int, double, double> t(3, 2.33, 3.22); cout << t;}int main(){ //Init(); //tieIntuple(); //special(); output(); system("pause"); return 0;}
1 0
- c++ tuple的操作
- C#Tuple的用法
- C#Tuple的用法
- c++ tuple的基本操作
- Python中元组tuple的操作
- c++ pair和tuple的操作
- list set dict tuple的基本操作
- python基础--tuple操作
- Scala的Tuple、Array、Map和文件操作
- python学习笔记(6):tuple的基本操作
- Python的字符串,list,tuple,set,字典操作详解
- 【python学习笔记】6.list和tuple的操作
- Python的list、tuple、set、dictionary操作总结
- Boost C++: 数据结构---tuple
- [C++]tuple简介
- scala Map 和 Tuple操作
- Python——tuple操作
- Python的tuple
- jq-easyUI
- 抽象类(abstract class)和接口(interface)有什么异同
- spark数据分析之ip归属地查询
- 二叉树的非递归遍历
- expect脚本实例
- c++ tuple的操作
- Ubuntu下配置git
- 为Linux技术学习推荐看的书籍—《Linux就该这么学》
- save命令+get命令+start命令+edit命令+spool命令+临时变量+已定义的变量
- 如何将硬盘从一个虚拟机添加到另一个虚拟机
- Centos安装Sublime text 3
- Unable to connect to Command Metric Stream.解决方案
- SPARK:sortByKey和sortBy 函数讲解
- Java设计模式——模板方法(Template Method)以及策略模式比较