A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/tuple/get/ below:

function template

<tuple>

std::get (1)
template <size_t I, class... Types>typename tuple_element< I, tuple<Types...> >::type& get(tuple<Types...>& tpl) noexcept;
(2)
template <size_t I, class... Types>typename tuple_element< I, tuple<Types...> >::type&& get(tuple<Types...>&& tpl) noexcept;
(3)
template <size_t I, class... Types>typename tuple_element< I, tuple<Types...> >::type const& get(const tuple<Types...>& tpl) noexcept;

Get element

Returns a reference to the Ith element of tuple tpl.

Version (2), which takes an rvalue reference of a tuple as argument, applies forward to the returned element.

Version (3), which takes a const tuple as argument, returns a const reference to the element.

get can also be used on tuple-like objects like pair and array (see pair's and array's specializations).

Notice that get uses a template parameter, I, to determine which element to be gotten. Template parameters must be constexpr (compile-time const values).



Template parameters
I
Position of an element in the tuple, with 0 as the position of the first element.
size_t is an unsigned integral type.
Types
Types of the elements in the tuple (generally obtained implicitly from tpl).

Function parameters
tpl
A tuple object with more than I elements.

Return value A reference to the element at the specified position in the tuple.
tuple_element< I, tuple<Types...> >::type is the type of the Ith element in the tuple.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// tuple's get
#include <iostream>
#include <tuple>

int main ()
{
  std::tuple<int,char> mytuple (10,'a');

  std::get<0>(mytuple) = 20;

  std::cout << "mytuple contains: ";
  std::cout << std::get<0>(mytuple) << " and " << std::get<1>(mytuple);
  std::cout << std::endl;

  return 0;
}

Output:
mytuple contains: 20 and a


See also
tie
Tie arguments to tuple elements (function template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4