Curiously, is there any technical restriction if there are multiple return values for methods in languages such as java, c, C ++ or a restriction, only by specification? In assembly language, I understand that a call can set a single value for registration.
struct
, . . ( , ++ tuple ( TR1, ++ 11 boost), )
tuple
, return. . !
struct Person { std::string Name; int Age; std::string Qualification; //... }; Person GetInfo() { Person person; //fill person members ... return person; }
std::pair, std::vector, std::map, std::list . ++ 0x std::tuple.
std::pair
std::vector
std::map
std::list
std::tuple
Genie , . , . , , , ()... , .: -)
: -)
, . , , :
(int, int, int) call(int x, int y, int z);
:
(a, b, c) = call(1, 2, 3);
. , . , , .
, return:
(int, int, int) call(int x, int y, int z); { return x+1, y+1, z+1 }
, :
(err, filehandle) = OpenFileDialog(...)
, . . : , .
. , , , , , .
2 .
, . , C . , , ML Haskell, , .
, , , , ML Haskell - "" . , , , , .
, , , "" , . - , (c.f call-with-values), - MATLAB:
call-with-values
function [x,y] = myFunc(a, b) ... end [p, q] = myFunc(3,4)
, (cons cell, array, ) .
, / ABI. , . - , .
, ++, :
std::tuple<int,float> func() { return std::make_tuple(1, 2.f); } int i; float f; std::tie(i, f) = func();
.
, .
second - ( const) .
, , , , C Java .
++ , , , Ruby python - , , return, , , -.
return
, ++ 17 (. ) ...
auto [x,y,z] = expression;
... return - , - , a tuple struct public. const, const.
public
const
This function also documents this ...
for (const auto& [key,value] : mymap) ...
... that avoids the reuse of less expressive ->firstand ->second.
->first
->second
When moving C ++ in this direction, it is likely that C and other C-language languages will look closely to do the same.