[Development] RFC: lambda or lambda return from lambda?
Marc Mutz
marc.mutz at kdab.com
Mon Feb 1 15:16:33 CET 2016
On Monday 01 February 2016 10:18:25 Jędrzej Nowacki wrote:
> So it would look like that:
>
> fields.erase(std::remove_if(fields.begin(),
> fields.end(),
> [&name](const QPair<QByteArray, QByteArray>
> &header)
> {
> return qstricmp(name.constData(),
> header.first) == 0;
> }),
> fields.end());
>
> // I hope that formating is still ok, and the code is not wrapped.
>
I am a great fanboy of algorithms and the STL, as should be clear by now :)
But I find the inlined lambda worse than an explicit loop. This is write-only
code, imo. Esp. since we can't (yet) use auto in the parameter list, but even
then, I'd always give a lambda a name (cf. my mail in response to Christian).
> For a bigger code we would actually require named functions. What do you
> think?
Named functions have two problems: a) that many compilers don't inline the
code. So at a minimum, you'd write a forwarding lambda, or the function would
be an auto variable holding a stateless lambda (the difference between the two
is almost non-existent, anyway). And b) that they cannot carry state. Lambdas
can.
Thanks,
Marc
--
Marc Mutz <marc.mutz at kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - The Qt Experts
More information about the Development
mailing list