From b0ce004b3633e252c4e77fee3f68cac7c81b3734 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 30 Sep 2012 11:09:44 +0900 Subject: [PATCH] fix generator implementation --- sprout/adl/not_found.hpp | 2 +- sprout/generator/generated_value.hpp | 114 ++++++++++++++------------- sprout/generator/next_generator.hpp | 114 ++++++++++++++------------- 3 files changed, 119 insertions(+), 111 deletions(-) diff --git a/sprout/adl/not_found.hpp b/sprout/adl/not_found.hpp index 46fd0ce8..c33e23d5 100644 --- a/sprout/adl/not_found.hpp +++ b/sprout/adl/not_found.hpp @@ -23,7 +23,7 @@ namespace sprout { // template struct is_found_via_adl - : public std::integral_constant::value> + : public std::integral_constant::value> {}; } // namespace sprout diff --git a/sprout/generator/generated_value.hpp b/sprout/generator/generated_value.hpp index deff3b2b..914c42df 100644 --- a/sprout/generator/generated_value.hpp +++ b/sprout/generator/generated_value.hpp @@ -16,21 +16,6 @@ namespace sprout_generator_detail { using sprout::tuples::get; using sprout_adl::generated_value; - template - struct has_mem_generated_value_test { - public: - template< - typename U = T, - typename = decltype(std::declval().generated_value()) - > - static std::true_type test(int); - static std::false_type test(...); - }; - template - struct has_mem_generated_value - : public decltype(sprout_generator_detail::has_mem_generated_value_test::test(0)) - {}; - template struct has_adl_generated_value_test { public: @@ -48,6 +33,21 @@ namespace sprout_generator_detail { : public decltype(sprout_generator_detail::has_adl_generated_value_test::test(0)) {}; + template + struct has_mem_generated_value_test { + public: + template< + typename U = T, + typename = decltype(std::declval().generated_value()) + > + static std::true_type test(int); + static std::false_type test(...); + }; + template + struct has_mem_generated_value + : public decltype(sprout_generator_detail::has_mem_generated_value_test::test(0)) + {}; + template struct has_get_generated_value_test { public: @@ -63,23 +63,6 @@ namespace sprout_generator_detail { : public decltype(sprout_generator_detail::has_get_generated_value_test::test(0)) {}; - template - struct select_mem_generated_value; - template - struct select_mem_generated_value< - T, - typename std::enable_if::value>::type - > - : public std::true_type - {}; - template - struct select_mem_generated_value< - T, - typename std::enable_if::value>::type - > - : public std::false_type - {}; - template struct select_adl_generated_value; template @@ -87,7 +70,6 @@ namespace sprout_generator_detail { T, typename std::enable_if< sprout_generator_detail::has_adl_generated_value::value - && !sprout_generator_detail::has_mem_generated_value::value >::type > : public std::true_type @@ -97,7 +79,29 @@ namespace sprout_generator_detail { T, typename std::enable_if::value - && !sprout_generator_detail::has_mem_generated_value::value + )>::type + > + : public std::false_type + {}; + + template + struct select_mem_generated_value; + template + struct select_mem_generated_value< + T, + typename std::enable_if< + sprout_generator_detail::has_mem_generated_value::value + && !sprout_generator_detail::has_adl_generated_value::value + >::type + > + : public std::true_type + {}; + template + struct select_mem_generated_value< + T, + typename std::enable_if::value + && !sprout_generator_detail::has_adl_generated_value::value )>::type > : public std::false_type @@ -110,8 +114,8 @@ namespace sprout_generator_detail { T, typename std::enable_if< sprout_generator_detail::has_get_generated_value::value - && !sprout_generator_detail::has_mem_generated_value::value && !sprout_generator_detail::has_adl_generated_value::value + && !sprout_generator_detail::has_mem_generated_value::value >::type > : public std::true_type @@ -121,8 +125,8 @@ namespace sprout_generator_detail { T, typename std::enable_if::value - && !sprout_generator_detail::has_mem_generated_value::value && !sprout_generator_detail::has_adl_generated_value::value + && !sprout_generator_detail::has_mem_generated_value::value )>::type > : public std::false_type @@ -131,14 +135,14 @@ namespace sprout_generator_detail { template struct noexcept_generated_value; template - struct noexcept_generated_value::value>::type> - : public std::integral_constant().generated_value(), false)> - {}; - template struct noexcept_generated_value::value>::type> : public std::integral_constant()), false)> {}; template + struct noexcept_generated_value::value>::type> + : public std::integral_constant().generated_value(), false)> + {}; + template struct noexcept_generated_value::value>::type> : public std::integral_constant(std::declval()), false)> {}; @@ -146,31 +150,21 @@ namespace sprout_generator_detail { template struct generated_value_result; template - struct generated_value_result::value>::type> { - public: - typedef decltype(std::declval().generated_value()) type; - }; - template struct generated_value_result::value>::type> { public: typedef decltype(generated_value(std::declval())) type; }; template + struct generated_value_result::value>::type> { + public: + typedef decltype(std::declval().generated_value()) type; + }; + template struct generated_value_result::value>::type> { public: typedef decltype(get<0>(std::declval())) type; }; - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type - generated_value_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) - { - return sprout::forward(t).generated_value(); - } template< typename T, typename sprout::enabler_if::value>::type = sprout::enabler @@ -181,6 +175,16 @@ namespace sprout_generator_detail { { return generated_value(sprout::forward(t)); } + template< + typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result::type + generated_value_impl(T&& t) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value::value)) + { + return sprout::forward(t).generated_value(); + } template< typename T, typename sprout::enabler_if::value>::type = sprout::enabler diff --git a/sprout/generator/next_generator.hpp b/sprout/generator/next_generator.hpp index 7a804183..20801a9d 100644 --- a/sprout/generator/next_generator.hpp +++ b/sprout/generator/next_generator.hpp @@ -16,21 +16,6 @@ namespace sprout_generator_detail { using sprout::tuples::get; using sprout_adl::next_generator; - template - struct has_mem_next_generator_test { - public: - template< - typename U = T, - typename = decltype(std::declval().next_generator()) - > - static std::true_type test(int); - static std::false_type test(...); - }; - template - struct has_mem_next_generator - : public decltype(sprout_generator_detail::has_mem_next_generator_test::test(0)) - {}; - template struct has_adl_next_generator_test { public: @@ -48,6 +33,21 @@ namespace sprout_generator_detail { : public decltype(sprout_generator_detail::has_adl_next_generator_test::test(0)) {}; + template + struct has_mem_next_generator_test { + public: + template< + typename U = T, + typename = decltype(std::declval().next_generator()) + > + static std::true_type test(int); + static std::false_type test(...); + }; + template + struct has_mem_next_generator + : public decltype(sprout_generator_detail::has_mem_next_generator_test::test(0)) + {}; + template struct has_get_next_generator_test { public: @@ -63,23 +63,6 @@ namespace sprout_generator_detail { : public decltype(sprout_generator_detail::has_get_next_generator_test::test(0)) {}; - template - struct select_mem_next_generator; - template - struct select_mem_next_generator< - T, - typename std::enable_if::value>::type - > - : public std::true_type - {}; - template - struct select_mem_next_generator< - T, - typename std::enable_if::value>::type - > - : public std::false_type - {}; - template struct select_adl_next_generator; template @@ -87,7 +70,6 @@ namespace sprout_generator_detail { T, typename std::enable_if< sprout_generator_detail::has_adl_next_generator::value - && !sprout_generator_detail::has_mem_next_generator::value >::type > : public std::true_type @@ -97,7 +79,29 @@ namespace sprout_generator_detail { T, typename std::enable_if::value - && !sprout_generator_detail::has_mem_next_generator::value + )>::type + > + : public std::false_type + {}; + + template + struct select_mem_next_generator; + template + struct select_mem_next_generator< + T, + typename std::enable_if< + sprout_generator_detail::has_mem_next_generator::value + && !sprout_generator_detail::has_adl_next_generator::value + >::type + > + : public std::true_type + {}; + template + struct select_mem_next_generator< + T, + typename std::enable_if::value + && !sprout_generator_detail::has_adl_next_generator::value )>::type > : public std::false_type @@ -110,8 +114,8 @@ namespace sprout_generator_detail { T, typename std::enable_if< sprout_generator_detail::has_get_next_generator::value - && !sprout_generator_detail::has_mem_next_generator::value && !sprout_generator_detail::has_adl_next_generator::value + && !sprout_generator_detail::has_mem_next_generator::value >::type > : public std::true_type @@ -121,8 +125,8 @@ namespace sprout_generator_detail { T, typename std::enable_if::value - && !sprout_generator_detail::has_mem_next_generator::value && !sprout_generator_detail::has_adl_next_generator::value + && !sprout_generator_detail::has_mem_next_generator::value )>::type > : public std::false_type @@ -131,14 +135,14 @@ namespace sprout_generator_detail { template struct noexcept_next_generator; template - struct noexcept_next_generator::value>::type> - : public std::integral_constant().next_generator(), false)> - {}; - template struct noexcept_next_generator::value>::type> : public std::integral_constant()), false)> {}; template + struct noexcept_next_generator::value>::type> + : public std::integral_constant().next_generator(), false)> + {}; + template struct noexcept_next_generator::value>::type> : public std::integral_constant(std::declval()), false)> {}; @@ -146,31 +150,21 @@ namespace sprout_generator_detail { template struct next_generator_result; template - struct next_generator_result::value>::type> { - public: - typedef decltype(std::declval().next_generator()) type; - }; - template struct next_generator_result::value>::type> { public: typedef decltype(next_generator(std::declval())) type; }; template + struct next_generator_result::value>::type> { + public: + typedef decltype(std::declval().next_generator()) type; + }; + template struct next_generator_result::value>::type> { public: typedef decltype(get<1>(std::declval())) type; }; - template< - typename T, - typename sprout::enabler_if::value>::type = sprout::enabler - > - inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type - next_generator_impl(T&& t) - SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) - { - return sprout::forward(t).next_generator(); - } template< typename T, typename sprout::enabler_if::value>::type = sprout::enabler @@ -181,6 +175,16 @@ namespace sprout_generator_detail { { return next_generator(sprout::forward(t)); } + template< + typename T, + typename sprout::enabler_if::value>::type = sprout::enabler + > + inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result::type + next_generator_impl(T&& t) + SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator::value)) + { + return sprout::forward(t).next_generator(); + } template< typename T, typename sprout::enabler_if::value>::type = sprout::enabler