2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2015-01-10 10:13:57 +00:00
|
|
|
Copyright (c) 2011-2015 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
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)
|
|
|
|
=============================================================================*/
|
2012-09-21 06:43:30 +00:00
|
|
|
#ifndef SPROUT_GENERATOR_NEXT_GENERATOR_HPP
|
|
|
|
#define SPROUT_GENERATOR_NEXT_GENERATOR_HPP
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <type_traits>
|
2013-04-22 04:04:27 +00:00
|
|
|
#include <sprout/config.hpp>
|
2012-09-21 06:43:30 +00:00
|
|
|
#include <sprout/utility/forward.hpp>
|
2013-04-22 04:04:27 +00:00
|
|
|
#include <sprout/generator/generator_access_traits.hpp>
|
2012-09-29 08:10:46 +00:00
|
|
|
#include <sprout/adl/not_found.hpp>
|
|
|
|
|
|
|
|
namespace sprout_adl {
|
2013-04-22 04:35:01 +00:00
|
|
|
sprout::not_found_via_adl get_next_generator(...);
|
2012-09-29 08:10:46 +00:00
|
|
|
} // namespace sprout_adl
|
2012-09-21 06:43:30 +00:00
|
|
|
|
2012-09-26 07:31:11 +00:00
|
|
|
namespace sprout_generator_detail {
|
2013-04-22 04:35:01 +00:00
|
|
|
using sprout_adl::get_next_generator;
|
2012-09-21 06:43:30 +00:00
|
|
|
|
2013-04-22 04:04:27 +00:00
|
|
|
template<typename Gen>
|
2013-04-22 04:35:01 +00:00
|
|
|
inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::get_next_generator(std::declval<Gen&>()))
|
|
|
|
get_next_generator(Gen& gen)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen>::get_next_generator(std::declval<Gen&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
2013-04-22 04:35:01 +00:00
|
|
|
return sprout::generators::generator_access_traits<Gen>::get_next_generator(gen);
|
2013-04-22 04:04:27 +00:00
|
|
|
}
|
|
|
|
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,
|
2013-04-22 04:35:01 +00:00
|
|
|
decltype(sprout::generators::generator_access_traits<typename std::remove_reference<Gen>::type>::get_next_generator(std::declval<Gen&&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
>::type
|
2013-04-22 04:35:01 +00:00
|
|
|
get_next_generator(Gen&& gen)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<typename std::remove_reference<Gen>::type>::get_next_generator(std::declval<Gen&&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
2013-04-22 04:35:01 +00:00
|
|
|
return sprout::generators::generator_access_traits<Gen>::get_next_generator(gen);
|
2013-04-22 04:04:27 +00:00
|
|
|
}
|
|
|
|
template<typename Gen>
|
2013-04-22 04:35:01 +00:00
|
|
|
inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen const>::get_next_generator(std::declval<Gen const&>()))
|
|
|
|
get_next_generator(Gen const& gen)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen const>::get_next_generator(std::declval<Gen const&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
2013-04-22 04:35:01 +00:00
|
|
|
return sprout::generators::generator_access_traits<Gen const>::get_next_generator(gen);
|
2013-04-22 04:04:27 +00:00
|
|
|
}
|
2012-09-21 06:43:30 +00:00
|
|
|
|
2013-04-22 04:04:27 +00:00
|
|
|
template<typename Gen>
|
2013-04-22 04:35:01 +00:00
|
|
|
inline SPROUT_CONSTEXPR decltype(get_next_generator(std::declval<Gen&>()))
|
|
|
|
call_get_next_generator(Gen& gen)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(get_next_generator(std::declval<Gen&>()))
|
2012-09-21 06:43:30 +00:00
|
|
|
{
|
2013-04-22 04:35:01 +00:00
|
|
|
return get_next_generator(gen);
|
2012-09-21 06:43:30 +00:00
|
|
|
}
|
2013-04-22 04:04:27 +00:00
|
|
|
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,
|
2013-04-22 04:35:01 +00:00
|
|
|
decltype(get_next_generator(std::declval<Gen&&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
>::type
|
2013-04-22 04:35:01 +00:00
|
|
|
call_get_next_generator(Gen&& gen)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(get_next_generator(std::declval<Gen&&>()))
|
2012-09-26 09:42:43 +00:00
|
|
|
{
|
2013-04-22 04:35:01 +00:00
|
|
|
return get_next_generator(gen);
|
2012-09-26 09:42:43 +00:00
|
|
|
}
|
2013-04-22 04:04:27 +00:00
|
|
|
template<typename Gen>
|
2013-04-22 04:35:01 +00:00
|
|
|
inline SPROUT_CONSTEXPR decltype(get_next_generator(std::declval<Gen const&>()))
|
|
|
|
call_get_next_generator(Gen const& gen)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(get_next_generator(std::declval<Gen const&>()))
|
2012-09-21 06:43:30 +00:00
|
|
|
{
|
2013-04-22 04:35:01 +00:00
|
|
|
return get_next_generator(gen);
|
2012-09-21 06:43:30 +00:00
|
|
|
}
|
|
|
|
} // namespace sprout_generator_detail
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace generators {
|
|
|
|
//
|
|
|
|
// next_generator
|
|
|
|
//
|
2013-04-22 14:55:30 +00:00
|
|
|
// effect:
|
|
|
|
// ADL callable get_next_generator(t) -> get_next_generator(t)
|
|
|
|
// otherwise -> sprout::generators::generator_access_traits<T>::get_next_generator(t)
|
|
|
|
// [default]
|
|
|
|
// member callable t.next_generator() -> t.next_generator()
|
|
|
|
// otherwise -> sprout::tuples::get<0>(t)
|
|
|
|
//
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename T>
|
2013-04-22 04:35:01 +00:00
|
|
|
inline SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_get_next_generator(std::declval<T>()))
|
2012-09-21 06:43:30 +00:00
|
|
|
next_generator(T&& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout_generator_detail::call_get_next_generator(std::declval<T>()))
|
2012-09-21 06:43:30 +00:00
|
|
|
{
|
2014-02-22 07:32:51 +00:00
|
|
|
return sprout_generator_detail::call_get_next_generator(SPROUT_FORWARD(T, t));
|
2012-09-21 06:43:30 +00:00
|
|
|
}
|
|
|
|
} // namespace generators
|
|
|
|
|
|
|
|
using sprout::generators::next_generator;
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_GENERATOR_NEXT_GENERATOR_HPP
|