You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know that class are still not supported on cppfront; but this makes the discussion even more relevant.
One of the things that lambda functions (arguably) get right is making their operator()const by default and requiring mutable if you want to change data from the lambda.
This should be done also for cpp2 classes. This has the advantages of (1) making lambdas less of a special case, and (2) making const-correct code the default.
That's the intent, and it just falls out of making in parameters the default. Classes will use explicit this which, like all parameters, defaults to in and therefore const.
This example now works:
main: () = {
v: std::vector = ( 1, 2, 3, 4, 5 );
// Definite last use of v => move-capture v into f's closure
f := :() -> forward _ = v$;
// Now we can access the vector captured inside f()...
f().push_back(6);
for f() do(e) std::cout << e; // prints 123456
}
I know that class are still not supported on cppfront; but this makes the discussion even more relevant.
One of the things that lambda functions (arguably) get right is making their
operator()
const
by default and requiringmutable
if you want to change data from the lambda.This should be done also for cpp2 classes. This has the advantages of (1) making lambdas less of a special case, and (2) making const-correct code the default.
This is kind of related to issue #25 .
The text was updated successfully, but these errors were encountered: