Share via


get Function <tuple>

Gets an element from a tuple object.

template<int Idx, class T1, class T2, ..., class TN>
    RI get(tuple<T1, T2, ..., TN>& tpl);
template<int Idx, class T1, class T2, ..., class TN>
    RI get(const tuple<T1, T2, ..., TN>& tpl);

Parameters

  • Idx
    The index of the element to get.

  • TN
    The type of the Nth tuple element.

  • tpl
    The tuple to select from.

Remarks

The template functions return a reference to the value at index Idx in the tuple object tpl. If the corresponding type Ui is a reference type both functions return Ui; otherwise the first function returns Ui& and the second function returns const Ui&.

Example

 

// std_tr1__tuple__get.cpp 
// compile with: /EHsc 
#include <tuple> 
#include <iostream> 
 
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; 
 
    return (0); 
    } 
 
 0 1 2 3

Requirements

Header: <tuple>

Namespace: std

See Also

Reference

<tuple>

tuple_element Class <tuple>