Namespaces
Variants
Views
Actions

std::get(std::tuple)

From cppreference.com
< cpp‎ | utility‎ | tuple
Revision as of 12:10, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dcl ">

<td >
template< std::size_t I, class... Types >

typename std::tuple_element<I, tuple<Types...> >::type&

    get( tuple<Types...>& t );
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< std::size_t I, class... Types >

typename std::tuple_element<I, tuple<Types...> >::type&&

    get( tuple<Types...>&& t );
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< std::size_t I, class... Types >

typename std::tuple_element<I, tuple<Types...> >::type const&

    get( const tuple<Types...>& t );
</td>

<td > (3) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

Extracts the Ith element element from the tuple. I is an integer value in [0, sizeof...(Types)).

Contents

Parameters

t - tuple whose contents to extract

Return value

1) Reference to the Ith element of t.

2) Rvalue reference to the Ith element of t, unless the element is of lvalue reference type, in which case lvalue reference is returned.

3) Const reference to the Ith element of t.

Exceptions

noexcept specification:  
noexcept
  

Example

#include <iostream>
#include <string>
#include <tuple>
 
int main()
{
    auto t = std::make_tuple(1, "Foo", 3.14);
    std::cout << "(" << std::get<0>(t) << ", " << std::get<1>(t)
              << ", " << std::get<2>(t) << ")\n";
}

Output:

(1, Foo, 3.14)

See also

Template:cpp/container/array/dcl list get
accesses an element of a pair
(function template) [edit]