In newer versions of the C++ standard, we are allowed to write functions that have multiple return values such as
std::tuple<int, std::string, float> someFunction0();
This forces us to call the functions as
int a;
std::string last_name;
float f_par;
std::tie(a, last_name, f_par) = someFunction0();
My question is, is there something that prevents the C++ committee from introducing a "simpler" form of multiple return value syntax? Such as
[int, std::string, float] someFunction1();
which would allow you to declare more inline when calling the function
[int a, std::string last_name, float f_par] = someFunction1();
(There are probably better syntactic solutions than the one that I provided.)
Compiler-wise, it shouldn't be an issue, right?
In your example std::tuple<int, std::string, float> someFunction0();
still returns one tuple
object, comprised of multiple sub-objects.
is there something that prevents the C++ committee from introducing a "simpler" form of multiple return value syntax?
You can use C++17 structured binding declaration to unpack/destructure it:
Case 2: binding a tuple-like type
float x{}; char y{}; int z{}; std::tuple<float&,char&&,int> tpl(x,std::move(y),z); const auto& [a,b,c] = tpl; // a names a structured binding that refers to x; decltype(a) is float& // b names a structured binding that refers to y; decltype(b) is char&& // c names a structured binding that refers to the 3rd element of tpl; decltype(c) is co`