fix random_result for generator concept

This commit is contained in:
bolero-MURAKAMI 2012-09-27 14:19:25 +09:00
parent aec15c55a8
commit ebadf4fa7c
4 changed files with 53 additions and 37 deletions

View file

@ -8,6 +8,8 @@
#include <sprout/tuple/tuple/get.hpp> #include <sprout/tuple/tuple/get.hpp>
namespace sprout_generator_detail { namespace sprout_generator_detail {
using sprout::tuples::get;
struct not_found_adl_generated_value {}; struct not_found_adl_generated_value {};
sprout_generator_detail::not_found_adl_generated_value generated_value(...); sprout_generator_detail::not_found_adl_generated_value generated_value(...);
@ -45,18 +47,18 @@ namespace sprout_generator_detail {
{}; {};
template<typename T> template<typename T>
struct has_tuple_get_generated_value_test { struct has_get_generated_value_test {
public: public:
template< template<
typename U = T, typename U = T,
typename = decltype(sprout::tuples::get<0>(std::declval<U>())) typename = decltype(get<0>(std::declval<U>()))
> >
static std::true_type test(int); static std::true_type test(int);
static std::false_type test(...); static std::false_type test(...);
}; };
template<typename T> template<typename T>
struct has_tuple_get_generated_value struct has_get_generated_value
: public decltype(sprout_generator_detail::has_tuple_get_generated_value_test<T>::test(0)) : public decltype(sprout_generator_detail::has_get_generated_value_test<T>::test(0))
{}; {};
template<typename T, typename Enable = void> template<typename T, typename Enable = void>
@ -100,12 +102,12 @@ namespace sprout_generator_detail {
{}; {};
template<typename T, typename Enable = void> template<typename T, typename Enable = void>
struct select_tuple_get_generated_value; struct select_get_generated_value;
template<typename T> template<typename T>
struct select_tuple_get_generated_value< struct select_get_generated_value<
T, T,
typename std::enable_if< typename std::enable_if<
sprout_generator_detail::has_tuple_get_generated_value<T>::value sprout_generator_detail::has_get_generated_value<T>::value
&& !sprout_generator_detail::has_mem_generated_value<T>::value && !sprout_generator_detail::has_mem_generated_value<T>::value
&& !sprout_generator_detail::has_adl_generated_value<T>::value && !sprout_generator_detail::has_adl_generated_value<T>::value
>::type >::type
@ -113,10 +115,10 @@ namespace sprout_generator_detail {
: public std::true_type : public std::true_type
{}; {};
template<typename T> template<typename T>
struct select_tuple_get_generated_value< struct select_get_generated_value<
T, T,
typename std::enable_if<!( typename std::enable_if<!(
sprout_generator_detail::has_tuple_get_generated_value<T>::value sprout_generator_detail::has_get_generated_value<T>::value
&& !sprout_generator_detail::has_mem_generated_value<T>::value && !sprout_generator_detail::has_mem_generated_value<T>::value
&& !sprout_generator_detail::has_adl_generated_value<T>::value && !sprout_generator_detail::has_adl_generated_value<T>::value
)>::type )>::type
@ -135,8 +137,8 @@ namespace sprout_generator_detail {
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(generated_value(std::declval<T>()), false)> : public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(generated_value(std::declval<T>()), false)>
{}; {};
template<typename T> template<typename T>
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_tuple_get_generated_value<T>::value>::type> struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_get_generated_value<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(sprout::tuples::get<0>(std::declval<T>()), false)> : public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(get<0>(std::declval<T>()), false)>
{}; {};
template<typename T, typename = void> template<typename T, typename = void>
@ -152,9 +154,9 @@ namespace sprout_generator_detail {
typedef decltype(generated_value(std::declval<T>())) type; typedef decltype(generated_value(std::declval<T>())) type;
}; };
template<typename T> template<typename T>
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_tuple_get_generated_value<T>::value>::type> { struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_get_generated_value<T>::value>::type> {
public: public:
typedef decltype(sprout::tuples::get<0>(std::declval<T>())) type; typedef decltype(get<0>(std::declval<T>())) type;
}; };
template< template<
@ -179,13 +181,13 @@ namespace sprout_generator_detail {
} }
template< template<
typename T, typename T,
typename sprout::enabler_if<sprout_generator_detail::select_tuple_get_generated_value<T>::value>::type = sprout::enabler typename sprout::enabler_if<sprout_generator_detail::select_get_generated_value<T>::value>::type = sprout::enabler
> >
inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type
generated_value_impl(T&& t) generated_value_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value)) SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value))
{ {
return sprout::tuples::get<0>(sprout::forward<T>(t)); return get<0>(sprout::forward<T>(t));
} }
} // namespace sprout_generator_detail } // namespace sprout_generator_detail

View file

@ -8,6 +8,8 @@
#include <sprout/tuple/tuple/get.hpp> #include <sprout/tuple/tuple/get.hpp>
namespace sprout_generator_detail { namespace sprout_generator_detail {
using sprout::tuples::get;
struct not_found_adl_next_generator {}; struct not_found_adl_next_generator {};
sprout_generator_detail::not_found_adl_next_generator next_generator(...); sprout_generator_detail::not_found_adl_next_generator next_generator(...);
@ -45,18 +47,18 @@ namespace sprout_generator_detail {
{}; {};
template<typename T> template<typename T>
struct has_tuple_get_next_generator_test { struct has_get_next_generator_test {
public: public:
template< template<
typename U = T, typename U = T,
typename = decltype(sprout::tuples::get<1>(std::declval<U>())) typename = decltype(get<1>(std::declval<U>()))
> >
static std::true_type test(int); static std::true_type test(int);
static std::false_type test(...); static std::false_type test(...);
}; };
template<typename T> template<typename T>
struct has_tuple_get_next_generator struct has_get_next_generator
: public decltype(sprout_generator_detail::has_tuple_get_next_generator_test<T>::test(0)) : public decltype(sprout_generator_detail::has_get_next_generator_test<T>::test(0))
{}; {};
template<typename T, typename Enable = void> template<typename T, typename Enable = void>
@ -100,12 +102,12 @@ namespace sprout_generator_detail {
{}; {};
template<typename T, typename Enable = void> template<typename T, typename Enable = void>
struct select_tuple_get_next_generator; struct select_get_next_generator;
template<typename T> template<typename T>
struct select_tuple_get_next_generator< struct select_get_next_generator<
T, T,
typename std::enable_if< typename std::enable_if<
sprout_generator_detail::has_tuple_get_next_generator<T>::value sprout_generator_detail::has_get_next_generator<T>::value
&& !sprout_generator_detail::has_mem_next_generator<T>::value && !sprout_generator_detail::has_mem_next_generator<T>::value
&& !sprout_generator_detail::has_adl_next_generator<T>::value && !sprout_generator_detail::has_adl_next_generator<T>::value
>::type >::type
@ -113,10 +115,10 @@ namespace sprout_generator_detail {
: public std::true_type : public std::true_type
{}; {};
template<typename T> template<typename T>
struct select_tuple_get_next_generator< struct select_get_next_generator<
T, T,
typename std::enable_if<!( typename std::enable_if<!(
sprout_generator_detail::has_tuple_get_next_generator<T>::value sprout_generator_detail::has_get_next_generator<T>::value
&& !sprout_generator_detail::has_mem_next_generator<T>::value && !sprout_generator_detail::has_mem_next_generator<T>::value
&& !sprout_generator_detail::has_adl_next_generator<T>::value && !sprout_generator_detail::has_adl_next_generator<T>::value
)>::type )>::type
@ -135,8 +137,8 @@ namespace sprout_generator_detail {
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(next_generator(std::declval<T>()), false)> : public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(next_generator(std::declval<T>()), false)>
{}; {};
template<typename T> template<typename T>
struct noexcept_next_generator<T, typename std::enable_if<sprout_generator_detail::select_tuple_get_next_generator<T>::value>::type> struct noexcept_next_generator<T, typename std::enable_if<sprout_generator_detail::select_get_next_generator<T>::value>::type>
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(sprout::tuples::get<1>(std::declval<T>()), false)> : public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(get<1>(std::declval<T>()), false)>
{}; {};
template<typename T, typename = void> template<typename T, typename = void>
@ -152,9 +154,9 @@ namespace sprout_generator_detail {
typedef decltype(next_generator(std::declval<T>())) type; typedef decltype(next_generator(std::declval<T>())) type;
}; };
template<typename T> template<typename T>
struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_tuple_get_next_generator<T>::value>::type> { struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_get_next_generator<T>::value>::type> {
public: public:
typedef decltype(sprout::tuples::get<1>(std::declval<T>())) type; typedef decltype(get<1>(std::declval<T>())) type;
}; };
template< template<
@ -179,13 +181,13 @@ namespace sprout_generator_detail {
} }
template< template<
typename T, typename T,
typename sprout::enabler_if<sprout_generator_detail::select_tuple_get_next_generator<T>::value>::type = sprout::enabler typename sprout::enabler_if<sprout_generator_detail::select_get_next_generator<T>::value>::type = sprout::enabler
> >
inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result<T>::type inline SPROUT_CONSTEXPR typename sprout_generator_detail::next_generator_result<T>::type
next_generator_impl(T&& t) next_generator_impl(T&& t)
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator<T>::value)) SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_next_generator<T>::value))
{ {
return sprout::tuples::get<1>(sprout::forward<T>(t)); return get<1>(sprout::forward<T>(t));
} }
} // namespace sprout_generator_detail } // namespace sprout_generator_detail

View file

@ -79,12 +79,24 @@ namespace sprout {
SPROUT_CONSTEXPR result_type const& result() const { SPROUT_CONSTEXPR result_type const& result() const {
return result_; return result_;
} }
result_type& generated_value() {
return result_;
}
SPROUT_CONSTEXPR result_type const& generated_value() const {
return result_;
}
engine_type& engine() { engine_type& engine() {
return engine_; return engine_;
} }
SPROUT_CONSTEXPR engine_type const& engine() const { SPROUT_CONSTEXPR engine_type const& engine() const {
return engine_; return engine_;
} }
random_result& next_generator() {
return *this;
}
SPROUT_CONSTEXPR random_result const& next_generator() const {
return *this;
}
distribution_type& distribution() { distribution_type& distribution() {
return distribution_; return distribution_;
} }
@ -199,11 +211,11 @@ namespace sprout {
SPROUT_CONSTEXPR engine_type const& engine() const { SPROUT_CONSTEXPR engine_type const& engine() const {
return engine_; return engine_;
} }
engine_type& next_generator() { random_result& next_generator() {
return engine_; return *this;
} }
SPROUT_CONSTEXPR engine_type const& next_generator() const { SPROUT_CONSTEXPR random_result const& next_generator() const {
return engine_; return *this;
} }
SPROUT_CONSTEXPR result_type min() const { SPROUT_CONSTEXPR result_type min() const {
return engine_.min(); return engine_.min();
@ -282,12 +294,12 @@ namespace sprout {
// next_generator // next_generator
// //
template<typename Engine, typename Distribution> template<typename Engine, typename Distribution>
inline SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution>::engine_type const& inline SPROUT_CONSTEXPR typename sprout::random::random_result<Engine, Distribution> const&
next_generator(sprout::random::random_result<Engine, Distribution> const& t) { next_generator(sprout::random::random_result<Engine, Distribution> const& t) {
return t.next_generator(); return t.next_generator();
} }
template<typename Engine, typename Distribution> template<typename Engine, typename Distribution>
inline typename sprout::random::random_result<Engine, Distribution>::engine_type& inline typename sprout::random::random_result<Engine, Distribution>&
next_generator(sprout::random::random_result<Engine, Distribution>& t) { next_generator(sprout::random::random_result<Engine, Distribution>& t) {
return t.next_generator(); return t.next_generator();
} }