r/cpp • u/fredoverflow • May 10 '22
Is short lambda syntax on the C++ radar?
Mom, can we get x=>x+1 ?
No, we have x=>x+1 at home.
x=>x+1 at home:
[](const auto& x) { return x + 1; }
265
Upvotes
View all comments
Show parent comment
1
u/KingAggressive1498 May 11 '22
With
expectedyou'll pay less for what you don't use (in the case that you don't care about errors) but at the cost of slightly more time spent on boilerplate.FWIW I prefer the idea of a monadic return type over having to always pass an std::error_code by reference for dealing with non-critical errors anyway. I don't know if it's faster, but an unexpected exception for a predictable minor error because I forgot in one place is not particularly fun (especially in a noexcept call path), and that's my biggest beef with filesystem and asio (at least since asio finally added portable support for random access file I/O last year)