Alternatives to boost::scoped_ptr in C++ 11

boost, c++

Solution

Yes, `scoped_ptr` can and should be replaced with `unique_ptr`. They represent the same idea (unique ownership), but `unique_ptr` does it better, and allows transfer of ownership via move semantics. (`scoped_ptr` didn't because it wasn't possible in C++98)

Problem

We've just upgraded our compiler to VC++ 2013 which has support for C++ 11. Previously we've been using shared_ptr and scoped_ptr classes from Boost, but since that is all we've been using from Boost, we're looking to remove that dependency. As far as I can tell, std::shared_ptrs are a drop-in replacement for boost::shared_ptrs, so that's (hopefully) easy. However, what is the best replacement for Boost scoped_ptrs (if there is one)? Would it be unique_ptr? (To be honest, even though I wrote the code, it was about 10 years ago, and I've forgotten what the purpose of using scoped_ptrs was... Maybe I was just "playing" with Boost, but as far as I can see a plain pointer would probably do in the cases I've examined).

Original source