Comment by ajuc
5 years ago
> local blocks that define which variables they read, mutate and export would IMO be a very good solution to this problem:
this is basically a lambda you call instantly.
[&x, y, z] () {
x = y + z;
}();
5 years ago
> local blocks that define which variables they read, mutate and export would IMO be a very good solution to this problem:
this is basically a lambda you call instantly.
[&x, y, z] () {
x = y + z;
}();
It's similar, but lambdas don't specify the behaviour as precisely, and they're not as readable since the use of a lambda implies a different intention, and the syntax that transforms them into a scope block is very subtle. They may also have performance overhead depending on the environment, which is (arguably) additional information the programmer has to consider on usage.