From 1e4a8303238e16b1f24f6c7069ffd5ef272d2101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Mon, 7 Sep 2015 18:25:36 +0200 Subject: [PATCH] Added move semantics to ebo_functor_holder --- .../intrusive/detail/ebo_functor_holder.hpp | 142 +++++++++++++----- 1 file changed, 102 insertions(+), 40 deletions(-) diff --git a/include/boost/intrusive/detail/ebo_functor_holder.hpp b/include/boost/intrusive/detail/ebo_functor_holder.hpp index 27dd093..9fec5a3 100644 --- a/include/boost/intrusive/detail/ebo_functor_holder.hpp +++ b/include/boost/intrusive/detail/ebo_functor_holder.hpp @@ -22,6 +22,8 @@ # pragma once #endif +#include + namespace boost { namespace intrusive { namespace detail { @@ -155,20 +157,63 @@ template struct is_unary_or_binary_function : is_unary_or_binary_function_impl {}; -template -class ebo_functor_holder_impl +template::value> +class ebo_functor_holder { + BOOST_COPYABLE_AND_MOVABLE(ebo_functor_holder) + public: - ebo_functor_holder_impl() + typedef T functor_type; + + ebo_functor_holder() + : t_() {} - ebo_functor_holder_impl(const T& t) - : t_(t) + + explicit ebo_functor_holder(const T &t) + : t_(t) {} + + explicit ebo_functor_holder(BOOST_RV_REF(T) t) + : t_(::boost::move(t)) + {} + template - ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2) - : t_(arg1, arg2) + ebo_functor_holder(BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2) + : t_(::boost::forward(arg1), ::boost::forward(arg2)) {} + ebo_functor_holder(const ebo_functor_holder &x) + : t_(x) + {} + + ebo_functor_holder(BOOST_RV_REF(ebo_functor_holder) x) + : t_(x.t_) + {} + + ebo_functor_holder& operator=(BOOST_COPY_ASSIGN_REF(ebo_functor_holder) x) + { + this->get() = x.get(); + return *this; + } + + ebo_functor_holder& operator=(BOOST_RV_REF(ebo_functor_holder) x) + { + this->get() = ::boost::move(x.get()); + return *this; + } + + ebo_functor_holder& operator=(const T &x) + { + this->get() = x; + return *this; + } + + ebo_functor_holder& operator=(BOOST_RV_REF(T) x) + { + this->get() = ::boost::move(x); + return *this; + } + T& get(){return t_;} const T& get()const{return t_;} @@ -177,51 +222,68 @@ class ebo_functor_holder_impl }; template -class ebo_functor_holder_impl +class ebo_functor_holder : public T { + BOOST_COPYABLE_AND_MOVABLE(ebo_functor_holder) + public: - ebo_functor_holder_impl() + typedef T functor_type; + + ebo_functor_holder() + : T() {} - explicit ebo_functor_holder_impl(const T& t) - : T(t) + + explicit ebo_functor_holder(const T &t) + : T(t) {} + + explicit ebo_functor_holder(BOOST_RV_REF(T) t) + : T(::boost::move(t)) + {} + template - ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2) - : T(arg1, arg2) + ebo_functor_holder(BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2) + : T(::boost::forward(arg1), ::boost::forward(arg2)) {} + ebo_functor_holder(const ebo_functor_holder &x) + : T(static_cast(x)) + {} + + ebo_functor_holder(BOOST_RV_REF(ebo_functor_holder) x) + : T(BOOST_MOVE_BASE(T, x)) + {} + + ebo_functor_holder& operator=(BOOST_COPY_ASSIGN_REF(ebo_functor_holder) x) + { + const ebo_functor_holder&r = x; + this->get() = x.get(); + return *this; + } + + ebo_functor_holder& operator=(BOOST_RV_REF(ebo_functor_holder) x) + { + this->get() = ::boost::move(x.get()); + return *this; + } + + ebo_functor_holder& operator=(const T &x) + { + this->get() = x; + return *this; + } + + ebo_functor_holder& operator=(BOOST_RV_REF(T) x) + { + this->get() = ::boost::move(x); + return *this; + } + T& get(){return *this;} const T& get()const{return *this;} }; -template -class ebo_functor_holder - : public ebo_functor_holder_impl::value> -{ - private: - typedef ebo_functor_holder_impl::value> super; - - public: - typedef T functor_type; - ebo_functor_holder(){} - explicit ebo_functor_holder(const T& t) - : super(t) - {} - - template - ebo_functor_holder(const Arg1& arg1, const Arg2& arg2) - : super(arg1, arg2) - {} - - ebo_functor_holder& operator=(const ebo_functor_holder& x) - { - this->get()=x.get(); - return *this; - } -}; - - } //namespace detail { } //namespace intrusive { } //namespace boost {