std::tuple_element<std::tuple>
STD::元组[医]元素<std::tuple>
Defined in header | | |
---|---|---|
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 | | (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::元组<头,尾…>>{冒枝子型;};
*。
例
二次
#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';
}
二次
产出:
二次
true
二次
另见
std::tuple_element | 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) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。