Added move ctors for vector and deque (deque for gcc partially working for now)

no preprocessed files yet

[SVN r80331]
This commit is contained in:
Joel de Guzman
2012-08-31 14:33:12 +00:00
parent 16de1dcd01
commit c8b47ca3ca
9 changed files with 159 additions and 10 deletions

View File

@ -71,11 +71,35 @@ namespace boost { namespace fusion
: base(seq)
{}
explicit deque(typename detail::call_param<Head>::type head
, typename detail::call_param<Tail>::type... tail)
#if !defined(BOOST_NO_RVALUE_REFERENCES)
template <typename ...Elements>
deque(deque<Elements...>&& seq)
: base(std::forward<deque<Elements...>>(seq))
{}
#endif
deque(deque const& seq)
: base(seq)
{}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
deque(deque&& seq)
: base(std::forward<deque>(seq))
{}
#endif
explicit deque(Head const& head, Tail const&... tail)
: base(detail::deque_keyed_values<Head, Tail...>::call(head, tail...))
{}
//~ #if !defined(BOOST_NO_RVALUE_REFERENCES)
//~ template <typename Head_, typename ...Tail_>
//~ explicit deque(Head_&& head, Tail_&&... tail)
//~ : base(detail::deque_keyed_values<Head_, Tail_...>
//~ ::call(std::forward<Head_>(head), std::forward<Tail_>(tail)...))
//~ {}
//~ #endif
template <typename Sequence>
explicit deque(Sequence const& seq
, typename disable_if<is_convertible<Sequence, Head> >::type* /*dummy*/ = 0)

View File

@ -87,11 +87,32 @@ namespace boost { namespace fusion {
: base(t0, detail::nil_keyed_element())
{}
explicit deque(deque const& rhs)
: base(rhs)
{}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
explicit deque(T0&& t0)
: base(std::forward<T0>(t0), detail::nil_keyed_element())
{}
explicit deque(deque&& rhs)
: base(std::forward<deque>(rhs))
{}
#endif
template<BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, typename U)>
deque(deque<BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, U)> const& seq)
: base(seq)
{}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
template<BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, typename U)>
deque(deque<BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, U)>&& seq)
: base(std::forward<deque<BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, U)>>(seq))
{}
#endif
template<typename Sequence>
deque(Sequence const& seq, typename disable_if<is_convertible<Sequence, T0> >::type* /*dummy*/ = 0)
: base(base::from_iterator(fusion::begin(seq)))
@ -112,7 +133,6 @@ namespace boost { namespace fusion {
base::operator=(rhs);
return *this;
}
};
}}

View File

@ -72,6 +72,11 @@ namespace boost { namespace fusion { namespace detail
{
return type();
}
static type forward_()
{
return type();
}
};
template<typename N, BOOST_PP_ENUM_PARAMS(FUSION_MAX_DEQUE_SIZE, typename T)>

View File

@ -13,6 +13,8 @@
#error "C++03 only! This file should not have been included"
#endif
#define FUSION_DEQUE_FORWARD_CTOR_FORWARD(z, n, _) std::forward<T##n>(t##n)
#include <boost/preprocessor/iterate.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
@ -22,14 +24,22 @@
#define BOOST_PP_ITERATION_LIMITS (2, FUSION_MAX_DEQUE_SIZE)
#include BOOST_PP_ITERATE()
#undef FUSION_DEQUE_FORWARD_CTOR_FORWARD
#endif
#else
#define N BOOST_PP_ITERATION()
deque(BOOST_PP_ENUM_BINARY_PARAMS(N, typename add_reference<typename add_const<T, >::type>::type t))
: base(detail::deque_keyed_values<BOOST_PP_ENUM_PARAMS(N, T)>::call(BOOST_PP_ENUM_PARAMS(N, t)))
: base(detail::deque_keyed_values<BOOST_PP_ENUM_PARAMS(N, T)>::construct(BOOST_PP_ENUM_PARAMS(N, t)))
{}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
deque(BOOST_PP_ENUM_BINARY_PARAMS(N, T, && t))
: base(detail::deque_keyed_values<BOOST_PP_ENUM_PARAMS(N, T)>::
forward_(BOOST_PP_ENUM(N, FUSION_DEQUE_FORWARD_CTOR_FORWARD, _)))
{}
#endif
#undef N
#endif

View File

@ -15,19 +15,24 @@
#include <boost/preprocessor/iterate.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/preprocessor/repetition/enum_shifted.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#define FUSION_DEQUE_KEYED_VALUES_FORWARD(z, n, _) \
std::forward<BOOST_PP_CAT(T, n)>(BOOST_PP_CAT(t, n))
#define BOOST_PP_FILENAME_1 \
<boost/fusion/container/deque/detail/deque_keyed_values_call.hpp>
#define BOOST_PP_ITERATION_LIMITS (1, FUSION_MAX_DEQUE_SIZE)
#include BOOST_PP_ITERATE()
#undef FUSION_DEQUE_KEYED_VALUES_FORWARD
#endif
#else
#define N BOOST_PP_ITERATION()
static type call(BOOST_PP_ENUM_BINARY_PARAMS(N, typename add_reference<typename add_const<T, >::type>::type t))
static type construct(BOOST_PP_ENUM_BINARY_PARAMS(N, typename add_reference<typename add_const<T, >::type>::type t))
{
return type(t0,
deque_keyed_values_impl<
@ -38,5 +43,16 @@
>::call(BOOST_PP_ENUM_SHIFTED_PARAMS(N, t)));
}
static type forward_(BOOST_PP_ENUM_BINARY_PARAMS(N, T, && t))
{
return type(std::forward<T0>(t0),
deque_keyed_values_impl<
next_index
#if N > 1
, BOOST_PP_ENUM_SHIFTED_PARAMS(N, T)
#endif
>::forward_(BOOST_PP_ENUM_SHIFTED(N, FUSION_DEQUE_KEYED_VALUES_FORWARD, _)));
}
#undef N
#endif

View File

@ -47,16 +47,39 @@ namespace boost { namespace fusion { namespace detail
*it, base::from_iterator(fusion::next(it)));
}
keyed_element(keyed_element const& rhs)
: Rest(rhs.get_base()), value_(rhs.value_)
{}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
keyed_element(keyed_element&& rhs)
: Rest(std::forward<Rest>(rhs.forward_base()))
, value_(std::forward<Value>(rhs.value_))
{}
#endif
template <typename U, typename Rst>
keyed_element(keyed_element<Key, U, Rst> const& rhs)
: Rest(rhs.get_base()), value_(rhs.value_)
{}
Rest const get_base() const
Rest& get_base()
{
return *this;
}
Rest const& get_base() const
{
return *this;
}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
Rest&& forward_base()
{
return std::forward<Rest>(*static_cast<Rest*>(this));
}
#endif
typename cref_result<Value>::type get(Key) const
{
return value_;
@ -67,10 +90,17 @@ namespace boost { namespace fusion { namespace detail
return value_;
}
keyed_element(typename call_param<Value>::type value, Rest const& rest)
keyed_element(Value const& value, Rest const& rest)
: Rest(rest), value_(value)
{}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
keyed_element(Value&& value, Rest&& rest)
: Rest(std::forward<Rest>(rest))
, value_(std::forward<Value>(value))
{}
#endif
keyed_element()
: Rest(), value_()
{}

View File

@ -12,11 +12,14 @@
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#define FUSION_FORWARD_CTOR_MOVE(z, n, _) std::move(_##n)
#define BOOST_PP_FILENAME_1 \
<boost/fusion/container/vector/detail/vector_forward_ctor.hpp>
#define BOOST_PP_ITERATION_LIMITS (1, FUSION_MAX_VECTOR_SIZE)
#include BOOST_PP_ITERATE()
#undef FUSION_FORWARD_CTOR_MOVE
#endif
#else // defined(BOOST_PP_IS_ITERATING)
///////////////////////////////////////////////////////////////////////////////
@ -34,6 +37,14 @@
N, typename detail::call_param<T, >::type _))
: vec(BOOST_PP_ENUM_PARAMS(N, _)) {}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
#if N == 1
explicit
#endif
vector(BOOST_PP_ENUM_BINARY_PARAMS(N, T, && _))
: vec(BOOST_PP_ENUM(N, FUSION_FORWARD_CTOR_MOVE, _)) {}
#endif
#undef N
#endif // defined(BOOST_PP_IS_ITERATING)

View File

@ -12,7 +12,10 @@
#define FUSION_MEMBER_DEFAULT_INIT(z, n, _) m##n()
#define FUSION_MEMBER_INIT(z, n, _) m##n(_##n)
#define FUSION_COPY_INIT(z, n, _) m##n(other.m##n)
#define FUSION_MOVE_FROM_OTHER(z, n, _) m##n(std::move(other.m##n))
#define FUSION_MOVE(z, n, _) m##n(std::move(_##n))
#define FUSION_MEMBER_DECL(z, n, _) T##n m##n;
#define FUSION_FORWARD(z, n, _) std::forward<T##n>(_##n)
#define FUSION_MEMBER_ASSIGN(z, n, _) \
this->BOOST_PP_CAT(m, n) = vec.BOOST_PP_CAT(m, n);
@ -42,6 +45,11 @@
BOOST_PP_CAT(vector_data, N)()
: BOOST_PP_ENUM(N, FUSION_MEMBER_DEFAULT_INIT, _) {}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
BOOST_PP_CAT(vector_data, N)(BOOST_PP_ENUM_BINARY_PARAMS(N, T, && _))
: BOOST_PP_ENUM(N, FUSION_MOVE, _) {}
#endif
BOOST_PP_CAT(vector_data, N)(
BOOST_PP_ENUM_BINARY_PARAMS(
N, typename detail::call_param<T, >::type _))
@ -51,6 +59,12 @@
BOOST_PP_CAT(vector_data, N) const& other)
: BOOST_PP_ENUM(N, FUSION_COPY_INIT, _) {}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
BOOST_PP_CAT(vector_data, N)(
BOOST_PP_CAT(vector_data, N)&& other)
: BOOST_PP_ENUM(N, FUSION_MOVE_FROM_OTHER, _) {}
#endif
BOOST_PP_CAT(vector_data, N)&
operator=(BOOST_PP_CAT(vector_data, N) const& vec)
{
@ -105,6 +119,19 @@
N, typename detail::call_param<T, >::type _))
: base_type(BOOST_PP_ENUM_PARAMS(N, _)) {}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
#if (N == 1)
explicit
#endif
BOOST_PP_CAT(vector, N)(BOOST_PP_ENUM_BINARY_PARAMS(N, T, && _))
: base_type(BOOST_PP_ENUM(N, FUSION_FORWARD, _)) {}
#endif
#if !defined(BOOST_NO_RVALUE_REFERENCES)
BOOST_PP_CAT(vector, N)(BOOST_PP_CAT(vector, N)&& rhs)
: base_type(std::move(rhs)) {}
#endif
template <BOOST_PP_ENUM_PARAMS(N, typename U)>
BOOST_PP_CAT(vector, N)(
BOOST_PP_CAT(vector, N)<BOOST_PP_ENUM_PARAMS(N, U)> const& vec)
@ -166,3 +193,4 @@
#undef N

View File

@ -106,6 +106,11 @@ namespace boost { namespace fusion
vector(vector const& rhs)
: vec(rhs.vec) {}
#if !defined(BOOST_NO_RVALUE_REFERENCES)
vector(vector&& rhs)
: vec(std::move(rhs.vec)) {}
#endif
template <typename Sequence>
vector(Sequence const& rhs)
: vec(BOOST_FUSION_VECTOR_COPY_INIT()) {}