1
0
Fork 0
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:
bolero-MURAKAMI 2012-09-30 11:09:44 +09:00
parent da86582643
commit b0ce004b36
3 changed files with 119 additions and 111 deletions

View file

@ -23,7 +23,7 @@ namespace sprout {
// //
template<typename T> template<typename T>
struct is_found_via_adl 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 } // namespace sprout

View file

@ -16,21 +16,6 @@ namespace sprout_generator_detail {
using sprout::tuples::get; using sprout::tuples::get;
using sprout_adl::generated_value; 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> template<typename T>
struct has_adl_generated_value_test { struct has_adl_generated_value_test {
public: public:
@ -48,6 +33,21 @@ namespace sprout_generator_detail {
: public decltype(sprout_generator_detail::has_adl_generated_value_test<T>::test(0)) : 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> template<typename T>
struct has_get_generated_value_test { struct has_get_generated_value_test {
public: public:
@ -63,23 +63,6 @@ namespace sprout_generator_detail {
: public decltype(sprout_generator_detail::has_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>
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> template<typename T, typename Enable = void>
struct select_adl_generated_value; struct select_adl_generated_value;
template<typename T> template<typename T>
@ -87,7 +70,6 @@ namespace sprout_generator_detail {
T, T,
typename std::enable_if< typename std::enable_if<
sprout_generator_detail::has_adl_generated_value<T>::value sprout_generator_detail::has_adl_generated_value<T>::value
&& !sprout_generator_detail::has_mem_generated_value<T>::value
>::type >::type
> >
: public std::true_type : public std::true_type
@ -97,7 +79,29 @@ namespace sprout_generator_detail {
T, T,
typename std::enable_if<!( typename std::enable_if<!(
sprout_generator_detail::has_adl_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
{};
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 )>::type
> >
: public std::false_type : public std::false_type
@ -110,8 +114,8 @@ namespace sprout_generator_detail {
T, T,
typename std::enable_if< typename std::enable_if<
sprout_generator_detail::has_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 && !sprout_generator_detail::has_adl_generated_value<T>::value
&& !sprout_generator_detail::has_mem_generated_value<T>::value
>::type >::type
> >
: public std::true_type : public std::true_type
@ -121,8 +125,8 @@ namespace sprout_generator_detail {
T, T,
typename std::enable_if<!( typename std::enable_if<!(
sprout_generator_detail::has_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 && !sprout_generator_detail::has_adl_generated_value<T>::value
&& !sprout_generator_detail::has_mem_generated_value<T>::value
)>::type )>::type
> >
: public std::false_type : public std::false_type
@ -131,14 +135,14 @@ namespace sprout_generator_detail {
template<typename T, typename = void> template<typename T, typename = void>
struct noexcept_generated_value; struct noexcept_generated_value;
template<typename T> 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> 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)> : 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_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> 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)> : 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> template<typename T, typename = void>
struct generated_value_result; struct generated_value_result;
template<typename T> 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> { struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type> {
public: public:
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_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> { struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_get_generated_value<T>::value>::type> {
public: public:
typedef decltype(get<0>(std::declval<T>())) type; 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< template<
typename T, typename T,
typename sprout::enabler_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type = sprout::enabler 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)); 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< template<
typename T, typename T,
typename sprout::enabler_if<sprout_generator_detail::select_get_generated_value<T>::value>::type = sprout::enabler typename sprout::enabler_if<sprout_generator_detail::select_get_generated_value<T>::value>::type = sprout::enabler

View file

@ -16,21 +16,6 @@ namespace sprout_generator_detail {
using sprout::tuples::get; using sprout::tuples::get;
using sprout_adl::next_generator; 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> template<typename T>
struct has_adl_next_generator_test { struct has_adl_next_generator_test {
public: public:
@ -48,6 +33,21 @@ namespace sprout_generator_detail {
: public decltype(sprout_generator_detail::has_adl_next_generator_test<T>::test(0)) : 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> template<typename T>
struct has_get_next_generator_test { struct has_get_next_generator_test {
public: public:
@ -63,23 +63,6 @@ namespace sprout_generator_detail {
: public decltype(sprout_generator_detail::has_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>
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> template<typename T, typename Enable = void>
struct select_adl_next_generator; struct select_adl_next_generator;
template<typename T> template<typename T>
@ -87,7 +70,6 @@ namespace sprout_generator_detail {
T, T,
typename std::enable_if< typename std::enable_if<
sprout_generator_detail::has_adl_next_generator<T>::value sprout_generator_detail::has_adl_next_generator<T>::value
&& !sprout_generator_detail::has_mem_next_generator<T>::value
>::type >::type
> >
: public std::true_type : public std::true_type
@ -97,7 +79,29 @@ namespace sprout_generator_detail {
T, T,
typename std::enable_if<!( typename std::enable_if<!(
sprout_generator_detail::has_adl_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
{};
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 )>::type
> >
: public std::false_type : public std::false_type
@ -110,8 +114,8 @@ namespace sprout_generator_detail {
T, T,
typename std::enable_if< typename std::enable_if<
sprout_generator_detail::has_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 && !sprout_generator_detail::has_adl_next_generator<T>::value
&& !sprout_generator_detail::has_mem_next_generator<T>::value
>::type >::type
> >
: public std::true_type : public std::true_type
@ -121,8 +125,8 @@ namespace sprout_generator_detail {
T, T,
typename std::enable_if<!( typename std::enable_if<!(
sprout_generator_detail::has_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 && !sprout_generator_detail::has_adl_next_generator<T>::value
&& !sprout_generator_detail::has_mem_next_generator<T>::value
)>::type )>::type
> >
: public std::false_type : public std::false_type
@ -131,14 +135,14 @@ namespace sprout_generator_detail {
template<typename T, typename = void> template<typename T, typename = void>
struct noexcept_next_generator; struct noexcept_next_generator;
template<typename T> 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> 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)> : 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_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> 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)> : 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> template<typename T, typename = void>
struct next_generator_result; struct next_generator_result;
template<typename T> 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> { struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_adl_next_generator<T>::value>::type> {
public: public:
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_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> { struct next_generator_result<T, typename std::enable_if<sprout_generator_detail::select_get_next_generator<T>::value>::type> {
public: public:
typedef decltype(get<1>(std::declval<T>())) type; 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< template<
typename T, typename T,
typename sprout::enabler_if<sprout_generator_detail::select_adl_next_generator<T>::value>::type = sprout::enabler 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)); 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< template<
typename T, typename T,
typename sprout::enabler_if<sprout_generator_detail::select_get_next_generator<T>::value>::type = sprout::enabler typename sprout::enabler_if<sprout_generator_detail::select_get_next_generator<T>::value>::type = sprout::enabler