Opened 3 years ago

Last modified 3 years ago

#11259 new Feature Requests

boost::movelib::unique_ptr is not convertible to boost::shared_ptr

Reported by: Tavian Barnes <tavianator@…> Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.58.0 Severity: Problem
Keywords: Cc:


I'm working on porting some code to a platform without a C++11 standard library, and wanted to use the Boost versions of shared_ptr and unique_ptr. Unfortunately code like this doesn't work:

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();

because there is no conversion from movelib::unique_ptr to shared_ptr.

I'm happy to submit a patch that adds it but I'm not sure whether it's okay to add a Boost.Move dependency to Boost.SmartPtr?. And if I do that, should I also add move emulation to boost::shared_ptr? C++03 users might like the performance benefit of moving them instead of copying them.

Change History (2)

comment:2 Changed 3 years ago by Peter Dimov

Well, not exactly fixed. Under g++ (in C++03 mode) at least, your code still doesn't work. You need to do

mystd::shared_ptr<int> get_thing() {
	mystd::shared_ptr<int> r( load_thing() );
	return r;


	mystd::shared_ptr<int> r = load_thing();

doesn't work either.

VC++ doesn't mind.

Note: See TracTickets for help on using tickets.