C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Terse lambda

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Mon, 3 Feb 2025 20:10:04 +0100
pon., 3 lut 2025 o 19:11 Filip via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
> Hi, I think I don’t fully understand,
> You want to assign a name to a lambda when passing it as an argument to a function with => operator?
>

What "name"? What part of my email are you referring to exactly?
I never assign any name to any lambda. And `=>` is not an operator but
a token that will be part
of lambda syntax that replaces `{ return` part.

> Cheers, Filip
>
> Wiadomość napisana przez Marcin Jaczewski via Std-Proposals <std-proposals_at_[hidden]> w dniu 1 lut 2025, o godz. 16:35:
>
> One problem with the previous proposal was what value category
> should return type be, some prefer it as value other prefer reference.
> Question why not allow both? We could have 3 types of arrows:
>
> ```
> => //return value (if not specified explicitly)
> &=> //return reference
> &&=> //return forward reference
> ```
>
> only `decltype(auto)` is not easily available but this
> probably is only for very special cases.
>
> Most safe version need least typing and is simplest.
> Another thing syntax is intuitive, when someone sees `&`
> one of their first thoughts should be "reference?".
>
> This syntax could be consider of contraction of full syntax:
>
> ```
> [x]() -> auto& => x;
> [x]() -> auto &=> x;
> [x]() &=> x;
> ```
>
> Only drawback of syntax like this could break some current code like:
>
> ```
> foo<&T::operator=>() // could see `=>` instead of current `=` and `>`
> foo<&T::operator&=>() //similar `&=>` as one token.
> ```
>
> But we could simply handle this similar to `>>` in template context
> and require brackets:
>
> ```
> foo<&T::operator=> //split `=` and `>`
> foo<([] => 42)>
> ```
>
>
>
> If someone specify `->` and `=>` like:
>
> ```
> template<typename T>
> void foo(T&& t)
> {
> bar([&] -> T& &&=> t);
> bar([&] -> T&& &=> t);
> bar([&] &=> t);
> }
> ```
>
> Then similarly like forward reference parameters, all return types
> will have the same value category of `&`.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-02-03 19:10:16