首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::tuple_element<std::tuple>

Defined in header <tuple>

template< std::size_t I, class T > class tuple_element; /* undefined */

(1)

(since C++11)

template< std::size_t I, class... Types > class tuple_element< I, tuple<Types...> >;

(2)

(since C++11)

Defined in header <tuple>

Defined in header <array> Defined in header <utility>

(since C++17)(since C++17)

template< std::size_t I, class T > class tuple_element< I, const T > { typedef typename std::add_const<typename std::tuple_element<I, T>::type>::type type; };

(3)

(since C++11)

template< std::size_t I, class T > class tuple_element< I, volatile T > { typedef typename std::add_volatile<typename std::tuple_element<I, T>::type>::type type; };

(4)

(since C++11)

template< std::size_t I, class T > class tuple_element< I, const volatile T > { typedef typename std::add_cv<typename std::tuple_element<I, T>::type>::type type; };

(5)

(since C++11)

提供对元组元素类型的编译时索引访问。

成员类型

Member type

Definition

type

the type of Ith element of the tuple, where I is in [0, sizeof...(Types))

帮助者类型

template <std::size_t I, class T> using tuple_element_t = typename tuple_element<I, T>::type;

(since C++14)

可能的实施

模板<std::size[医]TI,类T>结构元组[医]元素;//递归案例模板<std::size[医]我,班长,班长...。尾>结构元组[医]元素<i,std::tuple<head,tail...>>:std::tuple[医]元素<i-1,std::tuple<tail...>>{};//基案例模板<class Head,class...。尾>结构元组[医]元素<0,std::元组<头,尾…>>{冒枝子型;};

*。

二次

代码语言:javascript
复制
#include <iostream>
#include <tuple>
 
template <class... Args>
struct type_list
{
   template <std::size_t N>
   using type = typename std::tuple_element<N, std::tuple<Args...>>::type;
};
 
int main()
{
   std::cout << std::boolalpha;
   type_list<int, char, bool>::type<2> x = true;
   std::cout << x << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
true

二次

另见

std::tuple_element<std::array>

obtains the type of the elements of array (class template specialization)

std::tuple_element<std::pair> (C++11)

obtains the type of the elements of pair (class template specialization)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券