3 ms·
You are being intentionally dishonest by using the most verbose lambda expression you can think of. It would be very unusual to write something like that. You e
by detrino 13y ago
You are being intentionally dishonest by using the most verbose lambda expression you can think of. It would be very unusual to write something like that. You even managed to include one of the rare deprecated language features.
- rayiner 13y agoThe example is from the first hit for a Google search for "C++ lambda syntax" (an MSDN article). In any case, unusual language features still are part of the syntax. They must be parsed and they must be understood by programmers in case they come across them. The ugly parts of a language don't go away just because you don't use them that often. Also, I'm not sure what you're objecting to. The throw clause? The ugly part here is the overloading of the brackets and equal sign to specify the capture list.
- 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.