共用方式為


tuple_element Class <tuple>

Wraps the type of a tuple element.

template<int Idx, class Tuple>
class tuple_element {
    typedef Ti type;
    };

Parameters

  • Idx
    The index of the designated element.

  • Tuple
    The type of the tuple.

Remarks

The template class has a nested typedef type that is a synonym for the type at index Idx of the tuple type Tuple.

Example

 

// std_tr1__tuple__tuple_element.cpp 
// compile with: /EHsc 
#include <tuple> 
#include <iostream> 
#include <utility> 
 
typedef std::tuple<int, double, int, double> Mytuple; 
int main() 
    { 
    Mytuple c0(0, 1, 2, 3); 
 
// display contents " 0 1 2 3" 
    std::cout << " " << std::get<0>(c0); 
    std::cout << " " << std::get<1>(c0); 
    std::cout << " " << std::get<2>(c0); 
    std::cout << " " << std::get<3>(c0); 
    std::cout << std::endl; 
 
// display first element " 0" 
    std::tuple_element<0, Mytuple>::type val = std::get<0>(c0); 
    std::cout << " " << val; 
    std::cout << std::endl; 
 
    return (0); 
    } 
 
 0 1 2 3
 0

Requirements

Header: <tuple>

Namespace: std

See Also

Reference

<tuple>

tuple Class

tuple_size Class <tuple>