function template
<tuple>

std::tie

template<class... Types>
  tuple<Types&...> tie (Types&... args) noexcept;
Tie arguments to tuple elements
Constructs a tuple object 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 (lvalues) 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>     // std::cout
#include <tuple>        // std::tuple, std::make_tuple, std::tie

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 << '\n';
  std::cout << "mychar contains: " << mychar << '\n';

  return 0;
}


Output:
myint contains: 10
mychar contains: a

Data races

None introduced by this call.
Notice though that the arguments may be modified by any use of the returned object.

Exception safety

No-throw guarantee: this function never throws exceptions.

See also