Sounds like a great way to make code disposable, because coming back at a snippet months later it wont be real clear what the hell it does if it isn't commented thoroughly. ...And then you're just changing what you have to type (not eliminating it).-Stoic Joker
If misused, yes - but if used correctly, it's going to make code a lot easier to read, because it reduces irrelevant line noise.
Iterating a collection is one example, already shown - it's pretty atrocious in old-style C++, and franky... You don't need all the information present in such a block, it's noise. What you're interested in 99% of the time is not how you iterate, it's what you're doing in each iteration. Simplifying the 99% is, by itself, a pretty good idea... and it makes the 1% where you have funky iterator needs stand out. That's good as well.
And for declaring variables - you already have the full variable type on the right-hand side of the assignment expression, duplicating it to the right is a waste of time, and nothing but line noise (unless you need to construct some concrete subtype, and assign it to a generic interface type... but that's another case of the
specific and special use case that with C++11 doesn't drown in the 99%).
C++11 is meh. I mean, lambda functions, wtf are they good for? Especially combined with "auto".-Tuxman
It's good for writing expressive, elegant and succinct code... focusing on what's going to happen, instead of the (often irrelevant) minutiae of implementation details. It also lets you rethink API design - turning things inside-out can be quite beneficial.
You might see lambdas as just syntactic sugar for function objects, but they're the glue that makes functional-style programming feasible in C++... The STL algorithms used to be a real pain to use, it's much more interesting now we have lambdas.
And you get all this goodness while
still having a strong statically typed typesystem, compiler-checked, and with pretty much the best damn performance of all of the higher-level languages.
So C++15 or something will maybe allow us to drop the type completely, let's call it "C++ PHP Edition". Oh wait, PHP introduced types...-Tuxman
Please educate yourself
I will use auto like crazy. I will actually use it wherever possible.-phitsc
I think you can go a bit overboard, really. I wouldn't personally use it for primitive types - and I'm wary of using it for variables assigned to the result of a function call. Yes, an IDE will show you the type on mouse-hovering, but you don't always have an IDE... and even when you have, it takes precious milliseconds to deduce the type of a variable that way.
It depends on the code, though. If the variable type seems entirely irrelevant, and all operations are clearly understandable by looking just at the code using the variable, I might still use auto for function-return-assigned variables.
auto does also not replace typedef, as the type of a lambda expression for example is only known to the compiler (if you want to assign the lambda expression to a variable).-phitsc
Variables with "unspeakable (type) names" - I love that expression