mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix random_result for generator concept
This commit is contained in:
parent
aec15c55a8
commit
ebadf4fa7c
4 changed files with 53 additions and 37 deletions
|
@ -8,6 +8,8 @@
|
|||
#include <sprout/tuple/tuple/get.hpp>
|
||||
|
||||
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<typename T>
|
||||
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<U>()))
|
||||
typename = decltype(get<0>(std::declval<U>()))
|
||||
>
|
||||
static std::true_type test(int);
|
||||
static std::false_type test(...);
|
||||
};
|
||||
template<typename T>
|
||||
struct has_tuple_get_generated_value
|
||||
: public decltype(sprout_generator_detail::has_tuple_get_generated_value_test<T>::test(0))
|
||||
struct has_get_generated_value
|
||||
: public decltype(sprout_generator_detail::has_get_generated_value_test<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
|
@ -100,12 +102,12 @@ namespace sprout_generator_detail {
|
|||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_tuple_get_generated_value;
|
||||
struct select_get_generated_value;
|
||||
template<typename T>
|
||||
struct select_tuple_get_generated_value<
|
||||
struct select_get_generated_value<
|
||||
T,
|
||||
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_adl_generated_value<T>::value
|
||||
>::type
|
||||
|
@ -113,10 +115,10 @@ namespace sprout_generator_detail {
|
|||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct select_tuple_get_generated_value<
|
||||
struct select_get_generated_value<
|
||||
T,
|
||||
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_adl_generated_value<T>::value
|
||||
)>::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)>
|
||||
{};
|
||||
template<typename T>
|
||||
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_tuple_get_generated_value<T>::value>::type>
|
||||
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(sprout::tuples::get<0>(std::declval<T>()), false)>
|
||||
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(get<0>(std::declval<T>()), false)>
|
||||
{};
|
||||
|
||||
template<typename T, typename = void>
|
||||
|
@ -152,9 +154,9 @@ namespace sprout_generator_detail {
|
|||
typedef decltype(generated_value(std::declval<T>())) type;
|
||||
};
|
||||
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:
|
||||
typedef decltype(sprout::tuples::get<0>(std::declval<T>())) type;
|
||||
typedef decltype(get<0>(std::declval<T>())) type;
|
||||
};
|
||||
|
||||
template<
|
||||
|
@ -179,13 +181,13 @@ namespace sprout_generator_detail {
|
|||
}
|
||||
template<
|
||||
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
|
||||
generated_value_impl(T&& t)
|
||||
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
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <sprout/tuple/tuple/get.hpp>
|
||||
|
||||
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<typename T>
|
||||
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<U>()))
|
||||
typename = decltype(get<1>(std::declval<U>()))
|
||||
>
|
||||
static std::true_type test(int);
|
||||
static std::false_type test(...);
|
||||
};
|
||||
template<typename T>
|
||||
struct has_tuple_get_next_generator
|
||||
: public decltype(sprout_generator_detail::has_tuple_get_next_generator_test<T>::test(0))
|
||||
struct has_get_next_generator
|
||||
: public decltype(sprout_generator_detail::has_get_next_generator_test<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
|
@ -100,12 +102,12 @@ namespace sprout_generator_detail {
|
|||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_tuple_get_next_generator;
|
||||
struct select_get_next_generator;
|
||||
template<typename T>
|
||||
struct select_tuple_get_next_generator<
|
||||
struct select_get_next_generator<
|
||||
T,
|
||||
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_adl_next_generator<T>::value
|
||||
>::type
|
||||
|
@ -113,10 +115,10 @@ namespace sprout_generator_detail {
|
|||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct select_tuple_get_next_generator<
|
||||
struct select_get_next_generator<
|
||||
T,
|
||||
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_adl_next_generator<T>::value
|
||||
)>::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)>
|
||||
{};
|
||||
template<typename T>
|
||||
struct noexcept_next_generator<T, typename std::enable_if<sprout_generator_detail::select_tuple_get_next_generator<T>::value>::type>
|
||||
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(sprout::tuples::get<1>(std::declval<T>()), false)>
|
||||
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(get<1>(std::declval<T>()), false)>
|
||||
{};
|
||||
|
||||
template<typename T, typename = void>
|
||||
|
@ -152,9 +154,9 @@ namespace sprout_generator_detail {
|
|||
typedef decltype(next_generator(std::declval<T>())) type;
|
||||
};
|
||||
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:
|
||||
typedef decltype(sprout::tuples::get<1>(std::declval<T>())) type;
|
||||
typedef decltype(get<1>(std::declval<T>())) type;
|
||||
};
|
||||
|
||||
template<
|
||||
|
@ -179,13 +181,13 @@ namespace sprout_generator_detail {
|
|||
}
|
||||
template<
|
||||
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
|
||||
next_generator_impl(T&& t)
|
||||
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
|
||||
|
||||
|
|
|
@ -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<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) {
|
||||
return t.next_generator();
|
||||
}
|
||||
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) {
|
||||
return t.next_generator();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue