-
Book Overview & Buying
-
Table Of Contents
Modern C++ Programming Cookbook - Second Edition
By :
Returning multiple values from a function is very common, yet there is no first-class solution in C++ to make it possible in a straightforward way. Developers have to choose between returning multiple values through reference parameters to a function, defining a structure to contain the multiple values, or returning an std::pair or std::tuple. The first two use named variables, which gives them the advantage that they clearly indicate the meaning of the return value, but have the disadvantage that they have to be explicitly defined. std::pair has its members called first and second, while std::tuple has unnamed members that can only be retrieved with a function call, but can be copied to named variables using std::tie(). None of these solutions are ideal.
C++17 extends the semantic use of std::tie() into a first-class core language feature that enables unpacking the values of a tuple into named variables. This feature is...