From a53f93ff1ab1f6a03b829386665c4860c3e0ff90 Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Sat, 1 Sep 2012 02:01:26 +0000 Subject: [PATCH] move-assign for vector [SVN r80345] --- .../boost/fusion/container/deque/deque.hpp | 7 -- .../container/deque/detail/cpp03_deque.hpp | 9 --- .../container/deque/detail/keyed_element.hpp | 8 --- .../container/vector/detail/vector_n.hpp | 65 +++++++++++-------- .../boost/fusion/container/vector/vector.hpp | 19 +++++- 5 files changed, 57 insertions(+), 51 deletions(-) diff --git a/include/boost/fusion/container/deque/deque.hpp b/include/boost/fusion/container/deque/deque.hpp index fe3754d2..e826394f 100644 --- a/include/boost/fusion/container/deque/deque.hpp +++ b/include/boost/fusion/container/deque/deque.hpp @@ -131,13 +131,6 @@ namespace boost { namespace fusion } #if !defined(BOOST_NO_RVALUE_REFERENCES) - template - deque& operator=(deque&& rhs) - { - base::operator=(std::forward>(rhs)); - return *this; - } - template deque& operator=(T&& rhs) { diff --git a/include/boost/fusion/container/deque/detail/cpp03_deque.hpp b/include/boost/fusion/container/deque/detail/cpp03_deque.hpp index 36832b57..dcc1e3c3 100644 --- a/include/boost/fusion/container/deque/detail/cpp03_deque.hpp +++ b/include/boost/fusion/container/deque/detail/cpp03_deque.hpp @@ -135,15 +135,6 @@ namespace boost { namespace fusion { } #if !defined(BOOST_NO_RVALUE_REFERENCES) - template - deque& - operator=(deque&& rhs) - { - base::operator=(std::forward< - deque>(rhs)); - return *this; - } - template deque& operator=(T&& rhs) diff --git a/include/boost/fusion/container/deque/detail/keyed_element.hpp b/include/boost/fusion/container/deque/detail/keyed_element.hpp index f6250748..4dc60500 100644 --- a/include/boost/fusion/container/deque/detail/keyed_element.hpp +++ b/include/boost/fusion/container/deque/detail/keyed_element.hpp @@ -124,14 +124,6 @@ namespace boost { namespace fusion { namespace detail } #if !defined(BOOST_NO_RVALUE_REFERENCES) - template - keyed_element& operator=(keyed_element&& rhs) - { - base::operator=(std::forward>(rhs)); - value_ = std::forward(rhs.value_); - return *this; - } - keyed_element& operator=(keyed_element&& rhs) { base::operator=(std::forward(rhs)); diff --git a/include/boost/fusion/container/vector/detail/vector_n.hpp b/include/boost/fusion/container/vector/detail/vector_n.hpp index 4652303b..539b47fa 100644 --- a/include/boost/fusion/container/vector/detail/vector_n.hpp +++ b/include/boost/fusion/container/vector/detail/vector_n.hpp @@ -9,27 +9,31 @@ #if !defined(FUSION_MACRO_05042005) #define FUSION_MACRO_05042005 -#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(_##n) +#define FUSION_VECTOR_MEMBER_MEMBER_DEFAULT_INIT(z, n, _) m##n() +#define FUSION_VECTOR_MEMBER_MEMBER_INIT(z, n, _) m##n(_##n) +#define FUSION_VECTOR_MEMBER_COPY_INIT(z, n, _) m##n(other.m##n) +#define FUSION_VECTOR_MEMBER_FWD(z, n, _) m##n(std::forward(other.m##n)) +#define FUSION_VECTOR_ARG_FWD(z, n, _) m##n(std::forward(_##n)) +#define FUSION_VECTOR_MEMBER_MEMBER_DECL(z, n, _) T##n m##n; +#define FUSION_VECTOR_MEMBER_FORWARD(z, n, _) std::forward(_##n) -#define FUSION_MEMBER_ASSIGN(z, n, _) \ +#define FUSION_VECTOR_MEMBER_MEMBER_ASSIGN(z, n, _) \ this->BOOST_PP_CAT(m, n) = vec.BOOST_PP_CAT(m, n); -#define FUSION_DEREF_MEMBER_ASSIGN(z, n, _) \ +#define FUSION_VECTOR_MEMBER_DEREF_MEMBER_ASSIGN(z, n, _) \ this->BOOST_PP_CAT(m, n) = *BOOST_PP_CAT(i, n); -#define FUSION_AT_IMPL(z, n, _) \ +#define FUSION_VECTOR_MEMBER_MEMBER_FORWARD(z, n, _) \ + this->BOOST_PP_CAT(m, n) = std::forward< \ + BOOST_PP_CAT(T, n)>(vec.BOOST_PP_CAT(m, n)); + +#define FUSION_VECTOR_MEMBER_AT_IMPL(z, n, _) \ typename add_reference::type \ at_impl(mpl::int_) { return this->m##n; } \ typename add_reference::type>::type \ at_impl(mpl::int_) const { return this->m##n; } -#define FUSION_ITER_DECL_VAR(z, n, _) \ +#define FUSION_VECTOR_MEMBER_ITER_DECL_VAR(z, n, _) \ typedef typename result_of::next< \ BOOST_PP_CAT(I, BOOST_PP_DEC(n))>::type BOOST_PP_CAT(I, n); \ BOOST_PP_CAT(I, n) BOOST_PP_CAT(i, n) \ @@ -43,32 +47,32 @@ struct BOOST_PP_CAT(vector_data, N) { BOOST_PP_CAT(vector_data, N)() - : BOOST_PP_ENUM(N, FUSION_MEMBER_DEFAULT_INIT, _) {} + : BOOST_PP_ENUM(N, FUSION_VECTOR_MEMBER_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, _) {} + : BOOST_PP_ENUM(N, FUSION_VECTOR_ARG_FWD, _) {} #endif BOOST_PP_CAT(vector_data, N)( BOOST_PP_ENUM_BINARY_PARAMS( N, typename detail::call_param::type _)) - : BOOST_PP_ENUM(N, FUSION_MEMBER_INIT, _) {} + : BOOST_PP_ENUM(N, FUSION_VECTOR_MEMBER_MEMBER_INIT, _) {} BOOST_PP_CAT(vector_data, N)( BOOST_PP_CAT(vector_data, N) const& other) - : BOOST_PP_ENUM(N, FUSION_COPY_INIT, _) {} + : BOOST_PP_ENUM(N, FUSION_VECTOR_MEMBER_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, _) {} + : BOOST_PP_ENUM(N, FUSION_VECTOR_MEMBER_FWD, _) {} #endif BOOST_PP_CAT(vector_data, N)& operator=(BOOST_PP_CAT(vector_data, N) const& vec) { - BOOST_PP_REPEAT(N, FUSION_MEMBER_ASSIGN, _) + BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_MEMBER_ASSIGN, _) return *this; } @@ -78,7 +82,7 @@ { typedef typename result_of::begin::type I0; I0 i0 = fusion::begin(seq); - BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_ITER_DECL_VAR, _) + BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_VECTOR_MEMBER_ITER_DECL_VAR, _) return BOOST_PP_CAT(vector_data, N)(BOOST_PP_ENUM_PARAMS(N, *i)); } @@ -88,11 +92,11 @@ { typedef typename result_of::begin::type I0; I0 i0 = fusion::begin(seq); - BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_ITER_DECL_VAR, _) + BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_VECTOR_MEMBER_ITER_DECL_VAR, _) return BOOST_PP_CAT(vector_data, N)(BOOST_PP_ENUM_PARAMS(N, *i)); } - BOOST_PP_REPEAT(N, FUSION_MEMBER_DECL, _) + BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_MEMBER_DECL, _) }; template @@ -124,12 +128,12 @@ explicit #endif BOOST_PP_CAT(vector, N)(BOOST_PP_ENUM_BINARY_PARAMS(N, T, && _)) - : base_type(BOOST_PP_ENUM(N, FUSION_FORWARD, _)) {} + : base_type(BOOST_PP_ENUM(N, FUSION_VECTOR_MEMBER_FORWARD, _)) {} #endif #if !defined(BOOST_NO_RVALUE_REFERENCES) BOOST_PP_CAT(vector, N)(BOOST_PP_CAT(vector, N)&& rhs) - : base_type(std::move(rhs)) {} + : base_type(std::forward(rhs)) {} #endif template @@ -159,7 +163,7 @@ BOOST_PP_CAT(vector, N)& operator=(BOOST_PP_CAT(vector, N) const& vec) { - BOOST_PP_REPEAT(N, FUSION_MEMBER_ASSIGN, _) + BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_MEMBER_ASSIGN, _) return *this; } @@ -169,12 +173,21 @@ { typedef typename result_of::begin::type I0; I0 i0 = fusion::begin(seq); - BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_ITER_DECL_VAR, _) - BOOST_PP_REPEAT(N, FUSION_DEREF_MEMBER_ASSIGN, _) + BOOST_PP_REPEAT_FROM_TO(1, N, FUSION_VECTOR_MEMBER_ITER_DECL_VAR, _) + BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_DEREF_MEMBER_ASSIGN, _) return *this; } - BOOST_PP_REPEAT(N, FUSION_AT_IMPL, _) +#if !defined(BOOST_NO_RVALUE_REFERENCES) + BOOST_PP_CAT(vector, N)& + operator=(BOOST_PP_CAT(vector, N)&& vec) + { + BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_MEMBER_FORWARD, _) + return *this; + } +#endif + + BOOST_PP_REPEAT(N, FUSION_VECTOR_MEMBER_AT_IMPL, _) template typename add_reference::type>::type diff --git a/include/boost/fusion/container/vector/vector.hpp b/include/boost/fusion/container/vector/vector.hpp index c672bb3e..36c1b7ac 100644 --- a/include/boost/fusion/container/vector/vector.hpp +++ b/include/boost/fusion/container/vector/vector.hpp @@ -108,7 +108,7 @@ namespace boost { namespace fusion #if !defined(BOOST_NO_RVALUE_REFERENCES) vector(vector&& rhs) - : vec(std::move(rhs.vec)) {} + : vec(std::forward(rhs.vec)) {} #endif template @@ -140,6 +140,23 @@ namespace boost { namespace fusion return *this; } +#if !defined(BOOST_NO_RVALUE_REFERENCES) + vector& + operator=(vector&& rhs) + { + vec = std::forward(rhs.vec); + return *this; + } + + template + vector& + operator=(T&& rhs) + { + vec = std::forward(rhs); + return *this; + } +#endif + template typename add_reference< typename mpl::at_c::type