Search code examples
c++c++11raii

Using a unique_ptr without C++11


I would like to pass pointers to d around from one container to a next. At no point will there be more than one owner of the pointer (or d itself). I'd like that when the last pointer goes out of scope, delete d automatically called.

In C++11, I'd do this with unique_ptr. But, alas, I can't use C++11. What is the best equivalent in C++? Boost is fine. Or, if there is none, what is the appropriate way to handle this?


Solution

  • Well, boost::movelib::unique_ptr is part of the Boost.Move library which offers "Portable move semantics for C++03 and C++11 compilers". Since unique_ptr clearly needs move semantic, this looks like your best choice.