[Development] RFC: lambda or lambda return from lambda?

Marc Mutz marc.mutz at kdab.com
Mon Feb 1 18:37:32 CET 2016


On Monday 01 February 2016 13:34:05 Sergio Martins wrote:
> I would write:
> 
> removeIfFirstEquals(fields, name): because:
> 
> 1) I could read it in English instead of very verbose C++
> 2) I would not need to read the implementation

I tend to agree, but it only shifts the issue down one level of abstraction. 
And removeIfFirstEquals() isn't exactly clear, either. 
fields.removeIfFirstEquals(name) would be. Maybe when C++ lifts the distinction 
between a.f(b) and f(a, b)...

It also doesn't help when you need to reuse the lambda, e.g. when sorting a 
range by some predicate and then merging the range into an existing one.

> And for the implementation.. it doesn't matter, it's a named function,
> only  does one small thing and does it good.
> 
> About the inlining, which compilers don't and does it make a difference ?

Almost none do, unless they use/you switch on whole-program-optimisation.

> A  function call should negligible compared to erase + remove_if

It's not just a function call, it's a function call though a function pointer. 
Costs like a virtual function call and turns C++ std::sort into C's qsort. 
http://stackoverflow.com/questions/4708105/performance-of-qsort-vs-stdsort

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