Hacker News new | comments | show | ask | jobs | submit login

This is ridiculous. C++ lambdas (and std::function) don't replace iterators except for the most fervent disciples of the Church of Haskell. They replace single-function interfaces in cases where you would have had to put together a custom struct that did exactly the same thing as a lambda with capture but in about 15 more lines.

To be fair, the most fervent disciples of the Church of Haskell would use Haskell I'd think :)

I only scanned the paper, but I get the impression the title was chosen specifically to grab attention. "An empirical study comparing the use of C++ lambdas versus C++ STL iterators and programmer experience" wouldn't get eyes on their presentation, and eventually, being posted to HN...well, it would, but they'll surely get more reads/downloads this way.

Clickbaiting for conference proceedings, who would have known.

Such a title wouldn't be right, either. Their poor iterators don't seem to act like real iterators.

Don't you mean the church of A. Church? ;)

Yes, especially irritating in C++2003 here at work! you realise how useful the capture list is with lambdas when you have an in-function struct that can't see outside its own scope so you need to pass everything in (and won't have access to private portions of the outer class).

Lambdas really are great.

> and won't have access to private portions of the outer class

Nested and member function local classes are actually implicitly friends of the containing class. Not all compilers were conforming in this area though.

I'm not so sure. Generally implementing an iterator when the iteration doesn't represent a straightforward walk over the elements of a collection is much more error-prone. The implementation of the lambda version looks exactly the same as if you were just performing the iteration locally, while the iterator version requires saving and restoring a bunch of state and handling more edge cases. At call sites, the iterator version looks a little better, but not so much so that I'd consider the additional implementation complexity (and hence potential for bugs) worth it. That said, this is definitely a controversial opinion and there are arguments in the other direction as well.

Writing iterators is non trivial, but, lacking first class continuations, external iterators (a-la begin, end) are more powerful than internal iterators (a-la for_each), as they allow iterating multiple ranges at the same time and easily defining subranges.

For a long time I could not understand why anonymous closures were not implemented in c/c++, and even had arguments on forums, but then realized that people just do not think in that terms. You can provide lambdas, but they will use these for iterators or similar bs. And there is no better technique or framework for the case you described, they just don't do that at all.

Applications are open for YC Summer 2018

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact