If you're going to propose something, there should probably be a
reason for it. You haven't explained what problems you're trying to
solve here.
Mostly it is about "more clear" function calls, and a handy shortcut for aggregate local classes.
set_color( [red=200, green=10, blue=100] );
vector<int> x ( [capacity=20, fill=15] );
socket.open ( [port=2000, ip="localhost", timeout=1000] );// <- much better than open( 2000, "localhost", 1000 )
auto calculate(const vector<float>& v ) {
...
return [count, sum, mean=sum/count];
}
auto x = calculate(data);
cout << x.sum; // x has count, sum and mean members without the need to define the class.
It uses square brackets, but the main C++ syntax that represents a sequence of
values is curly braces. Indeed, when it comes to multiple values,
square brackets are used to decompose sequences of values, not to
create them.
Well, [] are used for other things, like indexing and attributes besides binding. I don´t think there is such "concept" of decompose with [] and compose with {}
Using a lambda makes absolutely no sense here. Lambdas are callable
function objects; capturing values is simply a means to the end of
making that function useful.
Kinda does, because this is the way c++ expands a lambda into a local class today, however the members are private, ( I don't think that is even mandated by the standard to be like that ) and making them public will probably be easy...
The biggest difference between this and
designated initializers in function calls, is that you don't need to pre-define the class that you will use as a parameter.
Cleiton