C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Lambda type not isolated within function

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 20 Apr 2023 15:35:27 +0100
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?
}

Received on 2023-04-20 14:35:40