C++ Tuple 库 - (constructor)
描述
它构造一个元组对象并涉及单独构造其元素,其初始化取决于调用的构造函数形式。
声明
以下是 std::tuple::tuple 的声明。
C++98
constexpr tuple();
C++11
constexpr tuple();
参数
默认构造函数是一个元组对象,其元素值已初始化。
返回值
none
异常
No-throw guarantee − 这个成员函数从不抛出异常。
数据竞争
访问 tpl 和 pr 的元素。
示例
在下面的 std::tuple::tuple 示例中。
#include <iostream>
#include <utility>
#include <tuple>
int main () {
std::tuple<int,char> first;
std::tuple<int,char> second (first);
std::tuple<int,char> third (std::make_tuple(20,'b'));
std::tuple<long,char> fourth (third);
std::tuple<int,char> fifth (10,'a');
std::tuple<int,char> sixth (std::make_pair(30,'c'));
std::cout << "fourth contains: " << std::get<0>(sixth);
std::cout << " and " << std::get<1>(fourth) << '\n';
return 0;
}
输出应该是这样的 −
fourth contains: 30 and b

