Boost logo

Boost Users :

Subject: [Boost-users] [Move, Container] returning a move-only type
From: John M. Dlugosz (ngnr63q02_at_[hidden])
Date: 2014-02-05 06:05:25


The definition of boost::container::vector includes: BOOST_COPYABLE_AND_MOVABLE
rather than BOOST_MOVABLE_BUT_NOT_COPYABLE if the element type cannot be copied.

If I have:
        typedef boost::container::vector<MyType> VecType;

        VecType foo()
                {
                â‹®
                return boost::move(some_other_vec);
                }

        VecType x= foo();

On a configuration with BOOST_NO_RVALUE_REFERENCES defined, this gives an error within
VecType's copy constructor, since MyType cannot be copied.

If I write
        VecType x= boost::move(foo());
then I get an error that no matching move is viable, as the move(T&) wants an lvalue as
the argument.

I can't write the return type of foo to be rv<VecType> because that can't be copied (fake
move-out like auto_pointer) either; the members are declared private and never defined.

I'm thinking that if VecType were BOOST_MOVABLE_BUT_NOT_COPYABLE then it would work as
expected, since operator rv<VecType>& would be provided.

How can I make this work without surgery on the Boost headers, and hopefully without
something ugly like deriving from vector and having to re-define and forward all the
various constructors and such?

—John


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net