31

I was wondering if there are any differences between the boost::shared_ptr and the std::shared_ptr found in the standard <memory> file.

8
  • This would depend on your implementation. Commented Feb 4, 2011 at 19:59
  • @robert Can they be used interchangeably? I am trying to implement this stackoverflow.com/questions/3559412/… Commented Feb 4, 2011 at 20:00
  • 1
    @P.R. - std::shared_ptr is the C++0x form of tr1::shared_ptr, and boost's shared_ptr should behave the same: stackoverflow.com/questions/3831572/… Commented Feb 4, 2011 at 20:01
  • Thanks :). I'll go ahead and do some test runs. Commented Feb 4, 2011 at 20:05
  • In light of that question, @Birryree, I guess this question really asks whether C++0x makes any changes to shared_ptr, or whether it's identical to the one from TR1. Commented Feb 4, 2011 at 20:09

1 Answer 1

19

std::shared_ptr is the C++0x form of tr1::shared_ptr, and boost's boost::shared_ptr should behave the same.

However, std::shared_ptr, in an implementation that conforms to C++0x standard, should/might have more convenience behavior on the shared_ptr class, as described in the following links:

The shared_ptr is a reference-counted pointer that acts as much as possible like a regular C++ data pointer. The TR1 implementation lacked certain pointer features such as aliasing and pointer arithmetic, but the C++0x version will add these.

Though from a quick cursory glance, I do not see operator+ and similar arithmetic operations on the shared_ptr type.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I'm a little confused by all these links and additional information. So, in all, what you mean is that std::shared_ptr and boost::shared_ptr behaves the same. Right?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.