构造

  构造函数

   tuple的构造函数很普通,没啥说的。

default (1)
  1. constexpr tuple();默认构造函数
copy / move (2)
  1. tuple (const tuple& tpl) = default; 拷贝构造函数
  2. tuple (tuple&& tpl) = default;移动构造函数
implicit conversion (3)
  1. template <class... UTypes>
  2. tuple (const tuple<UTypes...>& tpl); 广义拷贝构造函数,只要对应参数可以默认转换
  3. template <class... UTypes>
  4. tuple (tuple<UTypes...>&& tpl); 广义移动构造函数,只要对应参数可以默认转换
initialization (4)
  1. explicit tuple (const Types&... elems);构造并初始化
  2. template <class... UTypes>
  3. explicit tuple (UTypes&&... elems);构造并初始化,参数类型只要求可以默认转换
conversion from pair (5)
  1. template <class U1, class U2>
  2. tuple (const pair<U1,U2>& pr); pair构造
  3. template <class U1, class U2>
  4. tuple (pair<U1,U2>&& pr);

allocator (6)

在以上5类的基础上增加分配器参数,第一个参数无实际意义,只用来与(3)进行区别。

  1. template<class Alloc>
  2. tuple (allocator_arg_t aa, const Alloc& alloc);
  3. template<class Alloc>
  4. tuple (allocator_arg_t aa, const Alloc& alloc, const tuple& tpl);
  5. template<class Alloc>
  6. tuple (allocator_arg_t aa, const Alloc& alloc, tuple&& tpl);
  7. template<class Alloc,class... UTypes>
  8. tuple (allocator_arg_t aa, const Alloc& alloc, const tuple<UTypes...>& tpl);
  9. template<class Alloc, class... UTypes>
  10. tuple (allocator_arg_t aa, const Alloc& alloc, tuple<UTypes...>&& tpl);
  11. template<class Alloc>
  12. tuple (allocator_arg_t aa, const Alloc& alloc, const Types&... elems);
  13. template<class Alloc, class... UTypes>
  14. tuple (allocator_arg_t aa, const Alloc& alloc, UTypes&&... elems);
  15. template<class Alloc, class U1, class U2>
  16. tuple (allocator_arg_t aa, const Alloc& alloc, const pair<U1,U2>& pr);
  17. template<class Alloc, class U1, class U2>
  18. tuple (allocator_arg_t aa, const Alloc& alloc, pair<U1,U2>&& pr);
  1. 获取tuple的分量
      get模板函数可以获取tuple分量的引用,如下图所声明的,常量tuple获得常量引用,右值引用tuple获得右值引用,非常量非右值引用获得引用。
(1)
  1. template <size_t I, class... Types>
  2. typename tuple_element< I, tuple<Types...> >::type& get(tuple<Types...>& tpl) noexcept;
(2)
  1. template <size_t I, class... Types>
  2. typename tuple_element< I, tuple<Types...> >::type&& get(tuple<Types...>&& tpl) noexcept;
(3)
  1. template <size_t I, class... Types>
  2. typename tuple_element< I, tuple<Types...> >::type const& get(const tuple<Types...>& tpl) noexcept;

std::make_tuple

  1.   template<class... Types>
  2.   tuple<VTypes...> make_tuple (Types&&... args);  
      make_tuple模板函数,根据实参类型生成一个tuple,并用实参的值对其进行初始化。编译器在推断tuple各分量的类型时会去掉实参的顶级const属性、引用属性(包括右值引用),也就是说造出来的tuple存的是值。数组会推断为指针、函数会推断为函数指针。如果需要推断出引用类型,要借助std::refstd::cref
     
  1.   

std::tie

  1. template<class... Types>
  2. constexpr tuple<Types&...> tie (Types&... args) noexcept;
      tie生成一个tuple,此tuple包含的分量全部为实参的引用,与make_tuple完全相反。主要用于从tuple中提取数据。例如:
      int a,b,c;
      auto x = make_tuple(1,2,3);
      std::tie(a,b,c) = x;
  3.  

std::forward_as_tuple

template<class... Types>

constexpr tuple<Types&&...> forward_as_tuple(Types&&...)noexcept;

同std::tie一样,也是生成一个全是引用的tuple,不过std::tie只接受左值,而std::forward_as_tuple左值、右值都接受。主要是用于不损失类型属性的转发数据。

std::tuple_cat

template<class... Tuples>

tuple<CTypes...> tuple_cat(Tuples&&... tlps);

此函数接受多个tuple作为参数,然后返回一个tuple。返回的这个tuple将tuple_cat的参数中的tuple的所有元素按所属的tuple在参数中的顺序以及其在tuple中的顺序排列成一个新的tuple。新tuple中元素的类型与参数中的tuple中的元素的类型完全一致。

template<class... Types>

struct tuple_size<tuple<Types...>>;

tuple_size为辅助类,用于获取tuple中元素的个数。用法为:tuple_size<decltype(tuple)>::value

template<size_t I,class... Types>

struct tuple_element<I,tuple<Types ...>>;

tuple_element为辅助类,用于获取tuple中某个元素的类型。用法为:tuple_size<1,decltype(tuple)>::type

C++标准库之tuple的更多相关文章

  1. C/C++基础----标准库几个工具库tuple,bitset,正则表达式,随机数,IO库

    tuple tuple可以有任意多个成员 默认初始化,值初始化 构造函数是explicit,必须直接初始化 make_tuple(v1,v2,-,vn) get<i> (t) 返回第i个数 ...

  2. Python标准库13 循环器 (itertools)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在循环对象和函数对象中,我们了解了循环器(iterator)的功能.循环器是对象的 ...

  3. 【循序渐进学Python】11.常用标准库

    安装完Python之后,我们也同时获得了强大的Python标准库,通过使用这些标准库可以为我们节省大量的时间.这里是一些常用标准库的简单说明.更多的标准库的说明,可以参考Python文档 sys 模块 ...

  4. Boost程序库完全开发指南——深入C++“准”标准库(第3版)

    内容简介  · · · · · · Boost 是一个功能强大.构造精巧.跨平台.开源并且完全免费的C++程序库,有着“C++‘准’标准库”的美誉. Boost 由C++标准委员会部分成员所设立的Bo ...

  5. 读书笔记 effective c++ Item 54 让你自己熟悉包括TR1在内的标准库

    1. C++0x的历史渊源 C++标准——也就是定义语言的文档和程序库——在1998被批准.在2003年,一个小的“修复bug”版本被发布.然而标准委员会仍然在继续他们的工作,一个“2.0版本”的C+ ...

  6. python 标准库 -- subprocess

    subprocess 主要功能室执行外部的命令和程序 一个进程可 fork 一个子进程, 并让这个子进程 exec 另外一个程序. 在 python 中, 可以通过标准库中的 subprocess 包 ...

  7. C++相关:部分标准库特殊设施

    C++ tuple(元组) tuple是C++11新标准里的类型.它是一个类似pair类型的模板.pair类型是每个成员变量各自可以是任意类型,但是只能有俩个成员,而tuple与pair不同的是它可以 ...

  8. collections标准库

    collections标准库 之前Python的第三方库用的一直很舒服,现在突然发现标准库也有collections这样的神器,可以补充list.set.dict以外的应用 1. namedtuple ...

  9. python第六天 函数 python标准库实例大全

    今天学习第一模块的最后一课课程--函数: python的第一个函数: 1 def func1(): 2 print('第一个函数') 3 return 0 4 func1() 1 同时返回多种类型时, ...

随机推荐

  1. Delphi 7下最小化到系统托盘

    在Delphi 7下要制作系统托盘,只能制作一个比较简单的系统托盘,因为ShellAPI文件定义的TNotifyIconData结构体是比较早的版本.定义如下: 123456789   _NOTIFY ...

  2. Solr6.6 配置中文分词库mmseg4j

    1.准备 首先安装solr:参照搜索引擎Solr-6.6.0搭建,如果版本高于6,可能会不支持,需要改mmseg4j包 mmseg4j包下载: mmseg4j-solr-2.3.0-with-mmse ...

  3. Java笔记4:JDBC纯驱动方式连接Oracle

    JDBC纯驱动方式连接Oracle 1 下载Oracle提供的驱动程序包 下载地址: http://www.oracle.com/technetwork/database/enterprise-edi ...

  4. 【前后台分离模式下,使用OAuth Token方式认证】

    AngularJS is an awesome javascript framework. With it’s $resource service it is super fast and easy ...

  5. ubuntu vim markdown 实时预览

    vim-instant-markdown插件 该插件支持vim编辑markdown文件时实时预览,不需要手动做任何事情! 使用vim打开一个xxx.md文件,浏览器会自动打开一个预览网页,在编辑这个文 ...

  6. Solr删除数据

    步骤: 1.在Solr客户端左下方 Core Selector 中点选想要删除数据的索引库 2.点选Documents 3.右侧Document Type中点选XML 4.Document(s)中输入 ...

  7. BZOJ 4174 tty的求助 莫比乌斯反演

    题目大意:求∑Nn=1∑Mm=1∑m−1k=0⌊nk+xm⌋ mod 998244353 如果n和m都已经确定了.如今要求这坨玩应: ∑m−1k=0⌊nk+xm⌋ =∑m−1k=0(⌊nk%m+xm⌋ ...

  8. C# 多线程控制 通讯

    一.多线程的概念  Windows是一个多任务的系统,如果你使用的是windows 2000及其以上版本,你可以通过任务管理器查看当前系统运行的程序和进程.什么是进程呢?当一个程序开始运行时,它就是一 ...

  9. hibernate学习系列-----(7)hibernate对集合属性的操作之List集合篇

    今天要写的内容其实不多,本打算将hibernate对集合的操作的内容直接归结为一篇的,但想一想,还是分开写的比较好,毕竟前面的已经发布出去来了,废话不多说,开始吧! 依旧新建一个StudentList ...

  10. python基础语法(一)

    Python的特点 1. 简单 Python是一种代表简单思想的语言. 2. 易学 Python有极其简单的语法. 3. 免费.开源 Python是FLOSS(自由/开放源码软件)之一. 4. 高层语 ...