add generators::next_value function

This commit is contained in:
bolero-MURAKAMI 2016-04-28 08:42:13 +09:00
parent 2fe34cc922
commit 51614b1356
16 changed files with 681 additions and 98 deletions

View file

@ -0,0 +1,15 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_GENERATOR_ACCESS_FUNCTIONS_HPP
#define SPROUT_GENERATOR_ACCESS_FUNCTIONS_HPP
#include <sprout/config.hpp>
#include <sprout/generator/generated_value.hpp>
#include <sprout/generator/next_generator.hpp>
#endif // #ifndef SPROUT_GENERATOR_ACCESS_FUNCTIONS_HPP

View file

@ -0,0 +1,39 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_GENERATOR_ACCESS_FUNCTIONS_FWD_HPP
#define SPROUT_GENERATOR_ACCESS_FUNCTIONS_FWD_HPP
#include <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/generator/traits_fwd.hpp>
namespace sprout {
namespace generators {
//
// generated_value
//
template<typename T>
SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<typename std::remove_reference<T>::type>::get_generated_value(std::declval<T>()))
generated_value(T&& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<typename std::remove_reference<T>::type>::get_generated_value(std::declval<T>()));
//
// next_generator
//
template<typename T>
SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<typename std::remove_reference<T>::type>::get_next_generator(std::declval<T>()))
next_generator(T&& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<typename std::remove_reference<T>::type>::get_next_generator(std::declval<T>()));
} // namespace generators
using sprout::generators::generated_value;
using sprout::generators::next_generator;
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_ACCESS_FUNCTIONS_FWD_HPP

View file

@ -67,11 +67,11 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&>().generated_value())
get_generated_value(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&>().generated_value())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().generated_value())
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().generated_value())
{
typedef decltype(std::declval<Gen&>().generated_value()) type;
typedef decltype(std::declval<Gen>().generated_value()) type;
return sprout::const_reference_cast<type>(sprout::as_const(gen).generated_value());
}
};
@ -85,9 +85,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&>().generated_value())
get_generated_value(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&>().generated_value())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().generated_value())
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().generated_value())
{
return gen.generated_value();
}
@ -103,9 +103,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(*std::declval<Gen&>())
get_generated_value(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(*std::declval<Gen&>())
static SPROUT_CONSTEXPR decltype(*std::declval<Gen>())
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(*std::declval<Gen>())
{
return *gen;
}
@ -121,9 +121,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen&>()))
get_generated_value(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen&>()))
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen>()))
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen>()))
{
return sprout::tuples::get<0>(gen);
}
@ -138,11 +138,11 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&&>().generated_value())
get_generated_value(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&&>().generated_value())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().generated_value())
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().generated_value())
{
typedef decltype(std::declval<Gen&&>().generated_value()) type;
typedef decltype(std::declval<Gen>().generated_value()) type;
return sprout::const_reference_cast<type>(sprout::as_const(sprout::move(gen)).generated_value());
}
};
@ -156,9 +156,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&&>().generated_value())
get_generated_value(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&&>().generated_value())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().generated_value())
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().generated_value())
{
return sprout::move(gen).generated_value();
}
@ -174,9 +174,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(*std::declval<Gen&&>())
get_generated_value(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(*std::declval<Gen&&>())
static SPROUT_CONSTEXPR decltype(*std::declval<Gen>())
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(*std::declval<Gen>())
{
return *sprout::move(gen);
}
@ -192,9 +192,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen&&>()))
get_generated_value(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen&&>()))
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen>()))
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen>()))
{
return sprout::tuples::get<0>(sprout::move(gen));
}
@ -209,9 +209,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen const&>().generated_value())
get_generated_value(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen const&>().generated_value())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().generated_value())
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().generated_value())
{
return gen.generated_value();
}
@ -226,9 +226,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(*std::declval<Gen const&>())
get_generated_value(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(*std::declval<Gen const&>())
static SPROUT_CONSTEXPR decltype(*std::declval<Gen>())
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(*std::declval<Gen>())
{
return *gen;
}
@ -243,9 +243,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen const&>()))
get_generated_value(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen const&>()))
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen>()))
get_generated_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen>()))
{
return sprout::tuples::get<0>(gen);
}

View file

@ -15,7 +15,6 @@
#include <sprout/type_traits/identity.hpp>
#include <sprout/iterator/const_reference_cast.hpp>
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/utility/as_const.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple.hpp>
@ -68,11 +67,11 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&>().next_generator())
get_next_generator(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&>().next_generator())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().next_generator())
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().next_generator())
{
typedef decltype(std::declval<Gen&>().next_generator()) type;
typedef decltype(std::declval<Gen>().next_generator()) type;
return sprout::const_reference_cast<type>(sprout::as_const(gen).next_generator());
}
};
@ -86,32 +85,14 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&>().next_generator())
get_next_generator(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&>().next_generator())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().next_generator())
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().next_generator())
{
return gen.next_generator();
}
};
template<typename Gen>
struct get_next_generator_impl<
Gen,
typename std::enable_if<
std::is_lvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::is_substitutable_const_next_generator<Gen>::value
&& !sprout::detail::has_mem_next_generator<Gen>::value
&& !sprout::is_input_iterator<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::next(std::declval<Gen&>()))
get_next_generator(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::next(std::declval<Gen&>()))
{
return sprout::next(gen);
}
};
template<typename Gen>
struct get_next_generator_impl<
Gen,
typename std::enable_if<
@ -122,9 +103,27 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen&>()))
get_next_generator(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen&>()))
static SPROUT_CONSTEXPR decltype(std::declval<Gen>())
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>())
{
return gen;
}
};
template<typename Gen>
struct get_next_generator_impl<
Gen,
typename std::enable_if<
std::is_lvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::is_substitutable_const_next_generator<Gen>::value
&& !sprout::detail::has_mem_next_generator<Gen>::value
&& !sprout::is_input_iterator<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen>()))
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen>()))
{
return sprout::tuples::get<1>(gen);
}
@ -139,11 +138,11 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&&>().next_generator())
get_next_generator(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&&>().next_generator())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().next_generator())
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().next_generator())
{
typedef decltype(std::declval<Gen&&>().next_generator()) type;
typedef decltype(std::declval<Gen>().next_generator()) type;
return sprout::const_reference_cast<type>(sprout::as_const(sprout::move(gen)).next_generator());
}
};
@ -157,9 +156,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen&&>().next_generator())
get_next_generator(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&&>().next_generator())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().next_generator())
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().next_generator())
{
return sprout::move(gen).next_generator();
}
@ -175,11 +174,11 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::next(std::declval<Gen&&>()))
get_next_generator(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::next(std::declval<Gen&&>()))
static SPROUT_CONSTEXPR decltype(std::declval<Gen>())
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>())
{
return sprout::next(sprout::move(gen));
return sprout::move(gen);
}
};
template<typename Gen>
@ -193,9 +192,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen&&>()))
get_next_generator(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen&&>()))
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen>()))
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen>()))
{
return sprout::tuples::get<1>(sprout::move(gen));
}
@ -210,9 +209,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen const&>().next_generator())
get_next_generator(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen const&>().next_generator())
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().next_generator())
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().next_generator())
{
return gen.next_generator();
}
@ -227,11 +226,11 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::next(std::declval<Gen const&>()))
get_next_generator(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::next(std::declval<Gen const&>()))
static SPROUT_CONSTEXPR decltype(std::declval<Gen>())
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>())
{
return sprout::next(gen);
return gen;
}
};
template<typename Gen>
@ -244,9 +243,9 @@ namespace sprout {
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen const&>()))
get_next_generator(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen const&>()))
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen>()))
get_next_generator(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen>()))
{
return sprout::tuples::get<1>(gen);
}

View file

@ -0,0 +1,317 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_GENERATOR_DETAIL_NEXT_VALUE_HPP
#define SPROUT_GENERATOR_DETAIL_NEXT_VALUE_HPP
#include <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/iterator/const_reference_cast.hpp>
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
#include <sprout/iterator/next.hpp>
#include <sprout/utility/as_const.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/generator/access_functions_fwd.hpp>
#include <sprout/generator/next_generator.hpp>
#include <sprout/adl/not_found.hpp>
namespace sprout_adl {
sprout::not_found_via_adl generate_next_value(...);
} // namespace sprout_adl
namespace sprout {
namespace detail {
template<typename T>
struct has_mem_next_value_test {
public:
template<
typename U = T,
typename = typename sprout::identity<decltype(std::declval<U>().next_value())>::type
>
static sprout::true_type test(int);
static sprout::false_type test(...);
};
#if defined(_MSC_VER) && (_MSC_VER > 1900)
template<typename T, typename Base_ = typename sprout::identity<decltype(sprout::detail::has_mem_next_value_test<T>::test(0))>::type>
struct has_mem_next_value
: public Base_
{};
#else
template<typename T>
struct has_mem_next_value
: public sprout::identity<decltype(sprout::detail::has_mem_next_value_test<T>::test(0))>::type
{};
#endif
template<typename T>
struct has_function_call_test {
public:
template<
typename U = T,
typename = typename sprout::identity<decltype(std::declval<U>()())>::type
>
static sprout::true_type test(int);
static sprout::false_type test(...);
};
#if defined(_MSC_VER) && (_MSC_VER > 1900)
template<typename T, typename Base_ = typename sprout::identity<decltype(sprout::detail::has_function_call_test<T>::test(0))>::type>
struct has_function_call
: public Base_
{};
#else
template<typename T>
struct has_function_call
: public sprout::identity<decltype(sprout::detail::has_function_call_test<T>::test(0))>::type
{};
#endif
template<typename Gen, typename = void>
struct generate_next_value_impl;
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_lvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& sprout::detail::has_mem_next_value<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().next_value())
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().next_value())
{
return gen.next_value();
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_lvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::has_mem_next_value<Gen>::value
&& sprout::is_input_iterator<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::next(std::declval<Gen>()))
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::next(std::declval<Gen>()))
{
return sprout::next(gen);
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_lvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::has_mem_next_value<Gen>::value
&& !sprout::is_input_iterator<Gen>::value
&& sprout::detail::has_function_call<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen>()())
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>()())
{
return gen();
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_lvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::has_mem_next_value<Gen>::value
&& !sprout::is_input_iterator<Gen>::value
&& !sprout::detail::has_function_call<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::generators::next_value(sprout::generators::next_generator(std::declval<Gen>())))
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::next_value(sprout::generators::next_generator(std::declval<Gen>())))
{
return sprout::generators::next_value(sprout::generators::next_generator(gen));
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_rvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& sprout::detail::has_mem_next_value<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().next_value())
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().next_value())
{
return sprout::move(gen).next_value();
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_rvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::has_mem_next_value<Gen>::value
&& sprout::is_input_iterator<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::next(std::declval<Gen>()))
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::next(std::declval<Gen>()))
{
return sprout::next(sprout::move(gen));
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_rvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::has_mem_next_value<Gen>::value
&& !sprout::is_input_iterator<Gen>::value
&& sprout::detail::has_function_call<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen>()())
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>()())
{
return sprout::move(gen)();
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_rvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::has_mem_next_value<Gen>::value
&& !sprout::is_input_iterator<Gen>::value
&& !sprout::detail::has_function_call<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::generators::next_value(sprout::generators::next_generator(std::declval<Gen>())))
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::next_value(sprout::generators::next_generator(std::declval<Gen>())))
{
return sprout::generators::next_value(sprout::generators::next_generator(sprout::move(gen)));
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_reference<Gen>::value && std::is_const<typename std::remove_reference<Gen>::type>::value
&& sprout::detail::has_mem_next_value<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen>().next_value())
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().next_value())
{
return gen.next_value();
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_reference<Gen>::value && std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::has_mem_next_value<Gen>::value
&& sprout::is_input_iterator<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::next(std::declval<Gen>()))
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::next(std::declval<Gen>()))
{
return sprout::next(gen);
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_reference<Gen>::value && std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::has_mem_next_value<Gen>::value
&& !sprout::is_input_iterator<Gen>::value
&& sprout::detail::has_function_call<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(std::declval<Gen>()())
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>()())
{
return gen();
}
};
template<typename Gen>
struct generate_next_value_impl<
Gen,
typename std::enable_if<
std::is_reference<Gen>::value && std::is_const<typename std::remove_reference<Gen>::type>::value
&& !sprout::detail::has_mem_next_value<Gen>::value
&& !sprout::is_input_iterator<Gen>::value
&& !sprout::detail::has_function_call<Gen>::value
>::type
> {
public:
static SPROUT_CONSTEXPR decltype(sprout::generators::next_value(sprout::generators::next_generator(std::declval<Gen>())))
generate_next_value(Gen gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::next_value(sprout::generators::next_generator(std::declval<Gen>())))
{
return sprout::generators::next_value(sprout::generators::next_generator(gen));
}
};
} // namespace detail
} // namespace sprout
namespace sprout_generator_detail {
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::detail::generate_next_value_impl<Gen&>::generate_next_value(std::declval<Gen&>()))
generate_next_value(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::generate_next_value_impl<Gen&>::generate_next_value(std::declval<Gen&>()))
{
return sprout::detail::generate_next_value_impl<Gen&>::generate_next_value(gen);
}
template<typename Gen>
inline SPROUT_CONSTEXPR typename std::enable_if<
!std::is_const<Gen>::value && !std::is_volatile<Gen>::value && !std::is_reference<Gen>::value,
decltype(sprout::detail::generate_next_value_impl<Gen&&>::generate_next_value(std::declval<Gen&&>()))
>::type
generate_next_value(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::generate_next_value_impl<Gen&&>::generate_next_value(std::declval<Gen&&>()))
{
return sprout::detail::generate_next_value_impl<Gen&&>::generate_next_value(sprout::move(gen));
}
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::detail::generate_next_value_impl<Gen const&>::generate_next_value(std::declval<Gen const&>()))
generate_next_value(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::generate_next_value_impl<Gen const&>::generate_next_value(std::declval<Gen const&>()))
{
return sprout::detail::generate_next_value_impl<Gen const&>::generate_next_value(gen);
}
} // namespace sprout_generator_detail
#endif // #ifndef SPROUT_GENERATOR_DETAIL_NEXT_VALUE_HPP

View file

@ -9,7 +9,7 @@
#define SPROUT_GENERATOR_FUNCTIONS_HPP
#include <sprout/config.hpp>
#include <sprout/generator/generated_value.hpp>
#include <sprout/generator/next_generator.hpp>
#include <sprout/generator/access_functions.hpp>
#include <sprout/generator/generate_functions.hpp>
#endif // #ifndef SPROUT_GENERATOR_FUNCTIONS_HPP

View file

@ -0,0 +1,14 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_GENERATOR_GENERATE_FUNCTIONS_HPP
#define SPROUT_GENERATOR_GENERATE_FUNCTIONS_HPP
#include <sprout/config.hpp>
#include <sprout/generator/next_value.hpp>
#endif // #ifndef SPROUT_GENERATOR_GENERATE_FUNCTIONS_HPP

View file

@ -0,0 +1,30 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_GENERATOR_GENERATE_FUNCTIONS_FWD_HPP
#define SPROUT_GENERATOR_GENERATE_FUNCTIONS_FWD_HPP
#include <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/generator/traits_fwd.hpp>
namespace sprout {
namespace generators {
//
// next_value
//
template<typename T>
SPROUT_CONSTEXPR decltype(sprout::generators::generator_generate_traits<typename std::remove_reference<T>::type>::generate_next_value(std::declval<T>()))
next_value(T&& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_generate_traits<typename std::remove_reference<T>::type>::generate_next_value(std::declval<T>()));
} // namespace generators
using sprout::generators::next_value;
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_GENERATE_FUNCTIONS_FWD_HPP

View file

@ -39,8 +39,6 @@ namespace sprout {
return sprout::generators::generator_access_traits<typename std::remove_reference<T>::type>::get_generated_value(SPROUT_FORWARD(T, t));
}
} // namespace generators
using sprout::generators::generated_value;
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_GENERATED_VALUE_HPP

View file

@ -12,6 +12,7 @@
#include <sprout/config.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/generator/traits_fwd.hpp>
#include <sprout/generator/access_functions_fwd.hpp>
#include <sprout/generator/detail/generated_value.hpp>
#include <sprout/generator/detail/next_generator.hpp>

View file

@ -0,0 +1,97 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_GENERATOR_GENERATOR_GENERATE_TRAITS_HPP
#define SPROUT_GENERATOR_GENERATOR_GENERATE_TRAITS_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/generator/traits_fwd.hpp>
#include <sprout/generator/generate_functions_fwd.hpp>
#include <sprout/generator/detail/next_value.hpp>
namespace sprout_generator_detail {
using sprout_adl::generate_next_value;
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(generate_next_value(std::declval<Gen>()))
call_generate_next_value(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(generate_next_value(std::declval<Gen>()))
{
return generate_next_value(SPROUT_FORWARD(Gen, gen));
}
} // namespace sprout_generator_detail
namespace sprout {
namespace generators {
namespace detail {
template<typename Gen>
struct generator_generate_traits_const_default {
public:
// generate_next_value
static SPROUT_CONSTEXPR decltype(sprout::generators::generator_generate_traits<Gen>::generate_next_value(std::declval<Gen const&>()))
generate_next_value(Gen const& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_generate_traits<Gen>::generate_next_value(std::declval<Gen const&>()))
{
return sprout::generators::generator_generate_traits<Gen>::generate_next_value(t);
}
};
} // namespace detail
//
// generator_generate_generate_next_value_default
//
template<typename Gen>
struct generator_generate_generate_next_value_default {
public:
static SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_generate_next_value(std::declval<Gen&>()))
generate_next_value(Gen& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout_generator_detail::call_generate_next_value(std::declval<Gen&>()))
{
return sprout_generator_detail::call_generate_next_value(t);
}
static SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_generate_next_value(std::declval<Gen&&>()))
generate_next_value(Gen&& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout_generator_detail::call_generate_next_value(std::declval<Gen&&>()))
{
return sprout_generator_detail::call_generate_next_value(sprout::move(t));
}
static SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_generate_next_value(std::declval<Gen const&>()))
generate_next_value(Gen const& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout_generator_detail::call_generate_next_value(std::declval<Gen const&>()))
{
return sprout_generator_detail::call_generate_next_value(t);
}
};
//
// generator_generate_traits_default
//
template<typename Gen>
struct generator_generate_traits_default
: public sprout::generators::generator_generate_generate_next_value_default<Gen>
{};
//
// generator_generate_traits
//
template<typename Gen>
struct generator_generate_traits
: public sprout::generators::generator_generate_traits_default<Gen>
{};
template<typename Gen>
struct generator_generate_traits<Gen const>
: public sprout::generators::detail::generator_generate_traits_const_default<Gen>
{};
} // namespace generators
} // namespace sprout
#include <sprout/generator/next_generator.hpp>
#include <sprout/generator/next_value.hpp>
#endif // #ifndef SPROUT_GENERATOR_GENERATOR_GENERATE_TRAITS_HPP

View file

@ -28,7 +28,7 @@ namespace sprout {
// && callable sprout::as_const(t).next_generator()
// -> sprout::const_reference_cast<decltype(std::declval<T&>().next_generator())>(sprout::as_const(cont).next_generator())
// otherwise, callable t.next_generator() -> t.next_generator()
// otherwise, T is InputIterator -> sprout::next(t)
// otherwise, T is InputIterator -> t
// otherwise -> sprout::tuples::get<0>(t)
//
template<typename T>
@ -39,8 +39,6 @@ namespace sprout {
return sprout::generators::generator_access_traits<typename std::remove_reference<T>::type>::get_next_generator(SPROUT_FORWARD(T, t));
}
} // namespace generators
using sprout::generators::next_generator;
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_NEXT_GENERATOR_HPP

View file

@ -0,0 +1,42 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_GENERATOR_NEXT_VALUE_HPP
#define SPROUT_GENERATOR_NEXT_VALUE_HPP
#include <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/generator/generator_generate_traits.hpp>
namespace sprout {
namespace generators {
//
// next_value
//
// effect:
// sprout::generators::generator_generate_traits<T>::generate_next_value(t)
// [default]
// ADL callable generate_next_value(t) -> generate_next_value(t)
// [default]
// otherwise, callable t.next_value() -> t.next_value()
// otherwise, T is InputIterator -> sprout::next(t)
// otherwise, callable t() -> t()
// otherwise -> sprout::generators::next_value(sprout::generators::next_generator(t))
//
template<typename T>
inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_generate_traits<typename std::remove_reference<T>::type>::generate_next_value(std::declval<T>()))
next_value(T&& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_generate_traits<typename std::remove_reference<T>::type>::generate_next_value(std::declval<T>()))
{
return sprout::generators::generator_generate_traits<typename std::remove_reference<T>::type>::generate_next_value(SPROUT_FORWARD(T, t));
}
} // namespace generators
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_NEXT_VALUE_HPP

View file

@ -8,11 +8,12 @@
#ifndef SPROUT_GENERATOR_RESULTS_HPP
#define SPROUT_GENERATOR_RESULTS_HPP
#include <type_traits>
#include <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/generator/generated_value.hpp>
#include <sprout/generator/next_generator.hpp>
#include <sprout/generator/next_value.hpp>
namespace sprout {
namespace generators {
@ -32,12 +33,21 @@ namespace sprout {
struct next_generator
: public std::decay<decltype(sprout::generators::next_generator(std::declval<Generator>()()))>
{};
//
// next_value
//
template<typename Generator>
struct next_value
: public std::decay<decltype(sprout::generators::next_value(std::declval<Generator>()()))>
{};
} // namespace results
} // namespace generators
namespace results {
using sprout::generators::generated_value;
using sprout::generators::next_generator;
using sprout::generators::results::generated_value;
using sprout::generators::results::next_generator;
using sprout::generators::results::next_value;
} // namespace results
} // namespace sprout

View file

@ -0,0 +1,16 @@
/*=============================================================================
Copyright (c) 2011-2016 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#ifndef SPROUT_GENERATOR_TRAITS_HPP
#define SPROUT_GENERATOR_TRAITS_HPP
#include <sprout/config.hpp>
#include <sprout/generator/traits_fwd.hpp>
#include <sprout/generator/generator_access_traits.hpp>
#include <sprout/generator/generator_generate_traits.hpp>
#endif // #ifndef SPROUT_GENERATOR_TRAITS_HPP

View file

@ -17,9 +17,16 @@ namespace sprout {
//
template<typename Gen>
struct generator_access_traits;
//
// generator_generate_traits
//
template<typename Gen>
struct generator_generate_traits;
} // namespace generators
using sprout::generators::generator_access_traits;
using sprout::generators::generator_generate_traits;
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_TRAITS_FWD_HPP