|
Boost : |
Subject: [boost] [move] unique_ptr converting constructor
From: Peter Dimov (lists_at_[hidden])
Date: 2015-05-03 19:23:17
While looking at
https://svn.boost.org/trac/boost/ticket/11259
I found that after implementing a converting shared_ptr constructor that
takes a boost::movelib::unique_ptr, the straightforward code in the ticket
still fails (with g++ in C++03 mode):
namespace mystd {
using boost::shared_ptr;
using boost::make_shared;
using boost::movelib::unique_ptr;
using boost::movelib::make_unique;
}
mystd::unique_ptr<int> load_thing() {
return mystd::make_unique<int>(1);
}
mystd::shared_ptr<int> get_thing() {
return load_thing();
}
So, out of curiosity, I looked at how unique_ptr itself implements its
converting constructor.
It turns out that it, too, doesn't work.
mystd::unique_ptr<int const> get_thing_2() {
return load_thing();
}
Furthermore, the two possible ways to make the shared_ptr code work:
mystd::shared_ptr<int> get_thing() {
mystd::shared_ptr<int> r( load_thing() );
return r;
}
mystd::shared_ptr<int> get_thing() {
mystd::unique_ptr<int> r( load_thing() );
return boost::move( r );
}
fail for the unique_ptr<int const> case.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk