7

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

Daniel Heilper
  • 1,182
  • 2
  • 17
  • 34
rkm
  • 892
  • 2
  • 16
  • 32
  • `std::unique_ptr` is specified by the standard so any compliant implementation had better support it. But I'm not sure what exactly you are asking. The question you have linked to specifically wanted the semantics by Boost. Your question seems to be something different but I'm not sure what it is. – 5gon12eder May 09 '15 at 18:23
  • vs2010 and forward have an implementation of `std::unique_ptr` – Mgetz May 09 '15 at 18:32

1 Answers1

11

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.

Community
  • 1
  • 1
Howard Hinnant
  • 206,506
  • 52
  • 449
  • 577