Date: Thu, 20 Apr 2023 17:54:07 +0300
On Thu, 20 Apr 2023 at 17:35, Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Thu, Apr 20, 2023 at 2:16 PM Ville Voutilainen
> <ville.voutilainen_at_[hidden]> wrote:
> >
> > Lambdas were copyconstructible ever since they were introduced, and we
> > have since allowed
> > them to be defaultconstructible as well when there's nothing
> > preventing that, i.e. no captures,
> > as that has rather reasonable use cases.
>
>
> How about allowing the creation of new lambda object (with captures)
> by using initialiser braces? As follows:
>
> auto Func(int const arg)
> {
> auto mylambda = [arg](void) -> int
> {
> return arg + 3;
> };
>
> return mylambda;
> }
>
> typedef decltype(Func(4)) LambdaType;
>
> int main(int argc, char **argv)
> {
> LambdaType mylambda = { 3 }; // How about allowing this?
> }
Why would we? If you go through all that trouble, just write a
function object class. The syntax you suggest doesn't
work - the lambda in Func is a lambda that captures the argument of
Func, to create this new kind of lambda you
would need something else, and you already have all you need to
express that functionality, you don't
need to shoehorn that functionality into lambdas.
Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Thu, Apr 20, 2023 at 2:16 PM Ville Voutilainen
> <ville.voutilainen_at_[hidden]> wrote:
> >
> > Lambdas were copyconstructible ever since they were introduced, and we
> > have since allowed
> > them to be defaultconstructible as well when there's nothing
> > preventing that, i.e. no captures,
> > as that has rather reasonable use cases.
>
>
> How about allowing the creation of new lambda object (with captures)
> by using initialiser braces? As follows:
>
> auto Func(int const arg)
> {
> auto mylambda = [arg](void) -> int
> {
> return arg + 3;
> };
>
> return mylambda;
> }
>
> typedef decltype(Func(4)) LambdaType;
>
> int main(int argc, char **argv)
> {
> LambdaType mylambda = { 3 }; // How about allowing this?
> }
Why would we? If you go through all that trouble, just write a
function object class. The syntax you suggest doesn't
work - the lambda in Func is a lambda that captures the argument of
Func, to create this new kind of lambda you
would need something else, and you already have all you need to
express that functionality, you don't
need to shoehorn that functionality into lambdas.
Received on 2023-04-20 14:54:20