From ebadf4fa7c288e6ae5b410ac2aacbd2ddb9aef52 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 27 Sep 2012 14:19:25 +0900 Subject: [PATCH] fix random_result for generator concept --- sprout/generator/generated_value.hpp | 32 +++++++++++++++------------- sprout/generator/next_generator.hpp | 32 +++++++++++++++------------- sprout/iterator/filter_iterator.hpp | 2 +- sprout/random/random_result.hpp | 24 +++++++++++++++------ 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/sprout/generator/generated_value.hpp b/sprout/generator/generated_value.hpp index cfb82086..446fbc06 100644 --- a/sprout/generator/generated_value.hpp +++ b/sprout/generator/generated_value.hpp @@ -8,6 +8,8 @@ #include namespace sprout_generator_detail { + using sprout::tuples::get; + struct not_found_adl_generated_value {}; sprout_generator_detail::not_found_adl_generated_value generated_value(...); @@ -45,18 +47,18 @@ namespace sprout_generator_detail { {}; template - struct has_tuple_get_generated_value_test { + struct has_get_generated_value_test { public: template< typename U = T, - typename = decltype(sprout::tuples::get<0>(std::declval())) + typename = decltype(get<0>(std::declval())) > static std::true_type test(int); static std::false_type test(...); }; template - struct has_tuple_get_generated_value - : public decltype(sprout_generator_detail::has_tuple_get_generated_value_test::test(0)) + struct has_get_generated_value + : public decltype(sprout_generator_detail::has_get_generated_value_test::test(0)) {}; template @@ -100,12 +102,12 @@ namespace sprout_generator_detail { {}; template - struct select_tuple_get_generated_value; + struct select_get_generated_value; template - struct select_tuple_get_generated_value< + struct select_get_generated_value< T, typename std::enable_if< - sprout_generator_detail::has_tuple_get_generated_value::value + sprout_generator_detail::has_get_generated_value::value && !sprout_generator_detail::has_mem_generated_value::value && !sprout_generator_detail::has_adl_generated_value::value >::type @@ -113,10 +115,10 @@ namespace sprout_generator_detail { : public std::true_type {}; template - struct select_tuple_get_generated_value< + struct select_get_generated_value< T, typename std::enable_if::value + sprout_generator_detail::has_get_generated_value::value && !sprout_generator_detail::has_mem_generated_value::value && !sprout_generator_detail::has_adl_generated_value::value )>::type @@ -135,8 +137,8 @@ namespace sprout_generator_detail { : public std::integral_constant()), false)> {}; template - struct noexcept_generated_value::value>::type> - : public std::integral_constant(std::declval()), false)> + struct noexcept_generated_value::value>::type> + : public std::integral_constant(std::declval()), false)> {}; template @@ -152,9 +154,9 @@ namespace sprout_generator_detail { typedef decltype(generated_value(std::declval())) type; }; template - struct generated_value_result::value>::type> { + struct generated_value_result::value>::type> { public: - typedef decltype(sprout::tuples::get<0>(std::declval())) type; + typedef decltype(get<0>(std::declval())) type; }; template< @@ -179,13 +181,13 @@ namespace sprout_generator_detail { } template< typename T, - typename sprout::enabler_if::value>::type = sprout::enabler + 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::tuples::get<0>(sprout::forward(t)); + return get<0>(sprout::forward(t)); } } // namespace sprout_generator_detail diff --git a/sprout/generator/next_generator.hpp b/sprout/generator/next_generator.hpp index fcefd395..d5f8a13d 100644 --- a/sprout/generator/next_generator.hpp +++ b/sprout/generator/next_generator.hpp @@ -8,6 +8,8 @@ #include namespace sprout_generator_detail { + using sprout::tuples::get; + struct not_found_adl_next_generator {}; sprout_generator_detail::not_found_adl_next_generator next_generator(...); @@ -45,18 +47,18 @@ namespace sprout_generator_detail { {}; template - struct has_tuple_get_next_generator_test { + struct has_get_next_generator_test { public: template< typename U = T, - typename = decltype(sprout::tuples::get<1>(std::declval())) + typename = decltype(get<1>(std::declval())) > static std::true_type test(int); static std::false_type test(...); }; template - struct has_tuple_get_next_generator - : public decltype(sprout_generator_detail::has_tuple_get_next_generator_test::test(0)) + struct has_get_next_generator + : public decltype(sprout_generator_detail::has_get_next_generator_test::test(0)) {}; template @@ -100,12 +102,12 @@ namespace sprout_generator_detail { {}; template - struct select_tuple_get_next_generator; + struct select_get_next_generator; template - struct select_tuple_get_next_generator< + struct select_get_next_generator< T, typename std::enable_if< - sprout_generator_detail::has_tuple_get_next_generator::value + sprout_generator_detail::has_get_next_generator::value && !sprout_generator_detail::has_mem_next_generator::value && !sprout_generator_detail::has_adl_next_generator::value >::type @@ -113,10 +115,10 @@ namespace sprout_generator_detail { : public std::true_type {}; template - struct select_tuple_get_next_generator< + struct select_get_next_generator< T, typename std::enable_if::value + sprout_generator_detail::has_get_next_generator::value && !sprout_generator_detail::has_mem_next_generator::value && !sprout_generator_detail::has_adl_next_generator::value )>::type @@ -135,8 +137,8 @@ namespace sprout_generator_detail { : public std::integral_constant()), false)> {}; template - struct noexcept_next_generator::value>::type> - : public std::integral_constant(std::declval()), false)> + struct noexcept_next_generator::value>::type> + : public std::integral_constant(std::declval()), false)> {}; template @@ -152,9 +154,9 @@ namespace sprout_generator_detail { typedef decltype(next_generator(std::declval())) type; }; template - struct next_generator_result::value>::type> { + struct next_generator_result::value>::type> { public: - typedef decltype(sprout::tuples::get<1>(std::declval())) type; + typedef decltype(get<1>(std::declval())) type; }; template< @@ -179,13 +181,13 @@ namespace sprout_generator_detail { } template< typename T, - typename sprout::enabler_if::value>::type = sprout::enabler + 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::tuples::get<1>(sprout::forward(t)); + return get<1>(sprout::forward(t)); } } // namespace sprout_generator_detail diff --git a/sprout/iterator/filter_iterator.hpp b/sprout/iterator/filter_iterator.hpp index 738e85d5..44d5c50a 100644 --- a/sprout/iterator/filter_iterator.hpp +++ b/sprout/iterator/filter_iterator.hpp @@ -70,7 +70,7 @@ namespace sprout { , last(last) , pred(pred) {} - public: + public: filter_iterator() = default; filter_iterator(filter_iterator const&) = default; SPROUT_CONSTEXPR filter_iterator(predicate_type pred, iterator_type it, iterator_type last = iterator_type()) diff --git a/sprout/random/random_result.hpp b/sprout/random/random_result.hpp index 7c5f66e3..3fb21266 100644 --- a/sprout/random/random_result.hpp +++ b/sprout/random/random_result.hpp @@ -79,12 +79,24 @@ namespace sprout { SPROUT_CONSTEXPR result_type const& result() const { return result_; } + result_type& generated_value() { + return result_; + } + SPROUT_CONSTEXPR result_type const& generated_value() const { + return result_; + } engine_type& engine() { return engine_; } SPROUT_CONSTEXPR engine_type const& engine() const { return engine_; } + random_result& next_generator() { + return *this; + } + SPROUT_CONSTEXPR random_result const& next_generator() const { + return *this; + } distribution_type& distribution() { return distribution_; } @@ -199,11 +211,11 @@ namespace sprout { SPROUT_CONSTEXPR engine_type const& engine() const { return engine_; } - engine_type& next_generator() { - return engine_; + random_result& next_generator() { + return *this; } - SPROUT_CONSTEXPR engine_type const& next_generator() const { - return engine_; + SPROUT_CONSTEXPR random_result const& next_generator() const { + return *this; } SPROUT_CONSTEXPR result_type min() const { return engine_.min(); @@ -282,12 +294,12 @@ namespace sprout { // next_generator // template - inline SPROUT_CONSTEXPR typename sprout::random::random_result::engine_type const& + inline SPROUT_CONSTEXPR typename sprout::random::random_result const& next_generator(sprout::random::random_result const& t) { return t.next_generator(); } template - inline typename sprout::random::random_result::engine_type& + inline typename sprout::random::random_result& next_generator(sprout::random::random_result& t) { return t.next_generator(); }