mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
fix generator implementation
This commit is contained in:
parent
da86582643
commit
b0ce004b36
3 changed files with 119 additions and 111 deletions
|
@ -23,7 +23,7 @@ namespace sprout {
|
|||
//
|
||||
template<typename T>
|
||||
struct is_found_via_adl
|
||||
: public std::integral_constant<bool, sprout::is_not_found_via_adl<T>::value>
|
||||
: public std::integral_constant<bool, !sprout::is_not_found_via_adl<T>::value>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -16,21 +16,6 @@ namespace sprout_generator_detail {
|
|||
using sprout::tuples::get;
|
||||
using sprout_adl::generated_value;
|
||||
|
||||
template<typename T>
|
||||
struct has_mem_generated_value_test {
|
||||
public:
|
||||
template<
|
||||
typename U = T,
|
||||
typename = decltype(std::declval<U>().generated_value())
|
||||
>
|
||||
static std::true_type test(int);
|
||||
static std::false_type test(...);
|
||||
};
|
||||
template<typename T>
|
||||
struct has_mem_generated_value
|
||||
: public decltype(sprout_generator_detail::has_mem_generated_value_test<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
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<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
struct has_mem_generated_value_test {
|
||||
public:
|
||||
template<
|
||||
typename U = T,
|
||||
typename = decltype(std::declval<U>().generated_value())
|
||||
>
|
||||
static std::true_type test(int);
|
||||
static std::false_type test(...);
|
||||
};
|
||||
template<typename T>
|
||||
struct has_mem_generated_value
|
||||
: public decltype(sprout_generator_detail::has_mem_generated_value_test<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
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<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_mem_generated_value;
|
||||
template<typename T>
|
||||
struct select_mem_generated_value<
|
||||
T,
|
||||
typename std::enable_if<sprout_generator_detail::has_mem_generated_value<T>::value>::type
|
||||
>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct select_mem_generated_value<
|
||||
T,
|
||||
typename std::enable_if<!sprout_generator_detail::has_mem_generated_value<T>::value>::type
|
||||
>
|
||||
: public std::false_type
|
||||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_adl_generated_value;
|
||||
template<typename T>
|
||||
|
@ -87,7 +70,6 @@ namespace sprout_generator_detail {
|
|||
T,
|
||||
typename std::enable_if<
|
||||
sprout_generator_detail::has_adl_generated_value<T>::value
|
||||
&& !sprout_generator_detail::has_mem_generated_value<T>::value
|
||||
>::type
|
||||
>
|
||||
: public std::true_type
|
||||
|
@ -97,7 +79,29 @@ namespace sprout_generator_detail {
|
|||
T,
|
||||
typename std::enable_if<!(
|
||||
sprout_generator_detail::has_adl_generated_value<T>::value
|
||||
&& !sprout_generator_detail::has_mem_generated_value<T>::value
|
||||
)>::type
|
||||
>
|
||||
: public std::false_type
|
||||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_mem_generated_value;
|
||||
template<typename T>
|
||||
struct select_mem_generated_value<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
sprout_generator_detail::has_mem_generated_value<T>::value
|
||||
&& !sprout_generator_detail::has_adl_generated_value<T>::value
|
||||
>::type
|
||||
>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct select_mem_generated_value<
|
||||
T,
|
||||
typename std::enable_if<!(
|
||||
sprout_generator_detail::has_mem_generated_value<T>::value
|
||||
&& !sprout_generator_detail::has_adl_generated_value<T>::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<T>::value
|
||||
&& !sprout_generator_detail::has_mem_generated_value<T>::value
|
||||
&& !sprout_generator_detail::has_adl_generated_value<T>::value
|
||||
&& !sprout_generator_detail::has_mem_generated_value<T>::value
|
||||
>::type
|
||||
>
|
||||
: public std::true_type
|
||||
|
@ -121,8 +125,8 @@ namespace sprout_generator_detail {
|
|||
T,
|
||||
typename std::enable_if<!(
|
||||
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
|
||||
&& !sprout_generator_detail::has_mem_generated_value<T>::value
|
||||
)>::type
|
||||
>
|
||||
: public std::false_type
|
||||
|
@ -131,14 +135,14 @@ namespace sprout_generator_detail {
|
|||
template<typename T, typename = void>
|
||||
struct noexcept_generated_value;
|
||||
template<typename T>
|
||||
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_mem_generated_value<T>::value>::type>
|
||||
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::declval<T>().generated_value(), false)>
|
||||
{};
|
||||
template<typename T>
|
||||
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type>
|
||||
: 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_mem_generated_value<T>::value>::type>
|
||||
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::declval<T>().generated_value(), false)>
|
||||
{};
|
||||
template<typename T>
|
||||
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)>
|
||||
{};
|
||||
|
@ -146,31 +150,21 @@ namespace sprout_generator_detail {
|
|||
template<typename T, typename = void>
|
||||
struct generated_value_result;
|
||||
template<typename T>
|
||||
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_mem_generated_value<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(std::declval<T>().generated_value()) type;
|
||||
};
|
||||
template<typename T>
|
||||
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(generated_value(std::declval<T>())) type;
|
||||
};
|
||||
template<typename T>
|
||||
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_mem_generated_value<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(std::declval<T>().generated_value()) type;
|
||||
};
|
||||
template<typename T>
|
||||
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_get_generated_value<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(get<0>(std::declval<T>())) type;
|
||||
};
|
||||
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_generator_detail::select_mem_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::forward<T>(t).generated_value();
|
||||
}
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type = sprout::enabler
|
||||
|
@ -181,6 +175,16 @@ namespace sprout_generator_detail {
|
|||
{
|
||||
return generated_value(sprout::forward<T>(t));
|
||||
}
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_generator_detail::select_mem_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::forward<T>(t).generated_value();
|
||||
}
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_generator_detail::select_get_generated_value<T>::value>::type = sprout::enabler
|
||||
|
|
|
@ -16,21 +16,6 @@ namespace sprout_generator_detail {
|
|||
using sprout::tuples::get;
|
||||
using sprout_adl::next_generator;
|
||||
|
||||
template<typename T>
|
||||
struct has_mem_next_generator_test {
|
||||
public:
|
||||
template<
|
||||
typename U = T,
|
||||
typename = decltype(std::declval<U>().next_generator())
|
||||
>
|
||||
static std::true_type test(int);
|
||||
static std::false_type test(...);
|
||||
};
|
||||
template<typename T>
|
||||
struct has_mem_next_generator
|
||||
: public decltype(sprout_generator_detail::has_mem_next_generator_test<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
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<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
struct has_mem_next_generator_test {
|
||||
public:
|
||||
template<
|
||||
typename U = T,
|
||||
typename = decltype(std::declval<U>().next_generator())
|
||||
>
|
||||
static std::true_type test(int);
|
||||
static std::false_type test(...);
|
||||
};
|
||||
template<typename T>
|
||||
struct has_mem_next_generator
|
||||
: public decltype(sprout_generator_detail::has_mem_next_generator_test<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
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<T>::test(0))
|
||||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_mem_next_generator;
|
||||
template<typename T>
|
||||
struct select_mem_next_generator<
|
||||
T,
|
||||
typename std::enable_if<sprout_generator_detail::has_mem_next_generator<T>::value>::type
|
||||
>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct select_mem_next_generator<
|
||||
T,
|
||||
typename std::enable_if<!sprout_generator_detail::has_mem_next_generator<T>::value>::type
|
||||
>
|
||||
: public std::false_type
|
||||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_adl_next_generator;
|
||||
template<typename T>
|
||||
|
@ -87,7 +70,6 @@ namespace sprout_generator_detail {
|
|||
T,
|
||||
typename std::enable_if<
|
||||
sprout_generator_detail::has_adl_next_generator<T>::value
|
||||
&& !sprout_generator_detail::has_mem_next_generator<T>::value
|
||||
>::type
|
||||
>
|
||||
: public std::true_type
|
||||
|
@ -97,7 +79,29 @@ namespace sprout_generator_detail {
|
|||
T,
|
||||
typename std::enable_if<!(
|
||||
sprout_generator_detail::has_adl_next_generator<T>::value
|
||||
&& !sprout_generator_detail::has_mem_next_generator<T>::value
|
||||
)>::type
|
||||
>
|
||||
: public std::false_type
|
||||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_mem_next_generator;
|
||||
template<typename T>
|
||||
struct select_mem_next_generator<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
sprout_generator_detail::has_mem_next_generator<T>::value
|
||||
&& !sprout_generator_detail::has_adl_next_generator<T>::value
|
||||
>::type
|
||||
>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct select_mem_next_generator<
|
||||
T,
|
||||
typename std::enable_if<!(
|
||||
sprout_generator_detail::has_mem_next_generator<T>::value
|
||||
&& !sprout_generator_detail::has_adl_next_generator<T>::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<T>::value
|
||||
&& !sprout_generator_detail::has_mem_next_generator<T>::value
|
||||
&& !sprout_generator_detail::has_adl_next_generator<T>::value
|
||||
&& !sprout_generator_detail::has_mem_next_generator<T>::value
|
||||
>::type
|
||||
>
|
||||
: public std::true_type
|
||||
|
@ -121,8 +125,8 @@ namespace sprout_generator_detail {
|
|||
T,
|
||||
typename std::enable_if<!(
|
||||
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
|
||||
&& !sprout_generator_detail::has_mem_next_generator<T>::value
|
||||
)>::type
|
||||
>
|
||||
: public std::false_type
|
||||
|
@ -131,14 +135,14 @@ namespace sprout_generator_detail {
|
|||
template<typename T, typename = void>
|
||||
struct noexcept_next_generator;
|
||||
template<typename T>
|
||||
struct noexcept_next_generator<T, typename std::enable_if<sprout_generator_detail::select_mem_next_generator<T>::value>::type>
|
||||
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::declval<T>().next_generator(), false)>
|
||||
{};
|
||||
template<typename T>
|
||||
struct noexcept_next_generator<T, typename std::enable_if<sprout_generator_detail::select_adl_next_generator<T>::value>::type>
|
||||
: 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_mem_next_generator<T>::value>::type>
|
||||
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::declval<T>().next_generator(), false)>
|
||||
{};
|
||||
template<typename T>
|
||||
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)>
|
||||
{};
|
||||
|
@ -146,31 +150,21 @@ namespace sprout_generator_detail {
|
|||
template<typename T, typename = void>
|
||||
struct next_generator_result;
|
||||
template<typename T>
|
||||
struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_mem_next_generator<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(std::declval<T>().next_generator()) type;
|
||||
};
|
||||
template<typename T>
|
||||
struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_adl_next_generator<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(next_generator(std::declval<T>())) type;
|
||||
};
|
||||
template<typename T>
|
||||
struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_mem_next_generator<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(std::declval<T>().next_generator()) type;
|
||||
};
|
||||
template<typename T>
|
||||
struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_get_next_generator<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(get<1>(std::declval<T>())) type;
|
||||
};
|
||||
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_generator_detail::select_mem_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::forward<T>(t).next_generator();
|
||||
}
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_generator_detail::select_adl_next_generator<T>::value>::type = sprout::enabler
|
||||
|
@ -181,6 +175,16 @@ namespace sprout_generator_detail {
|
|||
{
|
||||
return next_generator(sprout::forward<T>(t));
|
||||
}
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_generator_detail::select_mem_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::forward<T>(t).next_generator();
|
||||
}
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_generator_detail::select_get_next_generator<T>::value>::type = sprout::enabler
|
||||
|
|
Loading…
Reference in a new issue