Export (0) Print
Expand All

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);

Idx

The index of the element to get.

TN

The type of the Nth tuple element.

tpl

The tuple to select from.

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&.

 

// 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

Header: <tuple>

Namespace: std

Show:
© 2014 Microsoft