Closed filipsajdak closed 8 months ago
See commit b9e73e06f93c9238b3d67a539d8276aa8b9db814.
Your function expression needs to be changed from
:() i$
to
:() -> _ == i$
.
Thanks! I think this has been answered so I'll close it, but if I missed something please reopen.
I ran into this yesterday. Took me quite a while to figure out what was wrong.
Intuitively I would say that using the constexpr marker ==
affects only the result and not the declaration of the lambda. But I do not have a better idea how to handle this. What was the original problem that required mutable
for the lambdas?
It's a fix or change in the conceptual model of what captures are. See the thread starting at https://github.com/hsutter/cppfront/commit/4bd0c0438f2d3fa65d3e65a55b17c3a296bd8bc3#commitcomment-134056070:
my conceptual model of captures is actually closer to them being additional local variables that are "static" (persistent across calls), and local variables are non-const by default.
that
==
also gives the "notmutable
" syntax
Thank you for the reference. Having muteable
as the default for lambdas needs to be getting used to when coming from cpp where it is the other way round.
In the current code (faacec05d8a752f68abf7354e64dbc72cbf11989), all anonymous functions are mutable.
Unfortunately, it broke passing anonymous functions with capture as in arguments. That means that the following code will not work:
Which generates (skipping boilerplate):
and fail during compilation with the following errors:
Also, I now have an issue using the boost::ut library, as it stores lambdas (that often have capture lists) as const references.
Maybe we can prefix mutable lambda with the
inout
keyword and make the unnamed functionin
by default?