std::tie
From Cppreference
| C++ Standard Library | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Utilities library | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::tuple | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Defined in header <tuple>
  | ||
| template< class... Types > tuple<Types&...> tie( Types&... args ); | (since C++11) | |
Creates a tuple of lvalue references to its arguments or instances of std::ignore.
| Contents | 
[edit] Parameters
| args | - | zero or more lvalue arguments to construct the tuple from | 
[edit] Return value
A std::tuple object containing lvalue referenes.
[edit] Exceptions
[edit] Example
tie can be used to introduce lexicographical comparison to a struct, or to unpack a tuple
#include <iostream> #include <string> #include <set> #include <tuple> struct S { int n; std::string s; float d; bool operator<(const S& rhs) const { return std::tie(n, s, d) < std::tie(rhs.n, rhs.s, rhs.d); } }; int main() { std::set<S> set_of_s; // S is LessThanComparable S value{42, "Test", 3.14}; std::set<S>::iterator iter; bool inserted; std::tie(iter, inserted) = set_of_s.insert(value); if(inserted) std::cout << "Value was inserted sucessfully\n"; }
Output:
Value was inserted sucessfully
| creates a tuple object of the type defined by the argument types (function template) | |
| creates a tuple of rvalue references (function template) | |
| creates a tuple by concatenating any number of tuples (function template) | |
| placeholder to skip an element when unpacking a tuple using tie (constant) | |