diff --git a/include/boost/move/detail/move_helpers.hpp b/include/boost/move/detail/move_helpers.hpp index ddfea9b..ed6f3d5 100644 --- a/include/boost/move/detail/move_helpers.hpp +++ b/include/boost/move/detail/move_helpers.hpp @@ -19,6 +19,8 @@ #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || (defined(_MSC_VER) && (_MSC_VER == 1600)) #include +#include +#include #include #endif #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) @@ -28,6 +30,7 @@ #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) struct not_a_type; +struct not_a_type2; #define BOOST_MOVE_CATCH_CONST(U) \ typename ::boost::mpl::if_< ::boost::is_class, BOOST_CATCH_CONST_RLVALUE(U), const U &>::type #define BOOST_MOVE_CATCH_RVALUE(U)\ @@ -40,7 +43,6 @@ struct not_a_type; #endif #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES - #define BOOST_MOVE_CONVERSION_AWARE_CATCH(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION)\ RETURN_VALUE PUB_FUNCTION(BOOST_MOVE_CATCH_CONST(TYPE) x)\ { return FWD_FUNCTION(static_cast(x)); }\ @@ -72,7 +74,7 @@ struct not_a_type; return FWD_FUNCTION(::boost::move(t));\ }\ // - +// ::boost::is_convertible::value && #elif (defined(_MSC_VER) && (_MSC_VER == 1600)) #define BOOST_MOVE_CONVERSION_AWARE_CATCH(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION)\ @@ -108,7 +110,7 @@ struct not_a_type; #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES -#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1)\ +#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1, UNLESS_CONVERTIBLE_TO)\ RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_CONST(TYPE) x)\ { return FWD_FUNCTION(arg1, static_cast(x)); }\ \ @@ -119,8 +121,7 @@ struct not_a_type; { return FWD_FUNCTION(arg1, const_cast(x)); }\ \ template\ - typename ::boost::enable_if_c\ - < ::boost::is_class::value &&\ + typename ::boost::enable_if_c<\ ::boost::is_same::value &&\ !::boost::has_move_emulation_enabled::value\ , RETURN_VALUE >::type\ @@ -128,10 +129,10 @@ struct not_a_type; { return FWD_FUNCTION(arg1, u); }\ \ template\ - typename ::boost::enable_if_c\ - < (!::boost::is_class::value || \ - !::boost::move_detail::is_rv::value) && \ - !::boost::is_same::value \ + typename ::boost::enable_if_c<\ + !::boost::move_detail::is_rv::value && \ + !::boost::is_same::value && \ + !::boost::is_convertible::value \ , RETURN_VALUE >::type\ PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\ {\ @@ -142,7 +143,7 @@ struct not_a_type; #elif (defined(_MSC_VER) && (_MSC_VER == 1600)) -#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1)\ +#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1, UNLESS_CONVERTIBLE_TO)\ RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_CONST(TYPE) x)\ { return FWD_FUNCTION(arg1, static_cast(x)); }\ \ @@ -151,7 +152,8 @@ struct not_a_type; \ template\ typename ::boost::enable_if_c\ - < !::boost::is_same::value\ + < !::boost::is_same::value && \ + !::boost::is_convertible::value \ , RETURN_VALUE >::type\ PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\ {\ @@ -162,7 +164,7 @@ struct not_a_type; #else -#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1)\ +#define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1, UNLESS_CONVERTIBLE_TO)\ RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_CONST(TYPE) x)\ { return FWD_FUNCTION(arg1, static_cast(x)); }\ \ diff --git a/test/conversion_test.cpp b/test/conversion_test.cpp index 5c973d7..9412ddb 100644 --- a/test/conversion_test.cpp +++ b/test/conversion_test.cpp @@ -84,34 +84,99 @@ class conversion_target_movable template class container { - typename ::boost::aligned_storage::value>::type storage_; + T *storage_; public: + struct const_iterator{}; + struct iterator : const_iterator{}; + container() + : storage_(0) + {} - typedef T * iterator; - typedef const T * const_iterator; + ~container() + { delete storage_; } + + container(const container &c) + : storage_(c.storage_ ? new T(*c.storage_) : 0) + {} + + container &operator=(const container &c) + { + if(storage_){ + delete storage_; + storage_ = 0; + } + storage_ = c.storage_ ? new T(*c.storage_) : 0; + return *this; + } BOOST_MOVE_CONVERSION_AWARE_CATCH(push_back, T, void, priv_push_back) - BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator) + BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(insert, T, iterator, priv_insert, const_iterator, const_iterator) + + template + iterator insert(Iterator, Iterator){ return iterator(); } ConstructionType construction_type() const - { return construction_type_impl(typename ::boost::is_class::type()); } + { return construction_type_impl(typename ::boost::is_class::type()); } + ConstructionType construction_type_impl(::boost::true_type) const - { return reinterpret_cast(storage_).construction_type(); } + { return storage_->construction_type(); } + ConstructionType construction_type_impl(::boost::false_type) const - { return Copied; } - - iterator begin() { return iterator(0); } + { return Copied; } + iterator begin() const { return iterator(); } + private: + template + void priv_construct(BOOST_MOVE_CATCH_FWD(U) x) + { + if(storage_){ + delete storage_; + storage_ = 0; + } + storage_ = new T(::boost::forward(x)); + } template void priv_push_back(BOOST_MOVE_CATCH_FWD(U) x) - { ::new (&storage_) T(::boost::forward(x)); } + { priv_construct(::boost::forward(x)); } template iterator priv_insert(const_iterator, BOOST_MOVE_CATCH_FWD(U) x) - { ::new (&storage_) T(::boost::forward(x)); return 0; } + { priv_construct(::boost::forward(x)); return iterator(); } +}; + +class recursive_container +{ + BOOST_COPYABLE_AND_MOVABLE(recursive_container) + public: + recursive_container() + {} + + recursive_container(const recursive_container &c) + : container_(c.container_) + {} + + recursive_container(BOOST_RV_REF(recursive_container) c) + : container_(::boost::move(c.container_)) + {} + + recursive_container & operator =(BOOST_COPY_ASSIGN_REF(recursive_container) c) + { + container_= c.container_; + return *this; + } + + recursive_container & operator =(BOOST_RV_REF(recursive_container) c) + { + container_= ::boost::move(c.container_); + return *this; + } + + container container_; + friend bool operator< (const recursive_container &a, const recursive_container &b) + { return &a < &b; } }; @@ -289,6 +354,61 @@ int main() c.insert(c.begin(), conversion_source()); assert(c.construction_type() == Copied); } + //c.insert(c.begin(), c.begin()); + } + + { + container c; + { + int x; + c.push_back(x); + assert(c.construction_type() == Copied); + c.insert(c.begin(), c.construction_type()); + assert(c.construction_type() == Copied); + } + { + const int x = 0; + c.push_back(x); + assert(c.construction_type() == Copied); + c.insert(c.begin(), x); + assert(c.construction_type() == Copied); + } + { + c.push_back(int(0)); + assert(c.construction_type() == Copied); + c.insert(c.begin(), int(0)); + assert(c.construction_type() == Copied); + } + { + conversion_source x; + c.push_back(x); + assert(c.construction_type() == Copied); + c.insert(c.begin(), x); + assert(c.construction_type() == Copied); + } + + { + const conversion_source x; + c.push_back(x); + assert(c.construction_type() == Copied); + c.insert(c.begin(), x); + assert(c.construction_type() == Copied); + } + { + c.push_back(conversion_source()); + assert(c.construction_type() == Copied); + c.insert(c.begin(), conversion_source()); + assert(c.construction_type() == Copied); + } + c.insert(c.begin(), c.begin()); + } + + { + recursive_container c; + recursive_container internal; + c.container_.insert(c.container_.begin(), recursive_container()); + c.container_.insert(c.container_.begin(), internal); + c.container_.insert(c.container_.begin(), c.container_.begin()); } return 0; @@ -677,5 +797,4 @@ int main() return 0; } - -*/ \ No newline at end of file +*/