I've been using the new auto
keyword available in the C++11 standard for complicated templated types which is what I believe it was designed for. But I'm also using it for things like:
auto foo = std::make_shared<Foo>();
And more skeptically for:
auto foo = bla(); // where bla() return a shared_ptr<Foo>
I haven't seen much discussion on this topic. It seems that auto
could be overused since a type is often a form of documentation and sanity checks. Where do you draw the line in using auto
and what are the recommended use cases for this new feature?
To clarify: I'm not asking for a philosophical opinion; I'm asking for the intended use of this keyword by the standard committee, possibly with comments on how that intended use is realized in practice.
auto
keyword, then you know how it's supposed to be used. That's what I'm asking, as someone who is new to this feature, is how am I supposed to use it?var
(that is, once people got over the idea that it wasn't dynamic typing after all). If you want you can start with this question and go through the related questions.auto
. Not all questions ask what is 2+2. For example, asking HOW I calculate 2+2 is still a good question, but you could easily call it "subjective". Perhaps I'm naive, but to me, if a question leads to a useful clarifying answer, then both the question and answer deserve to be on the site.auto foo = bla();
"bad" is clearly an opinion, not a fact, which makes this question and answer a discussion, which makes it relevant to Programmers SE, which is exactly what the close votes indicate. /shrug