I was wondering if there are any differences between the boost::shared_ptr
and the std::shared_ptr
found in the standard <memory>
file.
Asked
Active
Viewed 1.4k times
30

Nicol Bolas
- 449,505
- 63
- 781
- 982

Pepe
- 6,360
- 5
- 27
- 29
-
This would depend on your implementation. – robert Feb 04 '11 at 19:59
-
@robert Can they be used interchangeably? I am trying to implement this http://stackoverflow.com/questions/3559412/how-to-store-different-data-types-in-one-list-c/3560884#3560884 – Pepe Feb 04 '11 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: http://stackoverflow.com/questions/3831572/differences-between-tr1shared-ptr-and-boostshared-ptr – wkl Feb 04 '11 at 20:01
-
Thanks :). I'll go ahead and do some test runs. – Pepe Feb 04 '11 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. – Rob Kennedy Feb 04 '11 at 20:09
-
@Rob Kennedy - Guess I'll have to do an answer. :p – wkl Feb 04 '11 at 20:10
-
possible duplicate of [Differences between different flavours of shared_ptr](http://stackoverflow.com/questions/1086798/differences-between-different-flavours-of-shared-ptr) – JJJ Jul 07 '12 at 06:46
-
Possible duplicate of [Differences between different flavours of shared\_ptr](https://stackoverflow.com/questions/1086798/differences-between-different-flavours-of-shared-ptr) – Trevor Boyd Smith Jun 12 '18 at 13:24
1 Answers
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.
-
1Hi, 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? – Scott Yang Nov 27 '18 at 12:22