Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52699 - in sandbox/move: boost/container boost/container/detail boost/move libs/move/example libs/move/test
From: igaztanaga_at_[hidden]
Date: 2009-05-01 07:13:12


Author: igaztanaga
Date: 2009-05-01 07:13:10 EDT (Fri, 01 May 2009)
New Revision: 52699
URL: http://svn.boost.org/trac/boost/changeset/52699

Log:
Added has_nothrow_move trait.
Text files modified:
   sandbox/move/boost/container/detail/tree.hpp | 4 ++
   sandbox/move/boost/container/slist.hpp | 4 ++
   sandbox/move/boost/container/stable_vector.hpp | 48 +++++++++++++++++++----------------
   sandbox/move/boost/container/vector.hpp | 2
   sandbox/move/boost/move/move.hpp | 54 +++++++++++++++++++++++++++++++--------
   sandbox/move/libs/move/example/movable.hpp | 3 --
   sandbox/move/libs/move/test/back_move_inserter.cpp | 31 +++++++++++++++++-----
   sandbox/move/libs/move/test/move.cpp | 6 ++++
   8 files changed, 108 insertions(+), 44 deletions(-)

Modified: sandbox/move/boost/container/detail/tree.hpp
==============================================================================
--- sandbox/move/boost/container/detail/tree.hpp (original)
+++ sandbox/move/boost/container/detail/tree.hpp 2009-05-01 07:13:10 EDT (Fri, 01 May 2009)
@@ -146,6 +146,10 @@
 
    #else //#ifndef BOOST_CONTAINERS_PERFECT_FORWARDING
 
+ rbtree_node()
+ : m_data()
+ {}
+
    template<class ...Args>
    rbtree_node(Args &&...args)
       : m_data(boost::forward<Args>(args)...)

Modified: sandbox/move/boost/container/slist.hpp
==============================================================================
--- sandbox/move/boost/container/slist.hpp (original)
+++ sandbox/move/boost/container/slist.hpp 2009-05-01 07:13:10 EDT (Fri, 01 May 2009)
@@ -112,6 +112,10 @@
 
    #else //#ifndef BOOST_CONTAINERS_PERFECT_FORWARDING
 
+ slist_node()
+ : m_data()
+ {}
+
    template<class ...Args>
    slist_node(Args &&...args)
       : m_data(boost::forward<Args>(args)...)

Modified: sandbox/move/boost/container/stable_vector.hpp
==============================================================================
--- sandbox/move/boost/container/stable_vector.hpp (original)
+++ sandbox/move/boost/container/stable_vector.hpp 2009-05-01 07:13:10 EDT (Fri, 01 May 2009)
@@ -90,6 +90,8 @@
    }
 
    private:
+ clear_on_destroy(const clear_on_destroy &);
+ clear_on_destroy &operator=(const clear_on_destroy &);
    C &c_;
    bool do_clear_;
 };
@@ -227,6 +229,10 @@
 
    #else //#ifndef BOOST_CONTAINERS_PERFECT_FORWARDING
 
+ node_type()
+ : value()
+ {}
+
    template<class ...Args>
    node_type(Args &&...args)
       : value(boost::forward<Args>(args)...)
@@ -526,7 +532,16 @@
       STABLE_VECTOR_CHECK_INVARIANT;
    }
 
- stable_vector(size_type n,const T& t=T(),const Allocator& al=Allocator())
+ explicit stable_vector(size_type n)
+ : internal_data(Allocator()), impl(allocator_type())
+ {
+ stable_vector_detail::clear_on_destroy<stable_vector> cod(*this);
+ this->resize(n);
+ STABLE_VECTOR_CHECK_INVARIANT;
+ cod.release();
+ }
+
+ stable_vector(size_type n, const T& t, const Allocator& al=Allocator())
    : internal_data(al),impl(al)
    {
       stable_vector_detail::clear_on_destroy<stable_vector> cod(*this);
@@ -677,16 +692,12 @@
          }
          //Now fill pool if data is not enough
          if((n - size) > this->internal_data.pool_size){
- this->add_to_pool((n - size) - this->internal_data.pool_size, alloc_version());
+ this->add_to_pool((n - size) - this->internal_data.pool_size);
          }
       }
    }
 
- template<class AllocatorVersion>
- void clear_pool(AllocatorVersion,
- typename boost::container::containers_detail::enable_if_c
- <boost::container::containers_detail::is_same<AllocatorVersion, allocator_v1>
- ::value>::type * = 0)
+ void clear_pool(allocator_v1)
    {
       if(!impl.empty() && impl.back()){
          void_ptr &p1 = *(impl.end()-2);
@@ -703,11 +714,7 @@
       }
    }
 
- template<class AllocatorVersion>
- void clear_pool(AllocatorVersion,
- typename boost::container::containers_detail::enable_if_c
- <boost::container::containers_detail::is_same<AllocatorVersion, allocator_v2>
- ::value>::type * = 0)
+ void clear_pool(allocator_v2)
    {
 
       if(!impl.empty() && impl.back()){
@@ -725,11 +732,12 @@
       this->clear_pool(alloc_version());
    }
 
- template<class AllocatorVersion>
- void add_to_pool(size_type n, AllocatorVersion,
- typename boost::container::containers_detail::enable_if_c
- <boost::container::containers_detail::is_same<AllocatorVersion, allocator_v1>
- ::value>::type * = 0)
+ void add_to_pool(size_type n)
+ {
+ this->add_to_pool(n, alloc_version());
+ }
+
+ void add_to_pool(size_type n, allocator_v1)
    {
       size_type remaining = n;
       while(remaining--){
@@ -737,11 +745,7 @@
       }
    }
 
- template<class AllocatorVersion>
- void add_to_pool(size_type n, AllocatorVersion,
- typename boost::container::containers_detail::enable_if_c
- <boost::container::containers_detail::is_same<AllocatorVersion, allocator_v2>
- ::value>::type * = 0)
+ void add_to_pool(size_type n, allocator_v2)
    {
       void_ptr &p1 = *(impl.end()-2);
       void_ptr &p2 = impl.back();

Modified: sandbox/move/boost/container/vector.hpp
==============================================================================
--- sandbox/move/boost/container/vector.hpp (original)
+++ sandbox/move/boost/container/vector.hpp 2009-05-01 07:13:10 EDT (Fri, 01 May 2009)
@@ -477,7 +477,7 @@
    //! throws or T's default or copy constructor throws.
    //!
    //! <b>Complexity</b>: Linear to n.
- vector(size_type n)
+ explicit vector(size_type n)
       : base_t(allocator_type())
    { this->resize(n); }
 

Modified: sandbox/move/boost/move/move.hpp
==============================================================================
--- sandbox/move/boost/move/move.hpp (original)
+++ sandbox/move/boost/move/move.hpp 2009-05-01 07:13:10 EDT (Fri, 01 May 2009)
@@ -31,6 +31,8 @@
 #include <boost/type_traits/has_trivial_destructor.hpp>
 #include <boost/utility/addressof.hpp>
 
+/// @cond
+
 namespace boost {
 namespace move_detail {
 
@@ -52,9 +54,12 @@
    enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) };
 };
 
+
 } //namespace move_detail {
 } //namespace boost {
 
+/// @endcond
+
 #if !defined(BOOST_HAS_RVALUE_REFS) && !defined(BOOST_MOVE_DOXYGEN_INVOKED)
 
 namespace boost {
@@ -114,6 +119,10 @@
    static const bool value = false;
 };
 
+template <class T>
+struct has_nothrow_move : is_movable<T>
+{};
+
 //////////////////////////////////////////////////////////////////////////////
 //
 // move()
@@ -182,12 +191,11 @@
    { return *static_cast<boost::rv<TYPE>* >(this); }\
 //
 
+
 #define BOOST_RV_REF(TYPE)\
    boost::rv< TYPE >& \
 //
 
-/// @cond
-
 #define BOOST_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
    boost::rv< TYPE<ARG1, ARG2> >& \
 //
@@ -196,8 +204,6 @@
    boost::rv< TYPE<ARG1, ARG2, ARG3> >& \
 //
 
-/// @endcond
-
 #define BOOST_FWD_REF(TYPE)\
    const TYPE & \
 //
@@ -209,6 +215,25 @@
 
 namespace boost {
 
+/// @cond
+
+namespace move_detail {
+
+typedef char one;
+struct two {one _[2];};
+
+template <class T>
+struct internal_member_value_traits
+{
+ template <class U> static one test(...);
+ template <class U> static two test(typename U::boost_move_emulation_t* = 0);
+ static const bool value = sizeof(test<T>(0)) == sizeof(two);
+};
+
+} //namespace move_detail {
+
+/// @endcond
+
 //////////////////////////////////////////////////////////////////////////////
 //
 // is_movable
@@ -216,16 +241,25 @@
 //////////////////////////////////////////////////////////////////////////////
 
 //! For compilers with rvalue references, this traits class returns true
-//! if T && is convertible to T.
+//! if BOOST_ENABLE_MOVE_EMULATION is activated.
 //!
 //! For other compilers returns true if T is convertible to <i>boost::rv<T>&</i>
 template<class T>
 class is_movable
 {
    public:
- static const bool value = move_detail::is_convertible<T&&, T>::value;
+// static const bool value = move_detail::is_convertible<T&&, T>::value;
+ static const bool value = move_detail::internal_member_value_traits<T>::value;
 };
 
+//! For compilers with rvalue references, this traits class returns true
+//! if T && is convertible to T.
+//!
+//! For other compilers returns true if T has implemented move emulation.
+template <class T>
+struct has_nothrow_move : is_movable<T>
+{};
+
 //////////////////////////////////////////////////////////////////////////////
 //
 // move
@@ -277,17 +311,17 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
-//! This macro expands to nothing for compilers with rvalue references.
+//! This macro expands to a typedef named boost_move_emulation_t for compilers with rvalue references.
 //! Otherwise expands to:
 //! \code
 //! operator boost::rv<TYPE>&()
 //! { return static_cast<boost::rv<TYPE>& >(*this); }
 //! \endcode
 #define BOOST_ENABLE_MOVE_EMULATION(TYPE)\
+ typedef int boost_move_emulation_t;
+\
 //
 
-/// @cond
-
 #define BOOST_RV_REF_2_TEMPL_ARGS(TYPE, ARG1, ARG2)\
    TYPE<ARG1, ARG2> && \
 //
@@ -296,8 +330,6 @@
    TYPE<ARG1, ARG2, ARG3> && \
 //
 
-/// @endcond
-
 //! This macro expands to <i>T&&</i> for compilers with rvalue references.
 //! Otherwise expands to <i>boost::rv<T> &</i>.
 #define BOOST_RV_REF(TYPE)\

Modified: sandbox/move/libs/move/example/movable.hpp
==============================================================================
--- sandbox/move/libs/move/example/movable.hpp (original)
+++ sandbox/move/libs/move/example/movable.hpp 2009-05-01 07:13:10 EDT (Fri, 01 May 2009)
@@ -38,9 +38,6 @@
 
    bool moved() const //Observer
    { return value_ == 0; }
-
- friend bool operator < (const movable &l, const movable &r)
- { return l.value_ < r.value_; }
 };
 
 //]

Modified: sandbox/move/libs/move/test/back_move_inserter.cpp
==============================================================================
--- sandbox/move/libs/move/test/back_move_inserter.cpp (original)
+++ sandbox/move/libs/move/test/back_move_inserter.cpp 2009-05-01 07:13:10 EDT (Fri, 01 May 2009)
@@ -10,25 +10,27 @@
 //////////////////////////////////////////////////////////////////////////////
 #include <boost/move/move.hpp>
 #include <boost/container/vector.hpp>
+#include <boost/container/list.hpp>
+#include <boost/container/stable_vector.hpp>
 #include "../example/movable.hpp"
 
-int main()
+template<class Container>
+int move_test()
 {
- namespace bc = ::boost::container;
    //Default construct 10 movable objects
- bc::vector<movable> v(10);
+ Container v(10);
 
    //Test default constructed value
- if(v[0].moved()){
+ if(v.begin()->moved()){
       return 1;
    }
 
    //Move values
- bc::vector<movable> v2;
+ Container v2;
    std::copy(v.begin(), v.end(), boost::back_move_inserter(v2));
 
    //Test values have been moved
- if(!v[0].moved()){
+ if(!v.begin()->moved()){
       return 1;
    }
 
@@ -36,9 +38,24 @@
       return 1;
    }
 
- if(v2[0].moved()){
+ if(v2.begin()->moved()){
       return 1;
    }
+ return 0;
+}
+
+int main()
+{
+ namespace bc = ::boost::container;
 
+ if(move_test< bc::vector<movable> >()){
+ return 1;
+ }
+ if(move_test< bc::list<movable> >()){
+ return 1;
+ }
+ if(move_test< bc::stable_vector<movable> >()){
+ return 1;
+ }
    return 0;
 }

Modified: sandbox/move/libs/move/test/move.cpp
==============================================================================
--- sandbox/move/libs/move/test/move.cpp (original)
+++ sandbox/move/libs/move/test/move.cpp 2009-05-01 07:13:10 EDT (Fri, 01 May 2009)
@@ -10,6 +10,7 @@
 //////////////////////////////////////////////////////////////////////////////
 #include <boost/move/move.hpp>
 #include "../example/movable.hpp"
+#include <boost/static_assert.hpp>
 
 movable function(movable m)
 {
@@ -87,8 +88,13 @@
    function_ref(boost::move(m));
 }
 
+struct copyable
+{};
+
 int main()
 {
+ BOOST_STATIC_ASSERT((boost::has_nothrow_move<movable>::value == true));
+ BOOST_STATIC_ASSERT((boost::has_nothrow_move<copyable>::value == false));
    {
       movable m;
       movable m2(boost::move(m));


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