3 ms·
New features can reduce the complexity of code, but they cannot reduce the complexity of the language. C++ programmers still need to know what "new" and "delet
by roca 7y ago
New features can reduce the complexity of code, but they cannot reduce the complexity of the language.
C++ programmers still need to know what "new" and "delete" do, so they can work with older code that uses them. They also need to learn what "auto" does, so they can work with newer code that uses it. (The behavior of "auto" isn't trivial; how many C++ programmers understand the difference between "auto v = <expr>;" and "decltype(<expr>) v = <expr>;"?)
- shaklee3 7y agoWhy would you ever use or see the latter? Fabricated examples aren't helpful.
- deleted 7y ago[deleted]
- saagarjha 7y agoNot sure why this was downvoted, decltype was introduced with C++11 alongside of auto for declarations: the example given isn't accurate of reality. A better one might be a function returning auto vs returning decltype(some expression).
- detaro 7y agoWhich specific example is choosen doesn't seem all that relevant for the point of "there's these two similar but not identical things people have to/might not understand the difference of"
- saagarjha 7y agoPicking an example that never occurs is not relevant, because nobody needs to learn the thing that never comes up in practice.
- deleted 7y ago[deleted]
- detaro 7y agoBut as you show with your other example, the difference between auto and decltype does come up in practice, even if the example is not a typical one.
- comex 7y agoYou wouldn't... ...instead you'd use "decltype(auto) v = <expr>", which is equivalent. And people certainly use decltype(auto), or else it wouldn't have been added to the language, 3 years after regular auto.