From 9069a110e9ba9812b1f9655051ecd46c3a380eab Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Wed, 18 Jul 2012 22:15:59 +0900 Subject: [PATCH] fix tuple/fused --- sprout/tuple/fused.hpp | 42 ++++++---- sprout/type/iterator/index_iterator.hpp | 100 ------------------------ 2 files changed, 28 insertions(+), 114 deletions(-) diff --git a/sprout/tuple/fused.hpp b/sprout/tuple/fused.hpp index 054de1ea..29fcb48c 100644 --- a/sprout/tuple/fused.hpp +++ b/sprout/tuple/fused.hpp @@ -1,6 +1,7 @@ #ifndef SPROUT_TUPLE_FUSED_HPP #define SPROUT_TUPLE_FUSED_HPP +#include #include #include #include @@ -16,14 +17,32 @@ namespace sprout { class fused { public: typedef F functor_type; + private: + template + struct result_impl; + template + struct result_impl > { + public: + typedef decltype( + std::declval()( + sprout::tuples::get(std::declval())... + ) + ) type; + }; + public: + template + struct result + : public result_impl< + Tuple, + typename sprout::index_range<0, sprout::tuples::tuple_size::type>::value>::type + > + {}; private: functor_type f_; private: - template - SPROUT_CONSTEXPR auto - call(Tuple&& t, sprout::index_tuple) const - -> decltype(f_(sprout::tuples::get(sprout::forward(t))...)) - { + template + SPROUT_CONSTEXPR Result + call(Tuple&& t, sprout::index_tuple) const { return f_(sprout::tuples::get(sprout::forward(t))...); } public: @@ -36,16 +55,11 @@ namespace sprout { return f_; } template - SPROUT_CONSTEXPR auto - operator()(Tuple&& t) const - -> decltype(this->call( + SPROUT_CONSTEXPR typename result::type + operator()(Tuple&& t) const { + return call::type>( sprout::forward(t), - sprout::index_range<0, sprout::tuples::tuple_size::type>::value>::make() - )) - { - return call( - sprout::forward(t), - sprout::index_range<0, sprout::tuples::tuple_size::type>::value>::make() + sprout::index_range<0, sprout::tuples::tuple_size::type>::value>::make() ); } }; diff --git a/sprout/type/iterator/index_iterator.hpp b/sprout/type/iterator/index_iterator.hpp index ad6f3d7d..6f3bcacd 100644 --- a/sprout/type/iterator/index_iterator.hpp +++ b/sprout/type/iterator/index_iterator.hpp @@ -9,109 +9,9 @@ namespace sprout { namespace types { -// template -// struct index_iterator; -// -// namespace detail { -// // -// // index_iterator_impl -// // -// template -// struct index_iterator_impl; -// template -// struct index_iterator_impl< -// Tuple, -// Index, -// typename std::enable_if< -// sprout::types::tuple_size::value == 0 -// || (Index < 0) -// || (Index > sprout::types::tuple_size::value) -// >::type -// > { -// public: -// typedef sprout::types::void_ type; -// typedef sprout::types::void_ next; -// typedef sprout::types::void_ prev; -// public: -// template -// struct advance { -// public: -// typedef sprout::types::index_iterator type; -// }; -// }; -// template -// struct index_iterator_impl< -// Tuple, -// Index, -// typename std::enable_if< -// sprout::types::tuple_size::value != 0 -// && Index == 0 -// >::type -// > { -// public: -// typedef typename sprout::types::tuple_element::type type; -// typedef sprout::types::index_iterator next; -// typedef sprout::types::void_ prev; -// public: -// template -// struct advance { -// public: -// typedef sprout::types::index_iterator type; -// }; -// }; -// template -// struct index_iterator_impl< -// Tuple, -// Index, -// typename std::enable_if< -// sprout::types::tuple_size::value != 0 -// && Index == sprout::types::tuple_size::value -// >::type -// > { -// public: -// typedef sprout::types::void_ type; -// typedef sprout::types::void_ next; -// typedef sprout::types::index_iterator::value - 1> prev; -// public: -// template -// struct advance { -// public: -// typedef sprout::types::index_iterator type; -// }; -// }; -// template -// struct index_iterator_impl< -// Tuple, -// Index, -// typename std::enable_if< -// sprout::types::tuple_size::value != 0 -// && (Index > 0) -// && (Index < sprout::types::tuple_size::value) -// >::type -// > { -// public: -// typedef typename sprout::types::tuple_element::type type; -// typedef sprout::types::index_iterator next; -// typedef sprout::types::index_iterator prev; -// public: -// template -// struct advance { -// public: -// typedef sprout::types::index_iterator type; -// }; -// }; -// } // namespace detail // // index_iterator // -// template -// struct index_iterator -// : public sprout::types::detail::index_iterator_impl -// , public std::integral_constant -// { -// public: -// typedef typename sprout::types::detail::index_iterator_impl::type type; -// }; template struct index_iterator : public std::integral_constant