Sacrificing precision for ease of use?

I’m probably jumping the gun a little here as I can’t find Herb Sutter’s slides that Matt Pietrek is referring to, but… Once again I find myself asking why is it actually useful to repurpose the auto keyword in C++…

The idea seems to be that rather than this:

foo::iterator<int> i = myList.begin();</int>

You can do this:

// Type of 'i is inferred from the assignment
auto i = myList.begin();

I really don’t get what’s with these “productivity” enhancements that allow people to think less whilst coding. Let’s assume that I gain something whilst writing the code by using this new feature; and I’m not convinced that I would. Does someone whose job it is to maintain that code going to have the same gain? Let’s consider the situation, you’re looking at unfamiliar code and you come across this line:

auto i = myList.begin();

There’s no indication of what myList is. There’s no indication of what begin() returns. There’s no indication of which version of begin() we’re calling; is there a const version that returns something different to the non-const version? This code communicates less than the code that it replaces…

And, of course, this is actually quite a simplistic example. Let’s say we have this function on a collection class:

const CMyObject *CMyCollection::GetObject(i) const;

So we might have a call site like this:

const CMyObject *pObj = myCollection.GetObject(i);

Which could, perhaps, become:

auto pObj = myCollection.GetObject(i);

But what we’d rather do is restrict what we use pObj for, so we decide to manipulate it via one of the interfaces that it implements instead…

const IObjBase *pObj = myCollection.GetObject(i);

How do we do that with this new fangled auto? I assume we don’t?

C++ is a very expressive language; it allows you to be precise about what you want to do. What I’d like to know is what value this change has that makes up for the fact that the code is now potentially less precise and communicates considerably less? Perhaps the slides from talk will explain more… To me it just looks like the kind of thing that a lazy programmer writing a code generator would ask for…