function template

std::tie

<tuple>
template<class... Types>
  tuple<Types&...> tie (Types&... args) noexcept;
Tie arguments to tuple elements
Constructs a tuple whose elements are references to the arguments in args, in the same order.

This allows a set of objects to act as a tuple, which is especially useful to unpack tuple objects.

The special constant ignore can be used to specify elements of a tuple to be ignored instead of tied to a specific object.

Parameters

args
List of objects to be tied as elements of a tuple.

Return Value

A tuple with lvalue references to args.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// packing/unpacking tuples
#include <iostream>
#include <tuple>

int main ()
{
  int myint;
  char mychar;

  std::tuple<int,float,char> mytuple;

  mytuple = std::make_tuple (10, 2.6, 'a');          // packing values into tuple

  std::tie (myint, std::ignore, mychar) = mytuple;   // unpacking tuple into variables

  std::cout << "myint contains: " << myint << std::endl;
  std::cout << "mychar contains: " << mychar << std::endl;

  return 0;
}


Output:
myint contains: 10
mychar contains: a

See also