Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Boost smart pointers and std smart pointers?

So, I'd like to use smart pointers instead of raw and almost every topic on SO says about Boost library. But std has such things as std::auto_ptr and std::shared_ptr. Why Boost? What is the difference?

It was a question not about difference of the implementation, but about reasons to use Boost pointers. I suppose, given answer, including date of answering and context, is reasonably useful. It helps to understand how Boost pointers were added to std.

like image 294
Pavel Oganesyan Avatar asked Nov 07 '12 10:11

Pavel Oganesyan


People also ask

What is boost shared pointer?

shared_ptr is now part of the C++11 Standard, as std::shared_ptr . Starting with Boost release 1.53, shared_ptr can be used to hold a pointer to a dynamically allocated array. This is accomplished by using an array type ( T[] or T[N] ) as the template parameter.

What library do smart pointers come from?

In modern C++ programming, the Standard Library includes smart pointers, which are used to help ensure that programs are free of memory and resource leaks and are exception-safe.


1 Answers

Basically Boost did shared_ptr first. You may note that many of the new container classes in C++11 were in Boost long ago. I would expect this pattern to continue with the next revisions of the C++ standard, too. Boost supports older C++ compilers that don't talk C++11, which is a big benefit.

Incidentally, std::auto_ptr is deprecated in C++11, which brings in std::shared_ptr and std::unique_ptr instead, which are both significantly more useful.

like image 57
Rook Avatar answered Sep 24 '22 03:09

Rook