From 3078d76ceb5308ee6f82d640f2f3bf1456a72af7 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Tue, 28 Feb 2012 15:02:56 +0900 Subject: [PATCH] =?UTF-8?q?index=5Fn=20=E5=86=8D=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sprout/index_tuple.hpp | 72 ++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/sprout/index_tuple.hpp b/sprout/index_tuple.hpp index aacc7053..356dd0bc 100644 --- a/sprout/index_tuple.hpp +++ b/sprout/index_tuple.hpp @@ -98,32 +98,70 @@ namespace sprout { // index_n // namespace detail { - template< - sprout::index_t I, - std::size_t N, - typename Acc, - bool Break = (N == 0) - > - struct index_n_impl { + template + struct index_n_next; + template + struct index_n_next> { public: - typedef Acc type; + typedef sprout::index_tuple type; }; - template< - sprout::index_t I, - std::size_t N, - sprout::index_t... Indexes + + template + struct index_n_next2; + template + struct index_n_next2, Tail> { + public: + typedef sprout::index_tuple type; + }; + + template + struct index_n_impl; + template + struct index_n_impl< + I, + N, + typename std::enable_if<(N == 0)>::type + > { + public: + typedef sprout::index_tuple<> type; + }; + template + struct index_n_impl< + I, + N, + typename std::enable_if<(N == 1)>::type + > { + public: + typedef sprout::index_tuple type; + }; + template + struct index_n_impl< + I, + N, + typename std::enable_if<(N > 1 && N % 2 == 0)>::type > - struct index_n_impl, false> - : public sprout::detail::index_n_impl > + : public sprout::detail::index_n_next< + typename sprout::detail::index_n_impl::type + > + {}; + template + struct index_n_impl< + I, + N, + typename std::enable_if<(N > 1 && N % 2 == 1)>::type + > + : public sprout::detail::index_n_next2< + typename sprout::detail::index_n_impl::type, + I + > {}; } // namespace detail template< sprout::index_t I, - std::size_t N, - typename Acc = sprout::index_tuple<> + std::size_t N > struct index_n - : public sprout::detail::index_n_impl + : public sprout::detail::index_n_impl {}; } // namespace sprout