2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2014-01-08 07:48:12 +00:00
|
|
|
Copyright (c) 2011-2014 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)
|
|
|
|
=============================================================================*/
|
2013-04-22 04:04:27 +00:00
|
|
|
#ifndef SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP
|
|
|
|
#define SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/tuple/tuple.hpp>
|
2014-02-21 14:43:24 +00:00
|
|
|
#include <sprout/type_traits/identity.hpp>
|
2013-11-22 12:11:08 +00:00
|
|
|
#include <sprout/type_traits/integral_constant.hpp>
|
2013-04-22 04:04:27 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace generators {
|
|
|
|
namespace detail {
|
|
|
|
template<typename T>
|
|
|
|
struct has_mem_generated_value_test {
|
|
|
|
public:
|
|
|
|
template<
|
|
|
|
typename U = T,
|
2014-03-15 03:06:51 +00:00
|
|
|
typename = typename sprout::identity<decltype(std::declval<U>().generated_value())>::type
|
2013-04-22 04:04:27 +00:00
|
|
|
>
|
2013-11-22 12:11:08 +00:00
|
|
|
static sprout::true_type test(int);
|
|
|
|
static sprout::false_type test(...);
|
2013-04-22 04:04:27 +00:00
|
|
|
};
|
|
|
|
#if defined(_MSC_VER)
|
2014-03-15 03:06:51 +00:00
|
|
|
template<typename T, typename Base_ = typename sprout::identity<decltype(sprout::generators::detail::has_mem_generated_value_test<T>::test(0))>::type>
|
2013-04-22 04:04:27 +00:00
|
|
|
struct has_mem_generated_value
|
|
|
|
: public Base_
|
|
|
|
{};
|
|
|
|
#else
|
|
|
|
template<typename T>
|
|
|
|
struct has_mem_generated_value
|
2014-02-21 14:16:23 +00:00
|
|
|
: public sprout::identity<decltype(sprout::generators::detail::has_mem_generated_value_test<T>::test(0))>::type
|
2013-04-22 04:04:27 +00:00
|
|
|
{};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<typename Gen, typename = void>
|
|
|
|
struct generator_access_traits_generated_value_impl;
|
|
|
|
template<typename Gen>
|
|
|
|
struct generator_access_traits_generated_value_impl<
|
|
|
|
Gen,
|
|
|
|
typename std::enable_if<sprout::generators::detail::has_mem_generated_value<Gen>::value>::type
|
|
|
|
> {
|
|
|
|
public:
|
|
|
|
static SPROUT_CONSTEXPR decltype(std::declval<Gen&>().generated_value())
|
2013-04-22 04:35:01 +00:00
|
|
|
get_generated_value(Gen& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&>().generated_value())
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return t.generated_value();
|
|
|
|
}
|
|
|
|
static SPROUT_CONSTEXPR decltype(std::declval<Gen&&>().generated_value())
|
2013-04-22 04:35:01 +00:00
|
|
|
get_generated_value(Gen&& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&&>().generated_value())
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return t.generated_value();
|
|
|
|
}
|
|
|
|
static SPROUT_CONSTEXPR decltype(std::declval<Gen const&>().generated_value())
|
2013-04-22 04:35:01 +00:00
|
|
|
get_generated_value(Gen const& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen const&>().generated_value())
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return t.generated_value();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename Gen>
|
|
|
|
struct generator_access_traits_generated_value_impl<
|
|
|
|
Gen,
|
|
|
|
typename std::enable_if<!sprout::generators::detail::has_mem_generated_value<Gen>::value>::type
|
|
|
|
> {
|
|
|
|
public:
|
|
|
|
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen&>()))
|
2013-04-22 04:35:01 +00:00
|
|
|
get_generated_value(Gen& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return sprout::tuples::get<0>(t);
|
|
|
|
}
|
|
|
|
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen&&>()))
|
2013-04-22 04:35:01 +00:00
|
|
|
get_generated_value(Gen&& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return sprout::tuples::get<0>(t);
|
|
|
|
}
|
|
|
|
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval<Gen const&>()))
|
2013-04-22 04:35:01 +00:00
|
|
|
get_generated_value(Gen const& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen const&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return sprout::tuples::get<0>(t);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct has_mem_next_generator_test {
|
|
|
|
public:
|
|
|
|
template<
|
|
|
|
typename U = T,
|
2014-03-15 03:06:51 +00:00
|
|
|
typename = typename sprout::identity<decltype(std::declval<U>().next_generator())>::type
|
2013-04-22 04:04:27 +00:00
|
|
|
>
|
2013-11-22 12:11:08 +00:00
|
|
|
static sprout::true_type test(int);
|
|
|
|
static sprout::false_type test(...);
|
2013-04-22 04:04:27 +00:00
|
|
|
};
|
|
|
|
#if defined(_MSC_VER)
|
2014-03-15 03:06:51 +00:00
|
|
|
template<typename T, typename Base_ = typename sprout::identity<decltype(sprout::generators::detail::has_mem_next_generator_test<T>::test(0))>::type>
|
2013-04-22 04:04:27 +00:00
|
|
|
struct has_mem_next_generator
|
|
|
|
: public Base_
|
|
|
|
{};
|
|
|
|
#else
|
|
|
|
template<typename T>
|
|
|
|
struct has_mem_next_generator
|
2014-02-21 14:16:23 +00:00
|
|
|
: public sprout::identity<decltype(sprout::generators::detail::has_mem_next_generator_test<T>::test(0))>::type
|
2013-04-22 04:04:27 +00:00
|
|
|
{};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<typename Gen, typename = void>
|
|
|
|
struct generator_access_traits_next_generator_impl;
|
|
|
|
template<typename Gen>
|
|
|
|
struct generator_access_traits_next_generator_impl<
|
|
|
|
Gen,
|
|
|
|
typename std::enable_if<sprout::generators::detail::has_mem_next_generator<Gen>::value>::type
|
|
|
|
> {
|
|
|
|
public:
|
|
|
|
static SPROUT_CONSTEXPR decltype(std::declval<Gen&>().next_generator())
|
2013-04-22 04:35:01 +00:00
|
|
|
get_next_generator(Gen& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&>().next_generator())
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return t.next_generator();
|
|
|
|
}
|
|
|
|
static SPROUT_CONSTEXPR decltype(std::declval<Gen&&>().next_generator())
|
2013-04-22 04:35:01 +00:00
|
|
|
get_next_generator(Gen&& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen&&>().next_generator())
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return t.next_generator();
|
|
|
|
}
|
|
|
|
static SPROUT_CONSTEXPR decltype(std::declval<Gen const&>().next_generator())
|
2013-04-22 04:35:01 +00:00
|
|
|
get_next_generator(Gen const& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen const&>().next_generator())
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return t.next_generator();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename Gen>
|
|
|
|
struct generator_access_traits_next_generator_impl<
|
|
|
|
Gen,
|
|
|
|
typename std::enable_if<!sprout::generators::detail::has_mem_next_generator<Gen>::value>::type
|
|
|
|
> {
|
|
|
|
public:
|
|
|
|
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen&>()))
|
2013-04-22 04:35:01 +00:00
|
|
|
get_next_generator(Gen& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return sprout::tuples::get<1>(t);
|
|
|
|
}
|
|
|
|
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen&&>()))
|
2013-04-22 04:35:01 +00:00
|
|
|
get_next_generator(Gen&& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return sprout::tuples::get<1>(t);
|
|
|
|
}
|
|
|
|
static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval<Gen const&>()))
|
2013-04-22 04:35:01 +00:00
|
|
|
get_next_generator(Gen const& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen const&>()))
|
2013-04-22 04:04:27 +00:00
|
|
|
{
|
|
|
|
return sprout::tuples::get<1>(t);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
//
|
|
|
|
// generator_access_traits
|
|
|
|
//
|
|
|
|
template<typename Gen>
|
|
|
|
struct generator_access_traits
|
|
|
|
: public sprout::generators::detail::generator_access_traits_generated_value_impl<Gen>
|
|
|
|
, public sprout::generators::detail::generator_access_traits_next_generator_impl<Gen>
|
|
|
|
{};
|
|
|
|
template<typename Gen>
|
|
|
|
struct generator_access_traits<Gen const> {
|
|
|
|
public:
|
2013-04-22 04:35:01 +00:00
|
|
|
static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::get_generated_value(std::declval<Gen const&>()))
|
|
|
|
get_generated_value(Gen const& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen>::get_generated_value(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>::get_generated_value(t);
|
2013-04-22 04:04:27 +00:00
|
|
|
}
|
2013-04-22 04:35:01 +00:00
|
|
|
static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::get_next_generator(std::declval<Gen const&>()))
|
|
|
|
get_next_generator(Gen const& t)
|
2014-08-14 13:55:49 +00:00
|
|
|
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen>::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>::get_next_generator(t);
|
2013-04-22 04:04:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace generators
|
|
|
|
|
|
|
|
using sprout::generators::generator_access_traits;
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP
|