So, before quite some presentation, here is my question:
Why is there no support for multiple returned variables / values in C ++ (yet)?
To give you some more notes:
- What (if any) is a conceptually problem with multiple return values and C ++?
- Is there something in the way the compiler implements saving values from a function that makes multiple return values impossible / ineffective?
Recently, working a lot with lua, I came to ask myself why C ++ does not allow returning several values / variables from a function. To illustrate this, let me give an example of lua:
-- get the first four values of the fibonacci sequence
local function fib4()
return 1, 1, 2, 3
local fib0, fib1, fib2, fib3 = fib4()
/ - , ++, ( ), . , soure , ; ( ). , - [ lambdas]:
pro :
struct point_three_dim_t {
double x;
double y;
double z;
};
point_three_dim_t point = getCollisionPoint();
, , , , , x, y z first, second third. , , point_three_dim_t. ,
double x, y, z = getCollisionPoint();
- .
++ 11, , std::tuple, std::tie
std::tuple<double,double,double> getCollisionPoint();
double x, y, z;
std::tie( x, y, z ) = getCollisionPoint();
std::tuple<double,double,double> point = getCollisionPoint();
, , , , , lua.