From 871f9179c404153a533e5e83e4dcaefd85604d25 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 31 Oct 2011 20:10:07 +0900 Subject: [PATCH] =?UTF-8?q?sprout/tuple/sscrisk/cel/utility.hpp=20?= =?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/array.hpp | 2 + sprout/tuple/sscrisk/cel/array.hpp | 2 + sprout/tuple/sscrisk/cel/utility.hpp | 98 ++++++++++++++++++++++++++++ sprout/tuple/string.hpp | 2 + sprout/tuple/tuple.hpp | 25 ++++--- sprout/tuple/uuid.hpp | 2 + 6 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 sprout/tuple/sscrisk/cel/utility.hpp diff --git a/sprout/tuple/array.hpp b/sprout/tuple/array.hpp index 102f6852..b514e5e1 100644 --- a/sprout/tuple/array.hpp +++ b/sprout/tuple/array.hpp @@ -27,6 +27,8 @@ namespace sprout { return std::move(sprout::tuples::get(t)); } } // namespace tuples + + using sprout::tuples::get; } // namespace sprout #endif // #ifndef SPROUT_TUPLE_TUPLE_COMPARISON_HPP diff --git a/sprout/tuple/sscrisk/cel/array.hpp b/sprout/tuple/sscrisk/cel/array.hpp index 1cf94747..018eec1b 100644 --- a/sprout/tuple/sscrisk/cel/array.hpp +++ b/sprout/tuple/sscrisk/cel/array.hpp @@ -27,6 +27,8 @@ namespace sprout { return std::move(sprout::tuples::get(t)); } } // namespace tuples + + using sprout::tuples::get; } // namespace sprout #endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_ARRAY_HPP diff --git a/sprout/tuple/sscrisk/cel/utility.hpp b/sprout/tuple/sscrisk/cel/utility.hpp new file mode 100644 index 00000000..d02cd0fe --- /dev/null +++ b/sprout/tuple/sscrisk/cel/utility.hpp @@ -0,0 +1,98 @@ +#ifndef SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP +#define SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + namespace tuples { + // + // tuple_size + // + template + struct tuple_size > + : public std::integral_constant + {}; + + // + // tuple_element + // + namespace detail { + template + struct tuple_element_impl; + template + struct tuple_element_impl<0, sscrisk::cel::pair > { + public: + typedef T1 type; + }; + template + struct tuple_element_impl<1, sscrisk::cel::pair > { + public: + typedef T2 type; + }; + } // namespace detail + template + struct tuple_element > + : public sprout::tuples::detail::tuple_element_impl > + {}; + + // + // get + // + namespace detail { + template + struct get_impl; + template + struct get_impl<0, sscrisk::cel::pair > { + public: + T1& operator()(sscrisk::cel::pair& t) const { + return t.first; + } + T1 const& operator()(sscrisk::cel::pair const& t) const { + return t.first; + } + }; + template + struct get_impl<1, sscrisk::cel::pair > { + public: + public: + T2& operator()(sscrisk::cel::pair& t) const { + return t.second; + } + T2 const& operator()(sscrisk::cel::pair const& t) const { + return t.second; + } + }; + } // namespace detail + template + typename sprout::tuples::tuple_element >::type& get( + sscrisk::cel::pair& t + ) SPROUT_NOEXCEPT + { + static_assert(I < 2, "get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& get( + sscrisk::cel::pair const& t + ) SPROUT_NOEXCEPT + { + static_assert(I < 2, "get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + typename sprout::tuples::tuple_element >::type&& get( + sscrisk::cel::pair&& t + ) SPROUT_NOEXCEPT + { + return std::move(sprout::tuples::get(t)); + } + } // namespace tuples + + using sprout::tuples::get; +} // namespace sprout + +#endif // #ifndef SPROUT_TUPLE_SSCRISK_CEL_UTILITY_HPP diff --git a/sprout/tuple/string.hpp b/sprout/tuple/string.hpp index 9f49315f..a0d599ae 100644 --- a/sprout/tuple/string.hpp +++ b/sprout/tuple/string.hpp @@ -27,6 +27,8 @@ namespace sprout { return std::move(sprout::tuples::get(t)); } } // namespace tuples + + using sprout::tuples::get; } // namespace sprout #endif // #ifndef SPROUT_TUPLE_STRING_HPP diff --git a/sprout/tuple/tuple.hpp b/sprout/tuple/tuple.hpp index 3441cf0d..d2bd9bf8 100644 --- a/sprout/tuple/tuple.hpp +++ b/sprout/tuple/tuple.hpp @@ -261,6 +261,18 @@ namespace sprout { return sprout::tuples::tuple(args...); } + // + // swap + // + template + inline void swap( + sprout::tuples::tuple& lhs, + sprout::tuples::tuple& rhs + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) + { + lhs.swap(rhs); + } + namespace detail { template struct tuple_element_impl; @@ -281,6 +293,7 @@ namespace sprout { using sprout::tuples::make_tuple; using sprout::tuples::forward_as_tuple; using sprout::tuples::tie; + using sprout::tuples::swap; } // namespace sprout namespace std { @@ -325,7 +338,8 @@ namespace sprout { template SPROUT_CONSTEXPR auto get( T&& t - ) SPROUT_NOEXCEPT -> decltype(std::get(sprout::forward(t))) + ) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::get(sprout::forward(t)))) + -> decltype(std::get(sprout::forward(t))) { return std::get(sprout::forward(t)); } @@ -371,20 +385,11 @@ namespace sprout { { return sprout::tuples::detail::get_helper(t); } - - // - // swap - // - template - inline void swap(tuple& lhs, tuple& rhs) SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs))) { - lhs.swap(rhs); - } } // namespace tuples using sprout::tuples::tuple_size; using sprout::tuples::tuple_element; using sprout::tuples::get; - using sprout::tuples::swap; } // namespace sprout #endif // #ifndef SPROUT_TUPLE_TUPLE_HPP diff --git a/sprout/tuple/uuid.hpp b/sprout/tuple/uuid.hpp index e6800159..2a43d1b5 100644 --- a/sprout/tuple/uuid.hpp +++ b/sprout/tuple/uuid.hpp @@ -27,6 +27,8 @@ namespace sprout { return std::move(std::get(t)); } } // namespace tuples + + using sprout::tuples::get; } // namespace sprout #endif // #ifndef SPROUT_TUPLE_UUID_HPP