Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85659 - in trunk: boost/move/detail libs/move/test
From: igaztanaga_at_[hidden]
Date: 2013-09-12 17:56:02


Author: igaztanaga
Date: 2013-09-12 17:56:02 EDT (Thu, 12 Sep 2013)
New Revision: 85659
URL: http://svn.boost.org/trac/boost/changeset/85659

Log:
Added a convertible guard to conversion-aware macro to avoid ambiguities in overloads.

Text files modified:
   trunk/boost/move/detail/move_helpers.hpp | 26 +++---
   trunk/libs/move/test/conversion_test.cpp | 145 ++++++++++++++++++++++++++++++++++++---
   2 files changed, 146 insertions(+), 25 deletions(-)

Modified: trunk/boost/move/detail/move_helpers.hpp
==============================================================================
--- trunk/boost/move/detail/move_helpers.hpp Thu Sep 12 17:50:38 2013 (r85658)
+++ trunk/boost/move/detail/move_helpers.hpp 2013-09-12 17:56:02 EDT (Thu, 12 Sep 2013) (r85659)
@@ -19,6 +19,8 @@
 
 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || (defined(_MSC_VER) && (_MSC_VER == 1600))
 #include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_class.hpp>
+#include <boost/type_traits/is_convertible.hpp>
 #include <boost/utility/enable_if.hpp>
 #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<U>, BOOST_CATCH_CONST_RLVALUE(U), const U &>::type
 #define BOOST_MOVE_CATCH_RVALUE(U)\
@@ -40,7 +43,6 @@
 #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<const TYPE&>(x)); }\
@@ -72,7 +74,7 @@
       return FWD_FUNCTION(::boost::move(t));\
    }\
 //
-
+// ::boost::is_convertible<BOOST_MOVE_TEMPL_PARAM, TYPE>::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 @@
 
 #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<const TYPE&>(x)); }\
 \
@@ -119,8 +121,7 @@
    { return FWD_FUNCTION(arg1, const_cast<const TYPE &>(x)); }\
 \
    template<class BOOST_MOVE_TEMPL_PARAM>\
- typename ::boost::enable_if_c\
- < ::boost::is_class<TYPE>::value &&\
+ typename ::boost::enable_if_c<\
                         ::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value &&\
                        !::boost::has_move_emulation_enabled<BOOST_MOVE_TEMPL_PARAM>::value\
                      , RETURN_VALUE >::type\
@@ -128,10 +129,10 @@
    { return FWD_FUNCTION(arg1, u); }\
 \
    template<class BOOST_MOVE_TEMPL_PARAM>\
- typename ::boost::enable_if_c\
- < (!::boost::is_class<BOOST_MOVE_TEMPL_PARAM>::value || \
- !::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value) && \
- !::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value \
+ typename ::boost::enable_if_c<\
+ !::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>::value && \
+ !::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value && \
+ !::boost::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO>::value \
                      , RETURN_VALUE >::type\
    PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
    {\
@@ -142,7 +143,7 @@
 
 #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<const TYPE&>(x)); }\
 \
@@ -151,7 +152,8 @@
 \
    template<class BOOST_MOVE_TEMPL_PARAM>\
    typename ::boost::enable_if_c\
- < !::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value\
+ < !::boost::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value && \
+ !::boost::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO>::value \
                      , RETURN_VALUE >::type\
    PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
    {\
@@ -162,7 +164,7 @@
 
 #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<const TYPE&>(x)); }\
 \

Modified: trunk/libs/move/test/conversion_test.cpp
==============================================================================
--- trunk/libs/move/test/conversion_test.cpp Thu Sep 12 17:50:38 2013 (r85658)
+++ trunk/libs/move/test/conversion_test.cpp 2013-09-12 17:56:02 EDT (Thu, 12 Sep 2013) (r85659)
@@ -84,34 +84,99 @@
 template<class T>
 class container
 {
- typename ::boost::aligned_storage<sizeof(T), ::boost::alignment_of<T>::value>::type storage_;
+ T *storage_;
    public:
+ struct const_iterator{};
+ struct iterator : const_iterator{};
+ container()
+ : storage_(0)
+ {}
+
+ ~container()
+ { delete storage_; }
+
+ container(const container &c)
+ : storage_(c.storage_ ? new T(*c.storage_) : 0)
+ {}
 
- typedef T * iterator;
- typedef const T * const_iterator;
+ 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 <class Iterator>
+ iterator insert(Iterator, Iterator){ return iterator(); }
 
    ConstructionType construction_type() const
- { return construction_type_impl(typename ::boost::is_class<T>::type()); }
+ { return construction_type_impl(typename ::boost::is_class<T>::type()); }
+
    ConstructionType construction_type_impl(::boost::true_type) const
- { return reinterpret_cast<const T&>(storage_).construction_type(); }
- ConstructionType construction_type_impl(::boost::false_type) const
- { return Copied; }
+ { return storage_->construction_type(); }
 
- iterator begin() { return iterator(0); }
+ ConstructionType construction_type_impl(::boost::false_type) const
+ { return Copied; }
 
+ iterator begin() const { return iterator(); }
+
    private:
+ template<class U>
+ void priv_construct(BOOST_MOVE_CATCH_FWD(U) x)
+ {
+ if(storage_){
+ delete storage_;
+ storage_ = 0;
+ }
+ storage_ = new T(::boost::forward<U>(x));
+ }
 
    template<class U>
    void priv_push_back(BOOST_MOVE_CATCH_FWD(U) x)
- { ::new (&storage_) T(::boost::forward<U>(x)); }
+ { priv_construct(::boost::forward<U>(x)); }
 
    template<class U>
    iterator priv_insert(const_iterator, BOOST_MOVE_CATCH_FWD(U) x)
- { ::new (&storage_) T(::boost::forward<U>(x)); return 0; }
+ { priv_construct(::boost::forward<U>(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<recursive_container> container_;
+ friend bool operator< (const recursive_container &a, const recursive_container &b)
+ { return &a < &b; }
 };
 
 
@@ -289,6 +354,61 @@
          c.insert(c.begin(), conversion_source());
          assert(c.construction_type() == Copied);
       }
+ //c.insert(c.begin(), c.begin());
+ }
+
+ {
+ container<int> 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 @@
 
    return 0;
 }
-
-*/
\ No newline at end of file
+*/


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk