ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Herb Sutter's brief look at C++11

<< < (2/5) > >>

mouser:
Yeah i had the same gut reaction that gothic had.. that i like to be able to see what the type the variable is.. but i suppose we always still have that option.

I can see how the auto could come in very handy for those very short sections of code where you are using convoluted type iterators, which are a pain to type out for no good reason.  I would just be wary of overusing it.

Eóin:
With the likes of iterators I think it's a great thing, after all you don't want to care what the actual type of an iterator is, just that it behaves like you expect it to. It's duck typing but with the compiler verifying everything at compile time rather than forcing you to deal with runtime errors.

For the example you give, well I agree with you. But then foo is a local variable, likely it's lifetime is pretty short and it's type isn't as important as that it behaves as a vector-ish of strings. If your code specifically requires it to be a std::vector you can be more specific.

auto isn't necessarily meant to be used everywhere.

[edit] mouser beat me to saying much the same thing :)

Stoic Joker:
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).

Jibz:
Well, I guess time will tell 8)

Eóin:
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.
-Stoic Joker (November 01, 2011, 11:22 AM)
--- End quote ---

If misused sure, but I don't believe features should be left out because they could be misused. Also when you consider polymorphism and generic coding, both present in C++ for years now, this auto isn't exactly a whole new paradigm anyway.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version