Added move semantics to ebo_functor_holder

This commit is contained in:
Ion Gaztañaga
2015-09-07 18:25:36 +02:00
parent 79272de8ba
commit 1e4a830323

View File

@@ -22,6 +22,8 @@
# pragma once # pragma once
#endif #endif
#include <boost/move/utility_core.hpp>
namespace boost { namespace boost {
namespace intrusive { namespace intrusive {
namespace detail { namespace detail {
@@ -155,20 +157,63 @@ template<typename T>
struct is_unary_or_binary_function : is_unary_or_binary_function_impl<T> struct is_unary_or_binary_function : is_unary_or_binary_function_impl<T>
{}; {};
template<typename T, bool IsEmpty = true> template<typename T, bool = is_unary_or_binary_function<T>::value>
class ebo_functor_holder_impl class ebo_functor_holder
{ {
BOOST_COPYABLE_AND_MOVABLE(ebo_functor_holder)
public: 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<class Arg1, class Arg2> template<class Arg1, class Arg2>
ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2) ebo_functor_holder(BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
: t_(arg1, arg2) : t_(::boost::forward<Arg1>(arg1), ::boost::forward<Arg2>(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_;} T& get(){return t_;}
const T& get()const{return t_;} const T& get()const{return t_;}
@@ -177,51 +222,68 @@ class ebo_functor_holder_impl
}; };
template<typename T> template<typename T>
class ebo_functor_holder_impl<T, false> class ebo_functor_holder<T, false>
: public T : public T
{ {
BOOST_COPYABLE_AND_MOVABLE(ebo_functor_holder)
public: 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<class Arg1, class Arg2> template<class Arg1, class Arg2>
ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2) ebo_functor_holder(BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
: T(arg1, arg2) : T(::boost::forward<Arg1>(arg1), ::boost::forward<Arg2>(arg2))
{} {}
ebo_functor_holder(const ebo_functor_holder &x)
: T(static_cast<const T&>(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;} T& get(){return *this;}
const T& get()const{return *this;} const T& get()const{return *this;}
}; };
template<typename T>
class ebo_functor_holder
: public ebo_functor_holder_impl<T, is_unary_or_binary_function<T>::value>
{
private:
typedef ebo_functor_holder_impl<T, is_unary_or_binary_function<T>::value> super;
public:
typedef T functor_type;
ebo_functor_holder(){}
explicit ebo_functor_holder(const T& t)
: super(t)
{}
template<class Arg1, class Arg2>
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 detail {
} //namespace intrusive { } //namespace intrusive {
} //namespace boost { } //namespace boost {