I'm working on a C++03 project which requires forwarding semantics with the help of Boost.Move/other Boost libraries. The goal of the project is to provide unique_ptr in a forwards-compatible manner to C++11.
The C++11 standard requires the following constructor:
template<class U, class E>
unique_ptr(unique_ptr<U,E>&& u)
Which transfers the stored data from u (basically ptr_val = u.release()), and will:
- If E is a reference type, copy the deleter of u to *this.
- Otherwise, move the deleter of u to *this.
In tests, this code seems to "work":
// data fields: pointer ptr; delete_type del;
// only used if compiler doesn't support rvalue-refs
#define BOOST_COMMA ,
template<typename U, typename E>
unique_ptr(BOOST_RV_REF(unique_ptr<U BOOST_COMMA E>) u) : ptr(u.release()), del(boost::move(u.del))
{}
template<typename U, typename E>
unique_ptr(BOOST_RV_REF(unique_ptr<U BOOST_COMMA E&>) u) : ptr(u.release()), del(u.del)
{}
template<typename U, typename E>
unique_ptr(BOOST_RV_REF(unique_ptr<U BOOST_COMMA const E&>) u) : ptr(u.release()), del(u.del)
{}
Are there any important corner cases which this would not cover?