Alternative library/template class for the deprecated auto_ptr in C++17

277 views Asked by At

Have shared project library that has to be compiled with various compilers C++17 C++03 etc. So just using the better unique_ptr or the less than perfect auto_ptr as appropriate is not ideal if the code is to be kept common.

Have look at the #ifdef type solution but it gets messy. Plus making edits to well tried and tested coded is not a particular attractive idea!

Anyone know of a form, fit and function drop in replacement for auto_ptr?

1

There are 1 answers

0
Cosme On

There are Boost.Move and Boost Smart Pointer. std::unique_ptr and std::auto_ptr may be replaced by boost::movelib::unique_ptr. std::shared_ptr and std::weak_ptr by boost::shared_ptr and boost::weak_ptr.

And, you can be more expressive with boost::scoped_ptr when there is no intent to transfer ownership.