boost::container::vector fails to compile with C++03 compiler

The following example compiles fine when using GCC 4.4.6 with the --std=c++0x flag but fails to compile in C++03 mode. #include <stdint.h> #include <boost/container/vector.hpp> struct data { int i_; boost::container::vector<data> v_; }; int main( int argc, char** argv ) { data myData; myData.i_ = 10; data myData2; myData2.i_ = 30; myData.v_.push_back( myData2 ); return 0; } It compiles successfully with g++ --std=c++0x test-cont.cpp However if I remove the --std=c++0x I get the following errors: g++ test-cont.cpp In file included from include/c++/4.4.6/memory:49, boost/container/container_fwd.hpp:36, boost/container/vector.hpp:20, from test-cont.cpp:2: include/c++/4.4.6/bits/stl_algobase.h: In static member function static _OI std::__copy_move<false, false, std::random_access_iterator_tag>:: __copy_m(_II, _II, _OI) [with _II = boost::container::constant_iterator<data, long int>, _OI = data*]: include/c++/4.4.6/bits/stl_algobase.h:397: instantiated from _OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false, _II = boost::container::constant_iterator<data, long int>, _OI = data*] include/c++/4.4.6/bits/stl_algobase.h:436: instantiated from _OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false, _II = boost::container::constant_iterator<data, long int>, _OI = data*] include/c++/4.4.6/bits/stl_algobase.h:468: instantiated from _OI std::copy(_II, _II, _OI) [with _II = boost::container::constant_iterator<data, long int>, _OI = data*] boost/move/move.hpp:1147: instantiated from boost::copy_or_move(I, I, F, typename boost::move_detail::disable_if< boost::move_detail::is_move_iterator, void>::type*) [with I = boost::container::constant_iterator<data, long int>, F = data*] boost/container/detail/advanced_insert_int.hpp:58: instantiated from void boost::container::container_detail::advanced_insert_aux_proxy<A, FwdIt, Iterator>::copy_remaining_to(Iterator) [with A = std::allocator<data>, FwdIt = boost::container::constant_iterator<data, long int>, Iterator = data*] test-cont.cpp:21: instantiated from here include/c++/4.4.6/bits/stl_algobase.h:343: error: no match for operator= in * __result = __first.boost::container::constant_iterator<T, Difference>::operator* [with T = data, Difference = long int]() test-cont.cpp:5: note: candidates are: data& data::operator=(data&) It looks like boost::container::vector requires move semantics which I assumed would automatically use boost::move when compiled with a c++03 compiler. If I manually modify the struct data to define: a default constructor a copy constructor an assignment operator an emulated move constructor using BOOST_RV_REF an emulated move assignment operator using BOOST_RV_REF The example compiles. Having to manually add these move/copy constructors and assignment operators for C++03 is laborious. Is this a bug with boost::container? -- View this message in context: http://boost.2283326.n4.nabble.com/boost-container-vector-fails-to-compile-w... Sent from the Boost - Users mailing list archive at Nabble.com.

It appears that this is a limitation as explained here: http://www.boost.org/doc/libs/1_51_0/doc/html/move/emulation_limitations.htm... -- View this message in context: http://boost.2283326.n4.nabble.com/boost-container-vector-fails-to-compile-w... Sent from the Boost - Users mailing list archive at Nabble.com.

seems It's trying to use movable objects and this is supported only in C++11 STL On Fri, Oct 26, 2012 at 2:30 PM, mark pashley <mark.pashley@btinternet.com>wrote:
It appears that this is a limitation as explained here:
http://www.boost.org/doc/libs/1_51_0/doc/html/move/emulation_limitations.htm...
-- View this message in context: http://boost.2283326.n4.nabble.com/boost-container-vector-fails-to-compile-w... Sent from the Boost - Users mailing list archive at Nabble.com. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Hassan H. Monfared http://www.linkedin.com/pub/hassan-monfared/55/1b6/33 *I*men *R*ayaneh *S*hargh, +9821-88104832 CEO and technical manager

On Fri, Oct 26, 2012 at 4:00 AM, mark pashley <mark.pashley@btinternet.com>wrote:
It appears that this is a limitation as explained here:
http://www.boost.org/doc/libs/1_51_0/doc/html/move/emulation_limitations.htm...
This is indeed the issue. Basically, if struct data { boost::container::vector<int> x; }; then data turns out not to be const-assignable in C++03, due to the existence of a vector::operator=(vector &) overload rather than vector::operator=(vector const &). To get things functional, all you should have to do is explicitly define a data::operator=(data const &) (which does memberwise assignment), but to enable move semantics (which would be desirable if you had a boost::container::vector<data> as in your snipped example) you would indeed need to define a move constructor and move assignment operator (and default constructor if needed; I think you can get away with using the compiler-generated copy constructor). I would consider this a usability problem as it's error-prone (adding another member to the data struct but forgetting to include it in any or all of the move constructor or copy/move assignment operators is entirely possible) and tedious. This is why I've created macros to automate the generation of this boilerplate (and expand to nothing or the "= default" versions in C++11), and may be something Ion should consider adding. E.g., template< class First, class Second > struct pair { First first; Second second; BOOST_MOVABLE_COPYABLE_MEMBERWISE( typename pair, (( First )( first )) (( Second )( second )) ) }; Incidentally, with some additional complexity, the above macro can enable the move emulation machinery in C++03 iff either of First or Second is movable. If desired, I can see about packaging these up for inclusion in Boost.Move. - Jeff

If desired, I can see about packaging these up for inclusion in Boost.Move.
Sounds Good! Regards, Mark -- View this message in context: http://boost.2283326.n4.nabble.com/boost-container-vector-fails-to-compile-w... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (4)
-
Hassan Monfared
-
Ion Gaztañaga
-
Jeffrey Lee Hellrung, Jr.
-
mark pashley