Should I switch from using boost::shared_ptr to std::shared_ptr?

后端 未结 8 1766
一生所求
一生所求 2020-12-23 02:06

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 (

相关标签:
8条回答
  • 2020-12-23 02:38

    I suppose it depends how much you use boost. I personally only use it very sparingly (in fact the random number library, in a single project). I've recently started using -std=c++0x for my other projects, and I use the new std:: library features like shared_ptr in them. I like my projects to have the minimum of dependencies, so I'd rather be dependent on the compiler's standard library implementation than on boost.

    But I don't think there is a one-size-fits-all answer to this question.

    0 讨论(0)
  • 2020-12-23 02:38

    It's probably not a bad idea to start getting into the habit of using std::shared_ptr when allowed by the compiler. Since the interface is the same as boost's shared_ptr you can always switch back if you needed to.

    0 讨论(0)
  • 2020-12-23 02:42

    You should always use std::shared_ptr wherever possible, if it's available, instead of boost. This is basically because all new interfaces which use shared_ptr will use the Standard shared ptr.

    0 讨论(0)
  • 2020-12-23 02:43

    I found std::shared_ptr to be faster than boost::shared_ptr. I did a test, you can review the code and see the pie chart results comparing boost, Qt, and std shared pointers.

    https://www.osletek.com...

    0 讨论(0)
  • 2020-12-23 02:48

    Another reason to switch over to std::shared_ptr: it supports std::unique_ptr, i.e. has constructor.

    boost::shared_ptr doesn't.

    0 讨论(0)
  • 2020-12-23 02:49

    If you are just building on the one platform that is fine (make the switch)
    (Note: You do have unit tests to validate backward compatibility don't you?)

    If you compile on multiple platforms is where it becomes a little more awkward as you need to validate that the features on g++ 4.5 are available on all the platforms you use (ie building for MAC/Linux the default Mac g++ compiler is still a couple of version's behind the default compilers on Linux).

    0 讨论(0)
提交回复
热议问题