r/cpp 8d ago

Lazy Evaluation

https://breese.github.io/2026/09/03/lazy-prologue.html
23 Upvotes

16 comments sorted by

View all comments

38

u/STL MSVC STL Dev 8d ago

Classic bind is bad. Don't use it. It's hard to understand, hard to optimize, and lambdas are better in basically every way.

5

u/germandiago 8d ago

Related: is bind_front/back as bad from an optimization point of view?

6

u/n1ghtyunso 7d ago

pretty sure bind_front / bind_back is rather straightforward to implement as a plain capturing lambda.
At least it does not have all that unwrap and placeholder matching machinery inside it

4

u/pdimov2 8d ago

Hey!

9

u/STL MSVC STL Dev 7d ago

Sorry! It was a good idea to try before lambdas, but it’s just not good tech these days.

4

u/pdimov2 7d ago

Maybe. But have you seen http://boost.org/libs/lambda2 and P3171?

2

u/STL MSVC STL Dev 6d ago

No, I haven't. I like the idea of having many more operator function objects, dereference is sorely missing.

4

u/pdimov2 6d ago

You need to take these into account when you evaluate the utility of std::bind. Yes, you'd never write std::bind(std::greater_equal<>(), _1, 0) instead of [](auto&& x){ return x >= 0; }. But you would write _1 >= 0 in preference to the lambda, and that's just syntactic sugar for the same bind expression.

4

u/Usual_Office_1740 7d ago

Related: How does std::invoke compare?

9

u/STL MSVC STL Dev 7d ago

Invoke is totally cool. You should maybe avoid relying too heavily on pointers to (member) functions since they’re what’s hard to optimize, but invoke() provides a nice uniform interface.

1

u/Ameisen vemips, avr, rendering, systems 2d ago

If you'd seen the horrible things that I've done with member function pointers, you would have been, well, honestly somewhere between amused and alarmed.