Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83917 - in trunk: boost libs/any/test
From: antoshkka_at_[hidden]
Date: 2013-04-15 16:17:31


Author: apolukhin
Date: 2013-04-15 16:17:30 EDT (Mon, 15 Apr 2013)
New Revision: 83917
URL: http://svn.boost.org/trac/boost/changeset/83917

Log:
Do not use Boost.Move for rvalues emulation in Boost.Any (now rvalues in Boost.Any work only on C++11 compilers) (refs #6999)
Text files modified:
   trunk/boost/any.hpp | 126 +++++++++++++--------------------------
   trunk/libs/any/test/any_test_rv.cpp | 20 +++++-
   2 files changed, 58 insertions(+), 88 deletions(-)

Modified: trunk/boost/any.hpp
==============================================================================
--- trunk/boost/any.hpp (original)
+++ trunk/boost/any.hpp 2013-04-15 16:17:30 EDT (Mon, 15 Apr 2013)
@@ -10,7 +10,7 @@
 // what: variant type boost::any
 // who: contributed by Kevlin Henney,
 // with features contributed and bugs found by
-// Antony Polukhin, Ed Brey, Mark Rodgers,
+// Antony polukhin, Ed Brey, Mark Rodgers,
 // Peter Dimov, and James Curran
 // when: July 2001, Aplril 2013
 
@@ -22,7 +22,8 @@
 #include <boost/type_traits/is_reference.hpp>
 #include <boost/throw_exception.hpp>
 #include <boost/static_assert.hpp>
-#include <boost/move/move.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_same.hpp>
 
 // See boost/python/type_id.hpp
 // TODO: add BOOST_TYPEID_COMPARE_BY_NAME to config.hpp
@@ -35,80 +36,43 @@
 #include <cstring>
 # endif
 
-#ifdef BOOST_MSVC
-#pragma warning (push)
-#pragma warning (disable : 4521 ) // multiple copy constructors specified
-#pragma warning (disable : 4522 ) // multiple assignment operators specified
-#endif
-
 namespace boost
 {
     class any
     {
- private:
- // Mark this class copyable and movable
- BOOST_COPYABLE_AND_MOVABLE(any)
     public: // structors
 
         any() BOOST_NOEXCEPT
           : content(0)
         {
         }
-
- any(const any & other)
- : content(other.content ? other.content->clone() : 0)
- {
- }
-
- //Move constructor
- any(BOOST_RV_REF(any) other) BOOST_NOEXCEPT
- : content(other.content)
- {
- other.content = 0;
- }
-
-#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- any(any & other)
- : content(other.content ? other.content->clone() : 0)
- {
- }
 
         template<typename ValueType>
- any(ValueType&& value)
- : content(new holder< BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type >(
- ::boost::forward<ValueType>(value)
- ))
+ any(const ValueType & value)
+ : content(new holder<ValueType>(value))
         {
         }
-#else
- any(const ::boost::rv<any>& other)
+
+ any(const any & other)
           : content(other.content ? other.content->clone() : 0)
         {
         }
 
- template<typename ValueType>
- any(const ValueType & value)
- : content(new holder<ValueType>(value))
- {
- BOOST_STATIC_ASSERT_MSG(!boost::move_detail::is_rv<ValueType>::value,
- "You compiler can not deal with emulated move semantics."
- "Please remove moves of non boost::any types to boost::any container."
- );
- }
-#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
- template<typename ValueType>
- any(const ::boost::rv<ValueType> & value)
- : content(new holder<ValueType>(value))
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ // Move constructor
+ any(any&& other) BOOST_NOEXCEPT
+ : content(other.content)
         {
+ other.content = 0;
         }
 
+ // Perfect forwarding of ValueType
         template<typename ValueType>
- any(::boost::rv<ValueType> & value)
- : content(new holder<ValueType>(value))
+ any(ValueType&& value, typename boost::disable_if<boost::is_same<any&, ValueType> >::type* = 0)
+ : content(new holder< typename remove_reference<ValueType>::type >(static_cast<ValueType&&>(value)))
         {
         }
 #endif
-#endif // BOOST_NO_CXX11_RVALUE_REFERENCES
 
         ~any()
         {
@@ -122,49 +86,45 @@
             std::swap(content, rhs.content);
             return *this;
         }
-
- any & operator=(BOOST_COPY_ASSIGN_REF(any) rhs)
+
+
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+ template<typename ValueType>
+ any & operator=(const ValueType & rhs)
         {
             any(rhs).swap(*this);
             return *this;
         }
 
- any & operator=(BOOST_RV_REF(any) rhs) BOOST_NOEXCEPT
+ any & operator=(any rhs)
         {
- rhs.swap(*this); // noexcept
- any().swap(rhs); // noexcept
+ any(rhs).swap(*this);
             return *this;
         }
 
-#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- any & operator=(any& rhs)
+#else
+ any & operator=(const any& rhs)
         {
             any(rhs).swap(*this);
             return *this;
         }
 
- template<typename ValueType>
- any & operator=(ValueType&& rhs)
- {
- any( ::boost::forward<ValueType>(rhs) )
- .swap(*this);
- return *this;
- }
-#else
- template<typename ValueType>
- any & operator=(const ValueType & rhs)
+ // move assignement
+ any & operator=(any&& rhs) BOOST_NOEXCEPT
         {
- any(rhs).swap(*this);
+ rhs.swap(*this);
+ any().swap(rhs);
             return *this;
         }
 
- template<typename ValueType>
- any & operator=(ValueType & rhs)
+ // Perfect forwarding of ValueType
+ template <class ValueType>
+ any & operator=(ValueType&& rhs)
         {
- any(rhs).swap(*this);
+ any(static_cast<ValueType&&>(rhs)).swap(*this);
             return *this;
         }
-#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+#endif
 
     public: // queries
 
@@ -210,10 +170,12 @@
             {
             }
 
- holder(BOOST_RV_REF(ValueType) value)
- : held( boost::move(value) )
+#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
+ holder(ValueType&& value)
+ : held(static_cast< ValueType&& >(value))
             {
             }
+#endif
         public: // queries
 
             virtual const std::type_info & type() const
@@ -242,7 +204,7 @@
         friend ValueType * any_cast(any *) BOOST_NOEXCEPT;
 
         template<typename ValueType>
- friend ValueType * unsafe_any_cast(any *);
+ friend ValueType * unsafe_any_cast(any *) BOOST_NOEXCEPT;
 
 #else
 
@@ -253,7 +215,7 @@
         placeholder * content;
 
     };
-
+
     inline void swap(any & lhs, any & rhs) BOOST_NOEXCEPT
     {
         lhs.swap(rhs);
@@ -329,21 +291,17 @@
     // use typeid() comparison, e.g., when our types may travel across
     // different shared libraries.
     template<typename ValueType>
- inline ValueType * unsafe_any_cast(any * operand)
+ inline ValueType * unsafe_any_cast(any * operand) BOOST_NOEXCEPT
     {
         return &static_cast<any::holder<ValueType> *>(operand->content)->held;
     }
 
     template<typename ValueType>
- inline const ValueType * unsafe_any_cast(const any * operand)
+ inline const ValueType * unsafe_any_cast(const any * operand) BOOST_NOEXCEPT
     {
         return unsafe_any_cast<ValueType>(const_cast<any *>(operand));
     }
-} // namespace boost
-
-#ifdef BOOST_MSVC
-#pragma warning (pop)
-#endif
+}
 
 // Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.
 //

Modified: trunk/libs/any/test/any_test_rv.cpp
==============================================================================
--- trunk/libs/any/test/any_test_rv.cpp (original)
+++ trunk/libs/any/test/any_test_rv.cpp 2013-04-15 16:17:30 EDT (Mon, 15 Apr 2013)
@@ -14,6 +14,16 @@
 
 #include "boost/any.hpp"
 #include "../test.hpp"
+#include <boost/move/move.hpp>
+
+#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
+
+int main()
+{
+ return EXIT_SUCCESS;
+}
+
+#else
 
 namespace any_tests
 {
@@ -62,17 +72,16 @@
 
     
     class move_copy_conting_class {
- BOOST_COPYABLE_AND_MOVABLE(move_copy_conting_class)
     public:
         static unsigned int moves_count;
         static unsigned int copy_count;
 
         move_copy_conting_class(){}
- move_copy_conting_class(BOOST_RV_REF(move_copy_conting_class) /*param*/) {
+ move_copy_conting_class(move_copy_conting_class&& /*param*/) {
             ++ moves_count;
         }
 
- move_copy_conting_class& operator=(BOOST_RV_REF(move_copy_conting_class) /*param*/) {
+ move_copy_conting_class& operator=(move_copy_conting_class&& /*param*/) {
             ++ moves_count;
             return *this;
         }
@@ -80,7 +89,7 @@
         move_copy_conting_class(const move_copy_conting_class&) {
             ++ copy_count;
         }
- move_copy_conting_class& operator=(BOOST_COPY_ASSIGN_REF(move_copy_conting_class) /*param*/) {
+ move_copy_conting_class& operator=(const move_copy_conting_class& /*param*/) {
             ++ copy_count;
             return *this;
         }
@@ -264,3 +273,6 @@
             "checking move counts");
     }
 }
+
+#endif
+


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