Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing boost::scoped_ptr to std::unique_ptr

I am using boost::scoped_ptr in the code which I would like to replace with std::unique_ptr. I would like to know if there are any disadvantages in moving to std::unique_ptr. Boost is portable across platforms and compilers. But I am not sure if C++11 supported by all compilers such as MSVC. I know GCC and Clang support C++11 pretty well.

I've already read the SO question “intrusive_ptr in C++11” whose short answer is “No”. So If anyone had experience in using both, please share your comments and thoughts

like image 921
rkm Avatar asked May 09 '15 18:05

rkm


1 Answers

Mgetz has generously provided the information that all recent VS implementations supply unique_ptr.

I recommend that you replace boost::scoped_ptr<T> with const std::unique_ptr<T>. The reason for the const is that this most closely models boost::scoped_ptr<T> which is not "movable." However I believe boost::scoped_ptr<T> does support swapping. So if you are using that, the compiler will complain everywhere you try to swap a const std::unique_ptr<T> and you can then mark those instances as non-const.

like image 68
Howard Hinnant Avatar answered Oct 13 '22 06:10

Howard Hinnant