Boost C++ Libraries: Ticket #9644: Containers and move-only elements w/Move Emulation https://svn.boost.org/trac10/ticket/9644 <p> 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. </p> <p> If I have: </p> <pre class="wiki"> typedef boost::container::vector&lt;MyType&gt; VecType; VecType foo() { ⋮ return boost::move(some_other_vec); } VecType x= foo(); </pre><p> On a configuration with BOOST_NO_RVALUE_REFERENCES defined, this gives an error within <a class="missing wiki">VecType</a>'s copy constructor, since <a class="missing wiki">MyType</a> cannot be copied. </p> <p> If I write </p> <pre class="wiki"> VecType x= boost::move(foo()); </pre><p> then I get an error that no matching move is viable, as the move(T&amp;) wants an lvalue as the argument. </p> <p> I can't write the return type of foo to be rv&lt;<a class="missing wiki">VecType</a>&gt; because that can't be copied (fake move-out like auto_pointer) either; the members are declared private and never defined. </p> <p> 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. </p> <p> (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.) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9644 Trac 1.4.3 Ion Gaztañaga Sat, 17 Jan 2015 19:18:57 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9644#comment:1 https://svn.boost.org/trac10/ticket/9644#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> 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: </p> <pre class="wiki"> #include &lt;boost/container/vector.hpp&gt; //A non-copyable type #include "movable_int.hpp" typedef boost::container::vector&lt;boost::container::test::movable_int&gt; VecType; VecType some_other_vec; VecType foo() { return BOOST_MOVE_RET(VecType, some_other_vec); } int main() { VecType x= foo(); return 0; } </pre><p> Sadly there is little Boost.Container can do if this Boost.Move workaround does not work in your compiler. I hope this helps. </p> Ticket