4 ms·
"[=]" Capture all variables by value, fair enough. "mutable" Don't capture them const, this is very rare. "throw()" Promise not to throw an exception, this is
by detrino 13y ago
"[=]" Capture all variables by value, fair enough.
"mutable" Don't capture them const, this is very rare.
"throw()" Promise not to throw an exception, this is very rare for a lambda, and also deprecated in favor of noexcept.
"-> int" Explicit return type, usually not needed, and nearly never needed in C++14.
I was objecting to a contrived example used out of context to make C++'s syntax look worse than it is.
- rayiner 13y agoI'm not trying to make C++'s syntax "look bad." The standard itself makes C++'s syntax look bad. All those features, except maybe the empty throw clause, are basic things someone needs to know to use lambdas properly and to read code that uses lambdas. We're not talking about deprecated, never-used, features like "export" here. I don't understand your line of reasoning here. Is syntax not ugly if you usually don't use the ugly parts? I think everyone would agree that the parser ambiguity that used to exist between "vector<vector<int>>" and the right-shift operator ">>" was ugliness in the syntax. Is it a defense that you don't usually instantiate a template with an instantiation of another template?
- deleted 13y ago[deleted]
- deleted 13y ago[deleted]
- greyfade 13y agoNone of these features, except the capture clause, are things that anyone has to learn to use C++ lambdas; they should know these other features anyway, from other parts of the language. The late return type syntax (`-> type`) works with nearly all functions (`auto fn(foo) -> bar { ... }`), the `throw()` (now `noexcept`) specification has been used for long time, and `mutable` is a well-known syntax for potentially const objects; so the lambda syntax is, or at least should be, unsurprising. To say it's ugly is not saying much. We all know C++ is ugly. This is a given. But singling out lambda syntax, which is comparatively easy to grasp and largely consistent with the language, doesn't really make a case.