I would like to enable support for C++0x in GCC with -std=c++0x. I don’t absolutely necessarily need any of the currently supported C++11 features in GCC 4.5 (and soon 4.6), but I would like to start getting used to them. For example, in a few places where I use iterators, an auto type would be useful.
But again, I don’t need any of the currently supported features. The goal here is to encourage me to incorporate the features of the new standard into my programming “vocabulary”.
From what you know of the C++11 support, is it a good idea to enable it in GCC, and then embrace it by, for example, switching from using boost::shared_ptr to std::shared_ptr exclusively as the two don’t mix?
PS: I’m aware of this good question which compares the different flavors of shared_ptr but I’m asking a higher level advice on which to use before the standard is finalized. Another way of putting that is, when a compiler like GCC says it supports an “experimental feature”, does that mean I am likely to encounter weird errors during compilation that will be major time sinks and a source of cryptic questions on StackOverflow?
Edit: I decided to switch back from std::shared_ptr because I just don’t trust its support in GCC 4.5 as shown by example in this question.
There are a couple of reasons to switch over to
std::shared_ptr:std::shared_ptrand show the pointed to object directly, where it wouldn’t for say, boost’s implementation. At least in Visual Studio,std::shared_ptrlooks like a plain pointer in the debugger, whileboost::shared_ptrexposes a bunch of boost’s innards.You get an implementation which is almost guaranteed to be move-semantics enabled, which might save a few refcount modifications. (Theoretically — I’ve not tested this myself)As of 2014-07-22 at least,boost::shared_ptrunderstands move semantics.(Actually I stand corrected. See this — the specialization for this is forstd::shared_ptrcorrectly usesdelete []on array types, whileboost::shared_ptrcauses undefined behavior in such cases (you must useshared_arrayor a custom deleter)unique_ptronly, notshared_ptr.)And one major glaring reason not to:
Finally, you don’t really have to choose. (And if you’re targeting a specific compiler series (e.g. MSVC and GCC), you could easily extend this to use
std::tr1::shared_ptrwhen available. Unfortunately there doesn’t seem to be a standard way to detect TR1 support)