From e11c2eb867d33ac7cedcafbe4f75357116fee1b3 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 3 Nov 2011 13:15:21 +0900 Subject: [PATCH] =?UTF-8?q?sprout/utility/move.hpp=20=E8=BF=BD=E5=8A=A0=20?= =?UTF-8?q?tuple=20=E3=81=AB=E8=A6=81=E7=B4=A0=E6=95=B0=E3=81=AE=E7=95=B0?= =?UTF-8?q?=E3=81=AA=E3=82=8B=E3=82=BF=E3=83=97=E3=83=AB=E3=81=8B=E3=82=89?= =?UTF-8?q?=E3=81=AE=E6=9A=97=E9=BB=99=E3=81=AE=E5=A4=89=E6=8F=9B=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sprout/tuple/tuple.hpp | 62 ++++++++++++++++++++++++++++-------- sprout/utility.hpp | 2 +- sprout/utility/forward.hpp | 1 - sprout/utility/move.hpp | 17 ++++++++++ sprout/utility/operation.hpp | 8 +++++ 5 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 sprout/utility/move.hpp create mode 100644 sprout/utility/operation.hpp diff --git a/sprout/tuple/tuple.hpp b/sprout/tuple/tuple.hpp index d2bd9bf8..4b26406d 100644 --- a/sprout/tuple/tuple.hpp +++ b/sprout/tuple/tuple.hpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include namespace sprout { namespace tuples { @@ -71,6 +71,24 @@ namespace sprout { void swap(tuple_impl&) SPROUT_NOEXCEPT {} public: tuple_impl() = default; + template + SPROUT_CONSTEXPR explicit tuple_impl(UTypes&&... args) SPROUT_NOEXCEPT {} + SPROUT_CONSTEXPR tuple_impl(tuple_impl const&) = default; + SPROUT_CONSTEXPR tuple_impl(tuple_impl&&) = default; + template + SPROUT_CONSTEXPR tuple_impl(tuple_impl const& t) SPROUT_NOEXCEPT {} + template + SPROUT_CONSTEXPR tuple_impl(tuple_impl&& t) SPROUT_NOEXCEPT {} + tuple_impl& operator=(tuple_impl const&) = default; + tuple_impl& operator=(tuple_impl&& t) = default; + template + tuple_impl& operator=(sprout::tuples::detail::tuple_impl const&) SPROUT_NOEXCEPT { + return *this; + } + template + tuple_impl& operator=(sprout::tuples::detail::tuple_impl&&) SPROUT_NOEXCEPT { + return *this; + } }; template class tuple_impl @@ -87,7 +105,7 @@ namespace sprout { static SPROUT_CONSTEXPR Head& head(tuple_impl& t) SPROUT_NOEXCEPT { return base_type::head(t); } - static SPROUT_CONSTEXPR const Head& head(tuple_impl const& t) SPROUT_NOEXCEPT { + static SPROUT_CONSTEXPR Head const& head(tuple_impl const& t) SPROUT_NOEXCEPT { return base_type::head(t); } static SPROUT_CONSTEXPR inherited_type& tail(tuple_impl& t) SPROUT_NOEXCEPT { @@ -115,7 +133,7 @@ namespace sprout { : inherited_type(tail...) , base_type(h) {} - template::type> + template SPROUT_CONSTEXPR explicit tuple_impl(UHead&& h, UTail&&... tail) : inherited_type(sprout::forward(tail)...) , base_type(sprout::forward(h)) @@ -123,7 +141,7 @@ namespace sprout { SPROUT_CONSTEXPR tuple_impl(tuple_impl const&) = default; SPROUT_CONSTEXPR tuple_impl(tuple_impl&& t) SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_constructible::value && std::is_nothrow_move_constructible::value) - : inherited_type(std::move(tail(t))) + : inherited_type(sprout::move(tail(t))) , base_type(sprout::forward(head(t))) {} template @@ -133,9 +151,17 @@ namespace sprout { {} template SPROUT_CONSTEXPR tuple_impl(tuple_impl&& t) - : inherited_type(std::move(sprout::tuples::detail::tuple_impl::tail(t))) + : inherited_type(sprout::move(sprout::tuples::detail::tuple_impl::tail(t))) , base_type(sprout::forward(sprout::tuples::detail::tuple_impl::head(t))) {} + SPROUT_CONSTEXPR tuple_impl(tuple_impl const& t) + : inherited_type() + , base_type() + {} + SPROUT_CONSTEXPR tuple_impl(tuple_impl&& t) + : inherited_type() + , base_type() + {} tuple_impl& operator=(tuple_impl const& t) { head(*this) = head(t); tail(*this) = tail(t); @@ -145,7 +171,7 @@ namespace sprout { SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable::value && std::is_nothrow_move_assignable::value) { head(*this) = sprout::forward(head(t)); - tail(*this) = std::move(tail(t)); + tail(*this) = sprout::move(tail(t)); return *this; } template @@ -157,7 +183,15 @@ namespace sprout { template tuple_impl& operator=(sprout::tuples::detail::tuple_impl&& t) { head(*this) = sprout::forward(sprout::tuples::detail::tuple_impl::head(t)); - tail(*this) = std::move(sprout::tuples::detail::tuple_impl::tail(t)); + tail(*this) = sprout::move(sprout::tuples::detail::tuple_impl::tail(t)); + return *this; + } + tuple_impl& operator=(sprout::tuples::detail::tuple_impl const& t) { + *this = sprout::move(tuple_impl()); + return *this; + } + tuple_impl& operator=(sprout::tuples::detail::tuple_impl&& t) { + *this = sprout::move(tuple_impl()); return *this; } }; @@ -180,17 +214,17 @@ namespace sprout { SPROUT_CONSTEXPR explicit tuple(Types const&... elements) : inherited_type(elements...) {} - template::type> + template SPROUT_CONSTEXPR explicit tuple(UTypes&&... elements) : inherited_type(sprout::forward(elements)...) {} SPROUT_CONSTEXPR tuple(tuple const &) = default; SPROUT_CONSTEXPR tuple(tuple&&) = default; - template::type> + template SPROUT_CONSTEXPR tuple(sprout::tuples::tuple const& t) : inherited_type(static_cast const&>(t)) {} - template::type> + template SPROUT_CONSTEXPR tuple(sprout::tuples::tuple&& t) : inherited_type(static_cast&&>(t)) {} @@ -200,17 +234,17 @@ namespace sprout { return *this; } tuple& operator=(tuple&& rhs) SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable::value) { - static_cast(*this) = std::move(rhs); + static_cast(*this) = sprout::move(rhs); return *this; } - template::type> + template tuple& operator=(sprout::tuples::tuple const& rhs) { static_cast(*this) = rhs; return *this; } - template::type> + template tuple& operator=(sprout::tuples::tuple&& rhs) { - static_cast(*this) = std::move(rhs); + static_cast(*this) = sprout::move(rhs); return *this; } // tuple swap diff --git a/sprout/utility.hpp b/sprout/utility.hpp index 7de2faff..552b8f9e 100644 --- a/sprout/utility.hpp +++ b/sprout/utility.hpp @@ -2,6 +2,6 @@ #define SPROUT_UTILITY_HPP #include -#include +#include #endif // #ifndef SPROUT_UTILITY_HPP diff --git a/sprout/utility/forward.hpp b/sprout/utility/forward.hpp index 6ab573b1..3a9e87bf 100644 --- a/sprout/utility/forward.hpp +++ b/sprout/utility/forward.hpp @@ -17,4 +17,3 @@ namespace sprout { } // namespace sprout #endif // #ifndef SPROUT_UTILITY_FORWARD_HPP - diff --git a/sprout/utility/move.hpp b/sprout/utility/move.hpp new file mode 100644 index 00000000..d965fb7a --- /dev/null +++ b/sprout/utility/move.hpp @@ -0,0 +1,17 @@ +#ifndef SPROUT_UTILITY_MOVE_HPP +#define SPROUT_UTILITY_MOVE_HPP + +#include +#include + +namespace sprout { + // + // move + // + template + SPROUT_CONSTEXPR typename std::remove_reference::type&& move(T&& t) SPROUT_NOEXCEPT { + return static_cast::type&&>(t); + } +} // namespace sprout + +#endif // #ifndef SPROUT_UTILITY_MOVE_HPP diff --git a/sprout/utility/operation.hpp b/sprout/utility/operation.hpp new file mode 100644 index 00000000..df6e1d40 --- /dev/null +++ b/sprout/utility/operation.hpp @@ -0,0 +1,8 @@ +#ifndef SPROUT_UTILITY_OPERATION_HPP +#define SPROUT_UTILITY_OPERATION_HPP + +#include +#include +#include + +#endif // #ifndef SPROUT_UTILITY_OPERATION_HPP