Opened 9 years ago

Closed 8 years ago

#9644 closed Bugs (wontfix)

Containers and move-only elements w/Move Emulation

Reported by: John M. Długosz <mpbecey7gu@…> Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc: igaztanaga@…

Description

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.

This is a bug on Boost.Container, as it defines the copy constructor and the move emulation is not good enough to avoid the defined copy constructor.

(The project I found this on was using Boost 1.49. It is unchanged in the current version, but I've not tested it on that.)

Change History (1)

comment:1 by Ion Gaztañaga, 8 years ago

Resolution: wontfix
Status: newclosed

This is a very old bug, sorry for missing it. Boost.Move has its limitations, and Boost.Container can't do anything with this. But at least in old compilers like MSVC-7.1 recent BOOST_MOVE_RET makes this example work:

#include <boost/container/vector.hpp>

//A non-copyable type
#include "movable_int.hpp"

typedef boost::container::vector<boost::container::test::movable_int> VecType;

VecType some_other_vec;

VecType foo()
{
   return BOOST_MOVE_RET(VecType, some_other_vec);
}

int main()
{
   VecType x= foo();
   return 0;
}

Sadly there is little Boost.Container can do if this Boost.Move workaround does not work in your compiler. I hope this helps.

Note: See TracTickets for help on using tickets.