Ticket #6999: anymove.patch

File anymove.patch, 2.1 KB (added by tr3w <tr3w@…>, 10 years ago)

Naive move semantics implementation.

  • boost/any.hpp

    diff -dur trunc/boost/any.hpp fix/boost/any.hpp
    old new  
    1919#include <boost/throw_exception.hpp>
    2020#include <boost/static_assert.hpp>
    2121
     22#include <boost/move/move.hpp>
     23
    2224// See boost/python/type_id.hpp
    2325// TODO: add BOOST_TYPEID_COMPARE_BY_NAME to config.hpp
    2426# if (defined(__GNUC__) && __GNUC__ >= 3) \
     
    3436{
    3537    class any
    3638    {
     39        BOOST_COPYABLE_AND_MOVABLE_ALT(any)
    3740    public: // structors
    3841
    3942        any()
     
    4750        {
    4851        }
    4952
     53        template<typename ValueType>
     54        any(BOOST_RV_REF(ValueType) value,typename BOOST_MOVE_MPL_NS::disable_if<BOOST_MOVE_MPL_NS::is_lvalue_reference<ValueType> >::type* = 0)
     55          : content(new holder<typename remove_reference<ValueType>::type >(boost::move(value)))
     56        {
     57        }
     58
    5059        any(const any & other)
    5160          : content(other.content ? other.content->clone() : 0)
    5261        {
    5362        }
    5463
     64        any(BOOST_RV_REF(any) other)
     65          : content(other.content)
     66        {
     67            other.content = 0;
     68        }
     69
    5570        ~any()
    5671        {
    5772            delete content;
     
    7287            return *this;
    7388        }
    7489
     90        template<typename ValueType>
     91        typename BOOST_MOVE_MPL_NS::disable_if<BOOST_MOVE_MPL_NS::is_lvalue_reference<ValueType>,any >::type& operator=(BOOST_RV_REF(ValueType) rhs)
     92        {
     93            any(boost::move(rhs)).swap(*this);
     94            return *this;
     95        }
     96
    7597        any & operator=(any rhs)
    7698        {
    7799            rhs.swap(*this);
    78100            return *this;
    79101        }
    80102
     103        any & operator=(BOOST_RV_REF(any) rhs)
     104        {
     105            rhs.swap(*this);
     106            return *this;
     107        }
     108
    81109    public: // queries
    82110
    83111        bool empty() const
     
    119147
    120148            holder(const ValueType & value)
    121149              : held(value)
     150            {
     151            }
     152
     153            holder(BOOST_RV_REF(ValueType) value)
     154              : held(boost::move(value))
    122155            {
    123156            }
    124157