5 ms·
2. I'm sure IDEs/editors will start to implement features to grok object output and/or do static analysis to show you what type auto implies. It isn't necessari
by apaprocki 15y ago
2. I'm sure IDEs/editors will start to implement features to grok object output and/or do static analysis to show you what type auto implies. It isn't necessarily easy but it seems like the feature everyone would want. You could even produce a "de-auto" button that would toggle between auto and the substituted real type for readability.
3. Move operations are completely welcome as far as I'm concerned. I recently hit some performance problems which beg for move or emplace semantics. Most people don't realize the amount of copies they are making when using STL containers. These semantics will allow code to ensure only one instance of a value type is ever created when, say, inserting into a map. I feel like some people resort to going back to hand-rolled data structures or raw pointers when performance is critical because the current containers are missing this.
- CJefferson 15y agoIn templates, it is almost impossible to remove the 'auto'. Even something simple like: template<typename T> void f(T t1, T t2) { auto sum = t1 + t2; } There is nothing to replace auto with. Similar things apply to most templated functions. Of course outside of templates things get much easier, but I wouldn't expect to see quite so many autos.
- dilap 15y agoTrue, but at least screw-ups will be noticed at compile time. And how would you even write this snippet, pre auto?! (I think you'd either just assume t1 + t2 was T, or you'd have to go thru less-general, even-less-clear, gymnastics (like having some structure defined like get_sum_type<T,T>::thetype sum = t1 + t2).)
- koenigdavidmj 15y ago>And how would you even write this snippet, pre auto?! typeof(t1 + t2) sum = t1 + t2;
- koenigdavidmj 15y agoThat should be decltype, not typeof, btw
- dilap 15y agoThat's cheating! I meant how would you write it pre-C++11 extensions (and also not using the earlier GCC typeof extension). decltype is just a slightly different form of auto. :)
- CJefferson 15y agoExactly right, in C++03 this kind of stuff was really horrible. In general people (the STL, and all Maths code I've ever read), will just assume that the type is T. For things like iterators, you have to do things like: typename std::vector<T>::const_iterator it = v.begin(); (That typename has to be there, for stupid C++ reasons). Being able to reduce that to: auto it = v.begin(); Is probably the most visible advantages to C++11 is one of the most obvious improvements for many programers.