Christopher Smith wrote: > auto foo = new LongArduousType(...) > Just to clarify here, the real value of C++ 0x's new use of the "auto' keyword isn't for this scenario at all. It is for a related but distinct scenario:
for (Foo::bars_collection::const_iterator i = foo.getBars().begin(); i != foo.getBars().end(); ++i) So, the problem here is that odds are the code inside the for loop doesn't actually care about the type of the iterator. It just wants to have "i" be whatever type foo.getBars().begin() returns. When you read code like the above, you actually need to *check* what that function returns, in case there is some kind of evil cast happening (all too common if your iterator types are actually pointers) in that for loop (and then you have to figure out if a cast was intended or not). By instead changing it to: for (auto i = foo.getBars().begin(); i != foo.getBars().end(); ++i) You make it clear that no cast is intended, nor is one happening. Of course, many would correctly argue that the best way to clarify that would be to do: for_each(foo.getBars().begin(), foo.getBars().end(), ....) But a lot of C++ developers strongly resist that idiom, and sometimes the for loop is the cleanest way to represent the work being done. --Chris -- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg
