From f461643582b348120f7b1353721169e45947c0e3 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Mon, 22 Apr 2013 14:51:38 +0900 Subject: [PATCH] tuple support: random_result --- sprout/index_tuple/integer_range.hpp | 2 +- sprout/random/random_result.hpp | 96 ++++++++++++++++++++++++++++ sprout/tuple/sscrisk/cel/utility.hpp | 1 - sprout/tuple/std/utility.hpp | 1 - 4 files changed, 97 insertions(+), 3 deletions(-) diff --git a/sprout/index_tuple/integer_range.hpp b/sprout/index_tuple/integer_range.hpp index 3e6aaddc..42fcb34c 100644 --- a/sprout/index_tuple/integer_range.hpp +++ b/sprout/index_tuple/integer_range.hpp @@ -26,7 +26,7 @@ namespace sprout { struct integer_range_next_odd; template struct integer_range_next_odd, Next, Tail> - : public sprout::integer_seq + : public sprout::integer_seq {}; template::type Step, typename std::make_unsigned::type N, typename Enable = void> diff --git a/sprout/random/random_result.hpp b/sprout/random/random_result.hpp index e18d351a..49d0e184 100644 --- a/sprout/random/random_result.hpp +++ b/sprout/random/random_result.hpp @@ -7,8 +7,10 @@ #include #include #include +#include #include #include +#include namespace sprout { namespace random { @@ -288,6 +290,100 @@ namespace sprout { } // namespace random using sprout::random::random_result; + + namespace tuples { + namespace detail { + template + struct tuple_element_impl; + template + struct tuple_element_impl<0, sprout::random::random_result > { + public: + typedef typename sprout::random::random_result::result_type type; + }; + template + struct tuple_element_impl<1, sprout::random::random_result > { + public: + typedef sprout::random::random_result type; + }; + + template + struct get_impl; + template + struct get_impl<0, sprout::random::random_result > { + public: + SPROUT_CONSTEXPR typename sprout::random::random_result::result_type& + operator()(sprout::random::random_result& t) const { + return t.generated_value(); + } + SPROUT_CONSTEXPR typename sprout::random::random_result::result_type const& + operator()(sprout::random::random_result const& t) const { + return t.generated_value(); + } + }; + template + struct get_impl<1, sprout::random::random_result > { + public: + SPROUT_CONSTEXPR sprout::random::random_result& + operator()(sprout::random::random_result& t) const { + return t.next_generator(); + } + SPROUT_CONSTEXPR sprout::random::random_result const& + operator()(sprout::random::random_result const& t) const { + return t.next_generator(); + } + }; + } // namespace detail + } // namespace tuples +} // 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 std::integral_constant + {}; + + // + // tuple_element + // + template + struct tuple_element > + : public sprout::tuples::detail::tuple_element_impl > + {}; +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +} // namespace std + +namespace sprout { + namespace random { + // + // tuple_get + // + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type& + tuple_get(sprout::random::random_result& t) SPROUT_NOEXCEPT { + static_assert(I < 2, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type const& + tuple_get(sprout::random::random_result const& t) SPROUT_NOEXCEPT { + static_assert(I < 2, "tuple_get: index out of range"); + return sprout::tuples::detail::get_impl >()(t); + } + template + inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element >::type&& + tuple_get(sprout::random::random_result&& t) SPROUT_NOEXCEPT { + return sprout::move(sprout::tuples::get(t)); + } + } // namespace random } // namespace sprout #endif // #ifndef SPROUT_RANDOM_RANDOM_RESULT_HPP diff --git a/sprout/tuple/sscrisk/cel/utility.hpp b/sprout/tuple/sscrisk/cel/utility.hpp index c8fe1897..89ec97e2 100644 --- a/sprout/tuple/sscrisk/cel/utility.hpp +++ b/sprout/tuple/sscrisk/cel/utility.hpp @@ -55,7 +55,6 @@ namespace sprout { }; template struct get_impl<1, sscrisk::cel::pair > { - public: public: SPROUT_CONSTEXPR T2& operator()(sscrisk::cel::pair& t) const { return t.second; diff --git a/sprout/tuple/std/utility.hpp b/sprout/tuple/std/utility.hpp index d2a94678..c25fbc21 100644 --- a/sprout/tuple/std/utility.hpp +++ b/sprout/tuple/std/utility.hpp @@ -25,7 +25,6 @@ namespace sprout { }; template struct get_impl<1, std::pair > { - public: public: SPROUT_CONSTEXPR T2& operator()(std::pair& t) const { return t.second;