...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Tiers are sequences, where all elements are non-const reference types. They are constructed with a call to a couple of tie function templates. The succeeding sections document the various tier flavors.
Example:
int i; char c; double d;
...
vector_tie
(i, c, d);
The vector_tie
function creates
a vector
of type
. The same result could be achieved
with the call vector
<int&, char&, double&>make_vector
(ref
(i), ref
(c), ref
(d)) [11].
A tie can be used to 'unpack' another tuple into variables. E.g.:
int i; char c; double d;vector_tie
(i, c, d) =make_vector
(1,'a', 5.5); std::cout << i << " " << c << " " << d;
This code prints 1 a 5.5 to the standard output stream. A sequence unpacking operation like this is found for example in ML and Python. It is convenient when calling functions which return sequences.
There is also an object called ignore which allows you to ignore an element assigned by a sequence. The idea is that a function may return a sequence, only part of which you are interested in. For example:
char c;vector_tie
(ignore, c) =make_vector
(1, 'a');