Date: Fri, 16 May 2025 14:04:05 +0300
What you are asking for is the Y combinator. Apparently there was a
proposal to add it to the standard library (
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html) but
I don't know what happened to it.
On Fri, May 16, 2025 at 1:59 AM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
> On Thu, May 15, 2025 at 2:16 PM Pavel Vazharov wrote:
> >
> > C++23 is enough to cover you here:
> >
> > #include <print>
> >
> > int main(int const argc, char **const argv)
> > {
> > auto func = [argv](this auto&& self, int count)
> > {
> > if ( 0 == count ) return;
> > std::println("{}", argv[count - 1]);
> > self(count - 1);
> > };
> > func(argc);
> > }
>
>
> int main(int const argc, char **const argv)
> {
> auto func1 = +[](int count, char **argv)
> {
> // This one cannot recurse
> };
>
> auto func2 = +[](this auto &&self, int count, char **argv)
> {
> // This one won't compile
> };
> }
>
> Normally if a lambda doesn't have any captures, you can turn it into a
> normal function pointer by using the unary '+' operator. However in
> your code example, the lambda cannot be turned into a normal function
> pointer -- because it needs to be invoked on an object (i.e. it needs
> the 'this' pointer).
>
> So we still don't have a 'perfect' solution here yet, not even with
> C++23. I think for perfection we'd need std::recurse.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
proposal to add it to the standard library (
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html) but
I don't know what happened to it.
On Fri, May 16, 2025 at 1:59 AM Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]> wrote:
> On Thu, May 15, 2025 at 2:16 PM Pavel Vazharov wrote:
> >
> > C++23 is enough to cover you here:
> >
> > #include <print>
> >
> > int main(int const argc, char **const argv)
> > {
> > auto func = [argv](this auto&& self, int count)
> > {
> > if ( 0 == count ) return;
> > std::println("{}", argv[count - 1]);
> > self(count - 1);
> > };
> > func(argc);
> > }
>
>
> int main(int const argc, char **const argv)
> {
> auto func1 = +[](int count, char **argv)
> {
> // This one cannot recurse
> };
>
> auto func2 = +[](this auto &&self, int count, char **argv)
> {
> // This one won't compile
> };
> }
>
> Normally if a lambda doesn't have any captures, you can turn it into a
> normal function pointer by using the unary '+' operator. However in
> your code example, the lambda cannot be turned into a normal function
> pointer -- because it needs to be invoked on an object (i.e. it needs
> the 'this' pointer).
>
> So we still don't have a 'perfect' solution here yet, not even with
> C++23. I think for perfection we'd need std::recurse.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
-- This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.
Received on 2025-05-16 11:03:52