change generator_traits

This commit is contained in:
bolero-MURAKAMI 2016-04-27 15:02:12 +09:00
parent ef073dbdbb
commit 7f137c0a83
6 changed files with 541 additions and 206 deletions

View file

@ -0,0 +1,226 @@
/*=============================================================================
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_GENERATED_VALUE_HPP
#define SPROUT_GENERATOR_DETAIL_GENERATED_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/utility/as_const.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/adl/not_found.hpp>
namespace sprout_adl {
sprout::not_found_via_adl get_generated_value(...);
} // namespace sprout_adl
namespace sprout {
namespace detail {
template<typename T>
struct has_mem_generated_value_test {
public:
template<
typename U = T,
typename = typename sprout::identity<decltype(std::declval<U>().generated_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_generated_value_test<T>::test(0))>::type>
struct has_mem_generated_value
: public Base_
{};
#else
template<typename T>
struct has_mem_generated_value
: public sprout::identity<decltype(sprout::detail::has_mem_generated_value_test<T>::test(0))>::type
{};
#endif
template<typename T>
struct is_substitutable_const_generated_value
: public sprout::bool_constant<
sprout::detail::has_mem_generated_value<T const>::value
>
{};
template<typename Gen, typename = void>
struct get_generated_value_impl;
template<typename Gen>
struct get_generated_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::is_substitutable_const_generated_value<Gen>::value
>::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())
{
typedef decltype(std::declval<Gen&>().generated_value()) type;
return sprout::const_reference_cast<type>(sprout::as_const(gen).generated_value());
}
};
template<typename Gen>
struct get_generated_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::is_substitutable_const_generated_value<Gen>::value
&& sprout::detail::has_mem_generated_value<Gen>::value
>::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())
{
return gen.generated_value();
}
};
template<typename Gen>
struct get_generated_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::is_substitutable_const_generated_value<Gen>::value
&& !sprout::detail::has_mem_generated_value<Gen>::value
>::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&>()))
{
return sprout::tuples::get<0>(gen);
}
};
template<typename Gen>
struct get_generated_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::is_substitutable_const_generated_value<Gen>::value
>::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())
{
typedef decltype(std::declval<Gen&&>().generated_value()) type;
return sprout::const_reference_cast<type>(sprout::as_const(sprout::move(gen)).generated_value());
}
};
template<typename Gen>
struct get_generated_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::is_substitutable_const_generated_value<Gen>::value
&& sprout::detail::has_mem_generated_value<Gen>::value
>::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())
{
return sprout::move(gen).generated_value();
}
};
template<typename Gen>
struct get_generated_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::is_substitutable_const_generated_value<Gen>::value
&& !sprout::detail::has_mem_generated_value<Gen>::value
>::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&&>()))
{
return sprout::tuples::get<0>(sprout::move(gen));
}
};
template<typename Gen>
struct get_generated_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_generated_value<Gen const>::value
>::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())
{
return gen.generated_value();
}
};
template<typename Gen>
struct get_generated_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_generated_value<Gen const>::value
>::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&>()))
{
return sprout::tuples::get<0>(gen);
}
};
} // namespace detail
} // namespace sprout
namespace sprout_generator_detail {
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::detail::get_generated_value_impl<Gen&>::get_generated_value(std::declval<Gen&>()))
get_generated_value(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_generated_value_impl<Gen&>::get_generated_value(std::declval<Gen&>()))
{
return sprout::detail::get_generated_value_impl<Gen&>::get_generated_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::get_generated_value_impl<Gen&&>::get_generated_value(std::declval<Gen&&>()))
>::type
get_generated_value(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_generated_value_impl<Gen&&>::get_generated_value(std::declval<Gen&&>()))
{
return sprout::detail::get_generated_value_impl<Gen&&>::get_generated_value(sprout::move(gen));
}
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::detail::get_generated_value_impl<Gen const&>::get_generated_value(std::declval<Gen const&>()))
get_generated_value(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_generated_value_impl<Gen const&>::get_generated_value(std::declval<Gen const&>()))
{
return sprout::detail::get_generated_value_impl<Gen const&>::get_generated_value(gen);
}
} // namespace sprout_generator_detail
#endif // #ifndef SPROUT_GENERATOR_DETAIL_GENERATED_VALUE_HPP

View file

@ -0,0 +1,226 @@
/*=============================================================================
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_GENERATOR_HPP
#define SPROUT_GENERATOR_DETAIL_NEXT_GENERATOR_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/utility/as_const.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/adl/not_found.hpp>
namespace sprout_adl {
sprout::not_found_via_adl get_next_generator(...);
} // namespace sprout_adl
namespace sprout {
namespace detail {
template<typename T>
struct has_mem_next_generator_test {
public:
template<
typename U = T,
typename = typename sprout::identity<decltype(std::declval<U>().next_generator())>::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_generator_test<T>::test(0))>::type>
struct has_mem_next_generator
: public Base_
{};
#else
template<typename T>
struct has_mem_next_generator
: public sprout::identity<decltype(sprout::detail::has_mem_next_generator_test<T>::test(0))>::type
{};
#endif
template<typename T>
struct is_substitutable_const_next_generator
: public sprout::bool_constant<
sprout::detail::has_mem_next_generator<T const>::value
>
{};
template<typename Gen, typename = void>
struct get_next_generator_impl;
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
>::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())
{
typedef decltype(std::declval<Gen&>().next_generator()) type;
return sprout::const_reference_cast<type>(sprout::as_const(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
>::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())
{
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
>::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);
}
};
template<typename Gen>
struct get_next_generator_impl<
Gen,
typename std::enable_if<
std::is_rvalue_reference<Gen>::value && !std::is_const<typename std::remove_reference<Gen>::type>::value
&& sprout::detail::is_substitutable_const_next_generator<Gen>::value
>::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())
{
typedef decltype(std::declval<Gen&&>().next_generator()) type;
return sprout::const_reference_cast<type>(sprout::as_const(sprout::move(gen)).next_generator());
}
};
template<typename Gen>
struct get_next_generator_impl<
Gen,
typename std::enable_if<
std::is_rvalue_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
>::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())
{
return sprout::move(gen).next_generator();
}
};
template<typename Gen>
struct get_next_generator_impl<
Gen,
typename std::enable_if<
std::is_rvalue_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
>::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>(sprout::move(gen));
}
};
template<typename Gen>
struct get_next_generator_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_generator<Gen const>::value
>::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())
{
return gen.next_generator();
}
};
template<typename Gen>
struct get_next_generator_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_generator<Gen const>::value
>::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&>()))
{
return sprout::tuples::get<1>(gen);
}
};
} // namespace detail
} // namespace sprout
namespace sprout_generator_detail {
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::detail::get_next_generator_impl<Gen&>::get_next_generator(std::declval<Gen&>()))
get_next_generator(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_next_generator_impl<Gen&>::get_next_generator(std::declval<Gen&>()))
{
return sprout::detail::get_next_generator_impl<Gen&>::get_next_generator(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::get_next_generator_impl<Gen&&>::get_next_generator(std::declval<Gen&&>()))
>::type
get_next_generator(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_next_generator_impl<Gen&&>::get_next_generator(std::declval<Gen&&>()))
{
return sprout::detail::get_next_generator_impl<Gen&&>::get_next_generator(sprout::move(gen));
}
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::detail::get_next_generator_impl<Gen const&>::get_next_generator(std::declval<Gen const&>()))
get_next_generator(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_next_generator_impl<Gen const&>::get_next_generator(std::declval<Gen const&>()))
{
return sprout::detail::get_next_generator_impl<Gen const&>::get_next_generator(gen);
}
} // namespace sprout_generator_detail
#endif // #ifndef SPROUT_GENERATOR_DETAIL_NEXT_GENERATOR_HPP

View file

@ -20,11 +20,14 @@ namespace sprout {
// generated_value
//
// effect:
// sprout::generators::generator_access_traits<typename std::remove_reference<T>::type>::get_generated_value(t)
// sprout::generators::generator_access_traits<T>::get_generated_value(t)
// [default]
// ADL callable get_generated_value(t) -> get_generated_value(t)
// [default]
// callable t.generated_value() -> t.generated_value()
// T is not const
// && callable sprout::as_const(t).generated_value()
// -> sprout::const_reference_cast<decltype(std::declval<T&>().generated_value())>(sprout::as_const(cont).generated_value())
// otherwise, callable t.generated_value() -> t.generated_value()
// otherwise -> sprout::tuples::get<0>(t)
//
template<typename T>

View file

@ -9,166 +9,16 @@
#define SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP
#include <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/integral_constant.hpp>
#include <sprout/adl/not_found.hpp>
namespace sprout_adl {
sprout::not_found_via_adl get_generated_value(...);
sprout::not_found_via_adl get_next_generator(...);
} // namespace sprout_adl
namespace sprout {
namespace generators {
namespace detail {
template<typename T>
struct has_mem_generated_value_test {
public:
template<
typename U = T,
typename = typename sprout::identity<decltype(std::declval<U>().generated_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::generators::detail::has_mem_generated_value_test<T>::test(0))>::type>
struct has_mem_generated_value
: public Base_
{};
#else
template<typename T>
struct has_mem_generated_value
: public sprout::identity<decltype(sprout::generators::detail::has_mem_generated_value_test<T>::test(0))>::type
{};
#endif
template<typename Gen, typename = void>
struct get_generated_value_helper;
template<typename Gen>
struct get_generated_value_helper<
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())
call(Gen&& t)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().generated_value())
{
return SPROUT_FORWARD(Gen, t).generated_value();
}
};
template<typename Gen>
struct get_generated_value_helper<
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>()))
call(Gen&& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval<Gen>()))
{
return sprout::tuples::get<0>(SPROUT_FORWARD(Gen, t));
}
};
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_generated_value_helper<Gen>::call(std::declval<Gen>()))
get_generated_value_impl(Gen&& t) {
return sprout::generators::detail::get_generated_value_helper<Gen>::call(SPROUT_FORWARD(Gen, t));
}
template<typename T>
struct has_mem_next_generator_test {
public:
template<
typename U = T,
typename = typename sprout::identity<decltype(std::declval<U>().next_generator())>::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::generators::detail::has_mem_next_generator_test<T>::test(0))>::type>
struct has_mem_next_generator
: public Base_
{};
#else
template<typename T>
struct has_mem_next_generator
: public sprout::identity<decltype(sprout::generators::detail::has_mem_next_generator_test<T>::test(0))>::type
{};
#endif
template<typename Gen, typename = void>
struct get_next_generator_helper;
template<typename Gen>
struct get_next_generator_helper<
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())
call(Gen&& t)
SPROUT_NOEXCEPT_IF_EXPR(std::declval<Gen>().next_generator())
{
return t.next_generator();
}
};
template<typename Gen>
struct get_next_generator_helper<
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>()))
call(Gen&& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval<Gen>()))
{
return sprout::tuples::get<1>(SPROUT_FORWARD(Gen, t));
}
};
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_next_generator_helper<Gen>::call(std::declval<Gen>()))
get_next_generator_impl(Gen&& t) {
return sprout::generators::detail::get_next_generator_helper<Gen>::call(SPROUT_FORWARD(Gen, t));
}
} // namespace detail
} // namespace generators
} // namespace sprout
#include <sprout/generator/traits_fwd.hpp>
#include <sprout/generator/detail/generated_value.hpp>
#include <sprout/generator/detail/next_generator.hpp>
namespace sprout_generator_detail {
using sprout_adl::get_generated_value;
using sprout_adl::get_next_generator;
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_generated_value_impl(std::declval<Gen&>()))
get_generated_value(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_generated_value_impl(std::declval<Gen&>()))
{
return sprout::generators::detail::get_generated_value_impl(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::generators::detail::get_generated_value_impl(std::declval<Gen&&>()))
>::type
get_generated_value(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_generated_value_impl(std::declval<Gen&&>()))
{
return sprout::generators::detail::get_generated_value_impl(sprout::move(gen));
}
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_generated_value_impl(std::declval<Gen const&>()))
get_generated_value(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_generated_value_impl(std::declval<Gen const&>()))
{
return sprout::generators::detail::get_generated_value_impl(gen);
}
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(get_generated_value(std::declval<Gen>()))
call_get_generated_value(Gen&& gen)
@ -176,31 +26,6 @@ namespace sprout_generator_detail {
{
return get_generated_value(SPROUT_FORWARD(Gen, gen));
}
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_next_generator_impl(std::declval<Gen&>()))
get_next_generator(Gen& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_next_generator_impl(std::declval<Gen&>()))
{
return sprout::generators::detail::get_next_generator_impl(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::generators::detail::get_next_generator_impl(std::declval<Gen&&>()))
>::type
get_next_generator(Gen&& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_next_generator_impl(std::declval<Gen&&>()))
{
return sprout::generators::detail::get_next_generator_impl(sprout::move(gen));
}
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_next_generator_impl(std::declval<Gen const&>()))
get_next_generator(Gen const& gen)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_next_generator_impl(std::declval<Gen const&>()))
{
return sprout::generators::detail::get_next_generator_impl(gen);
}
template<typename Gen>
inline SPROUT_CONSTEXPR decltype(get_next_generator(std::declval<Gen>()))
call_get_next_generator(Gen&& gen)
@ -212,13 +37,33 @@ namespace sprout_generator_detail {
namespace sprout {
namespace generators {
namespace detail {
template<typename Gen>
struct generator_access_traits_const_default {
public:
// get_generated_value
static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::get_generated_value(std::declval<Gen const&>()))
get_generated_value(Gen const& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen>::get_generated_value(std::declval<Gen const&>()))
{
return sprout::generators::generator_access_traits<Gen>::get_generated_value(t);
}
// get_next_generator
static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::get_next_generator(std::declval<Gen const&>()))
get_next_generator(Gen const& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen>::get_next_generator(std::declval<Gen const&>()))
{
return sprout::generators::generator_access_traits<Gen>::get_next_generator(t);
}
};
} // namespace detail
//
// generator_access_traits
// generator_access_get_generated_value_default
//
template<typename Gen>
struct generator_access_traits {
struct generator_access_get_generated_value_default {
public:
// get_generated_value
static SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_get_generated_value(std::declval<Gen&>()))
get_generated_value(Gen& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout_generator_detail::call_get_generated_value(std::declval<Gen&>()))
@ -237,7 +82,13 @@ namespace sprout {
{
return sprout_generator_detail::call_get_generated_value(t);
}
// get_next_generator
};
//
// generator_access_get_next_generator_default
//
template<typename Gen>
struct generator_access_get_next_generator_default {
public:
static SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_get_next_generator(std::declval<Gen&>()))
get_next_generator(Gen& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout_generator_detail::call_get_next_generator(std::declval<Gen&>()))
@ -257,27 +108,28 @@ namespace sprout {
return sprout_generator_detail::call_get_next_generator(t);
}
};
template<typename Gen>
struct generator_access_traits<Gen const> {
public:
// get_generated_value
static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::get_generated_value(std::declval<Gen const&>()))
get_generated_value(Gen const& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen>::get_generated_value(std::declval<Gen const&>()))
{
return sprout::generators::generator_access_traits<Gen>::get_generated_value(t);
}
// get_next_generator
static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::get_next_generator(std::declval<Gen const&>()))
get_next_generator(Gen const& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen>::get_next_generator(std::declval<Gen const&>()))
{
return sprout::generators::generator_access_traits<Gen>::get_next_generator(t);
}
};
} // namespace generators
using sprout::generators::generator_access_traits;
//
// generator_access_traits_default
//
template<typename Gen>
struct generator_access_traits_default
: public sprout::generators::generator_access_get_generated_value_default<Gen>
, public sprout::generators::generator_access_get_next_generator_default<Gen>
{};
//
// generator_access_traits
//
template<typename Gen>
struct generator_access_traits
: public sprout::generators::generator_access_traits_default<Gen>
{};
template<typename Gen>
struct generator_access_traits<Gen const>
: public sprout::generators::detail::generator_access_traits_const_default<Gen>
{};
} // namespace generators
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP

View file

@ -20,11 +20,14 @@ namespace sprout {
// next_generator
//
// effect:
// sprout::generators::generator_access_traits<typename std::remove_reference<T>::type>::get_next_generator(t)
// sprout::generators::generator_access_traits<T>::get_next_generator(t)
// [default]
// ADL callable get_next_generator(t) -> get_next_generator(t)
// [default]
// callable t.next_generator() -> t.next_generator()
// T is not const
// && 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 -> sprout::tuples::get<0>(t)
//
template<typename T>

View file

@ -0,0 +1,25 @@
/*=============================================================================
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_FWD_HPP
#define SPROUT_GENERATOR_TRAITS_FWD_HPP
#include <sprout/config.hpp>
namespace sprout {
namespace generators {
//
// generator_access_traits
//
template<typename Gen>
struct generator_access_traits;
} // namespace generators
using sprout::generators::generator_access_traits;
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_TRAITS_FWD_HPP