From 37e5f52e4ce540cfff25b36de06144c545461495 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 30 Nov 2013 10:22:24 +0900 Subject: [PATCH] refix tuple_element roder --- sprout/type.hpp | 1 + sprout/type/type_tuple.hpp | 111 +++++++++++++++++++++++++--------- sprout/type/uniform_types.hpp | 82 +++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 30 deletions(-) create mode 100644 sprout/type/uniform_types.hpp diff --git a/sprout/type.hpp b/sprout/type.hpp index 2a908223..6527f3a1 100644 --- a/sprout/type.hpp +++ b/sprout/type.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/sprout/type/type_tuple.hpp b/sprout/type/type_tuple.hpp index c1a35962..71170fbb 100644 --- a/sprout/type/type_tuple.hpp +++ b/sprout/type/type_tuple.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -51,41 +52,91 @@ namespace sprout { namespace detail { template - struct tuple_head; + struct head_element; template - struct tuple_head > + struct head_element > : public sprout::identity {}; - template - struct tuple_skip; - template - struct tuple_skip< - I, N, sprout::types::type_tuple, - typename std::enable_if<(I == 0)>::type - > - : public sprout::identity > + template + struct tuple_head; + template + struct tuple_head > + : public sprout::identity > {}; - template - struct tuple_skip< - I, N, sprout::types::type_tuple, - typename std::enable_if<(I != 0 && I < N / 2)>::type - > - : public sprout::types::detail::tuple_skip< - I - 1, N / 2 - 1, - sprout::types::type_tuple - > + + template + struct tuple_tail; + template + struct tuple_tail > + : public sprout::identity > {}; - template - struct tuple_skip< - I, N, sprout::types::type_tuple, - typename std::enable_if<(I != 0 && I >= N / 2)>::type - > - : public sprout::types::detail::tuple_skip< - I - N / 2, N - N / 2, - typename sprout::types::detail::tuple_skip >::type - > + + template + struct dummy_index + : sprout::identity {}; + + template + struct tuple_drop_helper; + template + struct tuple_drop_helper > { + template + static sprout::types::type_tuple + eval(typename sprout::types::detail::dummy_index::type*..., Types*...); + }; + template + struct tuple_drop_impl; + template + struct tuple_drop_impl > + : public sprout::identity::type>::eval( + static_cast*>(0)... + ) + )>::type + {}; + template + struct tuple_drop; + template + struct tuple_drop > + : public sprout::types::detail::tuple_drop_impl > + {}; + +// template +// struct tuple_drop_impl; +// template +// struct tuple_drop_impl< +// I, N, sprout::types::type_tuple, +// typename std::enable_if<(I == 0)>::type +// > +// : public sprout::identity > +// {}; +// template +// struct tuple_drop_impl< +// I, N, sprout::types::type_tuple, +// typename std::enable_if<(I != 0 && I < N / 2)>::type +// > +// : public sprout::types::detail::tuple_drop_impl< +// I - 1, N / 2 - 1, +// sprout::types::type_tuple +// > +// {}; +// template +// struct tuple_drop_impl< +// I, N, sprout::types::type_tuple, +// typename std::enable_if<(I != 0 && I >= N / 2)>::type +// > +// : public sprout::types::detail::tuple_drop_impl< +// I - N / 2, N - N / 2, +// typename sprout::types::detail::tuple_drop_impl >::type +// > +// {}; +// template +// struct tuple_drop; +// template +// struct tuple_drop > +// : public sprout::types::detail::tuple_drop_impl > +// {}; } // namespace detail } // namespace types @@ -111,8 +162,8 @@ namespace std { // template struct tuple_element > - : public sprout::types::detail::tuple_head< - typename sprout::types::detail::tuple_skip >::type + : public sprout::types::detail::head_element< + typename sprout::types::detail::tuple_drop >::type > {}; #if defined(__clang__) diff --git a/sprout/type/uniform_types.hpp b/sprout/type/uniform_types.hpp new file mode 100644 index 00000000..7a710fe5 --- /dev/null +++ b/sprout/type/uniform_types.hpp @@ -0,0 +1,82 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ +#ifndef SPROUT_TYPE_UNIFORM_TYPES_HPP +#define SPROUT_TYPE_UNIFORM_TYPES_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout { + namespace types { + // + // uniform_types + // + template + struct uniform_types { + public: + typedef uniform_types type; + typedef sprout::types::index_iterator begin; + typedef sprout::types::index_iterator end; + public: + SPROUT_STATIC_CONSTEXPR std::size_t static_size = N; + }; + template + SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::types::uniform_types::static_size; + + // + // rebind_types + // + template + struct rebind_types > { + public: + template + struct apply { + public: + typedef sprout::types::uniform_types type; + }; + }; + } // namespace types + + using sprout::types::uniform_types; + using sprout::types::rebind_types; +} // namespace sprout + +namespace std { +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wmismatched-tags" +#endif + // + // tuple_size + // + template + struct tuple_size > + : public sprout::integral_constant + {}; + + // + // tuple_element + // + template + struct tuple_element > { + static_assert(I < N, "tuple_element<>: index out of range"); + public: + typedef T type; + }; +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +} // namespace std + +#endif // #ifndef SPROUT_TYPE_UNIFORM_TYPES_HPP