diff --git a/sprout/generator/detail/generated_value.hpp b/sprout/generator/detail/generated_value.hpp new file mode 100644 index 00000000..bc10f3bc --- /dev/null +++ b/sprout/generator/detail/generated_value.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout_adl { + sprout::not_found_via_adl get_generated_value(...); +} // namespace sprout_adl + +namespace sprout { + namespace detail { + template + struct has_mem_generated_value_test { + public: + template< + typename U = T, + typename = typename sprout::identity().generated_value())>::type + > + static sprout::true_type test(int); + static sprout::false_type test(...); + }; +#if defined(_MSC_VER) && (_MSC_VER > 1900) + template::test(0))>::type> + struct has_mem_generated_value + : public Base_ + {}; +#else + template + struct has_mem_generated_value + : public sprout::identity::test(0))>::type + {}; +#endif + + template + struct is_substitutable_const_generated_value + : public sprout::bool_constant< + sprout::detail::has_mem_generated_value::value + > + {}; + + template + struct get_generated_value_impl; + + template + struct get_generated_value_impl< + Gen, + typename std::enable_if< + std::is_lvalue_reference::value && !std::is_const::type>::value + && sprout::detail::is_substitutable_const_generated_value::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().generated_value()) + get_generated_value(Gen& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().generated_value()) + { + typedef decltype(std::declval().generated_value()) type; + return sprout::const_reference_cast(sprout::as_const(gen).generated_value()); + } + }; + template + struct get_generated_value_impl< + Gen, + typename std::enable_if< + std::is_lvalue_reference::value && !std::is_const::type>::value + && !sprout::detail::is_substitutable_const_generated_value::value + && sprout::detail::has_mem_generated_value::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().generated_value()) + get_generated_value(Gen& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().generated_value()) + { + return gen.generated_value(); + } + }; + template + struct get_generated_value_impl< + Gen, + typename std::enable_if< + std::is_lvalue_reference::value && !std::is_const::type>::value + && !sprout::detail::is_substitutable_const_generated_value::value + && !sprout::detail::has_mem_generated_value::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval())) + get_generated_value(Gen& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval())) + { + return sprout::tuples::get<0>(gen); + } + }; + + template + struct get_generated_value_impl< + Gen, + typename std::enable_if< + std::is_rvalue_reference::value && !std::is_const::type>::value + && sprout::detail::is_substitutable_const_generated_value::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().generated_value()) + get_generated_value(Gen&& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().generated_value()) + { + typedef decltype(std::declval().generated_value()) type; + return sprout::const_reference_cast(sprout::as_const(sprout::move(gen)).generated_value()); + } + }; + template + struct get_generated_value_impl< + Gen, + typename std::enable_if< + std::is_rvalue_reference::value && !std::is_const::type>::value + && !sprout::detail::is_substitutable_const_generated_value::value + && sprout::detail::has_mem_generated_value::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().generated_value()) + get_generated_value(Gen&& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().generated_value()) + { + return sprout::move(gen).generated_value(); + } + }; + template + struct get_generated_value_impl< + Gen, + typename std::enable_if< + std::is_rvalue_reference::value && !std::is_const::type>::value + && !sprout::detail::is_substitutable_const_generated_value::value + && !sprout::detail::has_mem_generated_value::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval())) + get_generated_value(Gen&& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval())) + { + return sprout::tuples::get<0>(sprout::move(gen)); + } + }; + + template + struct get_generated_value_impl< + Gen, + typename std::enable_if< + std::is_reference::value && std::is_const::type>::value + && sprout::detail::has_mem_generated_value::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().generated_value()) + get_generated_value(Gen const& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().generated_value()) + { + return gen.generated_value(); + } + }; + template + struct get_generated_value_impl< + Gen, + typename std::enable_if< + std::is_reference::value && std::is_const::type>::value + && !sprout::detail::has_mem_generated_value::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval())) + get_generated_value(Gen const& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval())) + { + return sprout::tuples::get<0>(gen); + } + }; + } // namespace detail +} // namespace sprout + +namespace sprout_generator_detail { + template + inline SPROUT_CONSTEXPR decltype(sprout::detail::get_generated_value_impl::get_generated_value(std::declval())) + get_generated_value(Gen& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_generated_value_impl::get_generated_value(std::declval())) + { + return sprout::detail::get_generated_value_impl::get_generated_value(gen); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, + decltype(sprout::detail::get_generated_value_impl::get_generated_value(std::declval())) + >::type + get_generated_value(Gen&& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_generated_value_impl::get_generated_value(std::declval())) + { + return sprout::detail::get_generated_value_impl::get_generated_value(sprout::move(gen)); + } + template + inline SPROUT_CONSTEXPR decltype(sprout::detail::get_generated_value_impl::get_generated_value(std::declval())) + get_generated_value(Gen const& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_generated_value_impl::get_generated_value(std::declval())) + { + return sprout::detail::get_generated_value_impl::get_generated_value(gen); + } +} // namespace sprout_generator_detail + +#endif // #ifndef SPROUT_GENERATOR_DETAIL_GENERATED_VALUE_HPP diff --git a/sprout/generator/detail/next_generator.hpp b/sprout/generator/detail/next_generator.hpp new file mode 100644 index 00000000..d1c603be --- /dev/null +++ b/sprout/generator/detail/next_generator.hpp @@ -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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace sprout_adl { + sprout::not_found_via_adl get_next_generator(...); +} // namespace sprout_adl + +namespace sprout { + namespace detail { + template + struct has_mem_next_generator_test { + public: + template< + typename U = T, + typename = typename sprout::identity().next_generator())>::type + > + static sprout::true_type test(int); + static sprout::false_type test(...); + }; +#if defined(_MSC_VER) && (_MSC_VER > 1900) + template::test(0))>::type> + struct has_mem_next_generator + : public Base_ + {}; +#else + template + struct has_mem_next_generator + : public sprout::identity::test(0))>::type + {}; +#endif + + template + struct is_substitutable_const_next_generator + : public sprout::bool_constant< + sprout::detail::has_mem_next_generator::value + > + {}; + + template + struct get_next_generator_impl; + + template + struct get_next_generator_impl< + Gen, + typename std::enable_if< + std::is_lvalue_reference::value && !std::is_const::type>::value + && sprout::detail::is_substitutable_const_next_generator::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().next_generator()) + get_next_generator(Gen& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().next_generator()) + { + typedef decltype(std::declval().next_generator()) type; + return sprout::const_reference_cast(sprout::as_const(gen).next_generator()); + } + }; + template + struct get_next_generator_impl< + Gen, + typename std::enable_if< + std::is_lvalue_reference::value && !std::is_const::type>::value + && !sprout::detail::is_substitutable_const_next_generator::value + && sprout::detail::has_mem_next_generator::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().next_generator()) + get_next_generator(Gen& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().next_generator()) + { + return gen.next_generator(); + } + }; + template + struct get_next_generator_impl< + Gen, + typename std::enable_if< + std::is_lvalue_reference::value && !std::is_const::type>::value + && !sprout::detail::is_substitutable_const_next_generator::value + && !sprout::detail::has_mem_next_generator::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval())) + get_next_generator(Gen& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval())) + { + return sprout::tuples::get<1>(gen); + } + }; + + template + struct get_next_generator_impl< + Gen, + typename std::enable_if< + std::is_rvalue_reference::value && !std::is_const::type>::value + && sprout::detail::is_substitutable_const_next_generator::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().next_generator()) + get_next_generator(Gen&& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().next_generator()) + { + typedef decltype(std::declval().next_generator()) type; + return sprout::const_reference_cast(sprout::as_const(sprout::move(gen)).next_generator()); + } + }; + template + struct get_next_generator_impl< + Gen, + typename std::enable_if< + std::is_rvalue_reference::value && !std::is_const::type>::value + && !sprout::detail::is_substitutable_const_next_generator::value + && sprout::detail::has_mem_next_generator::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().next_generator()) + get_next_generator(Gen&& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().next_generator()) + { + return sprout::move(gen).next_generator(); + } + }; + template + struct get_next_generator_impl< + Gen, + typename std::enable_if< + std::is_rvalue_reference::value && !std::is_const::type>::value + && !sprout::detail::is_substitutable_const_next_generator::value + && !sprout::detail::has_mem_next_generator::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval())) + get_next_generator(Gen&& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval())) + { + return sprout::tuples::get<1>(sprout::move(gen)); + } + }; + + template + struct get_next_generator_impl< + Gen, + typename std::enable_if< + std::is_reference::value && std::is_const::type>::value + && sprout::detail::has_mem_next_generator::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(std::declval().next_generator()) + get_next_generator(Gen const& gen) + SPROUT_NOEXCEPT_IF_EXPR(std::declval().next_generator()) + { + return gen.next_generator(); + } + }; + template + struct get_next_generator_impl< + Gen, + typename std::enable_if< + std::is_reference::value && std::is_const::type>::value + && !sprout::detail::has_mem_next_generator::value + >::type + > { + public: + static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval())) + get_next_generator(Gen const& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval())) + { + return sprout::tuples::get<1>(gen); + } + }; + } // namespace detail +} // namespace sprout + +namespace sprout_generator_detail { + template + inline SPROUT_CONSTEXPR decltype(sprout::detail::get_next_generator_impl::get_next_generator(std::declval())) + get_next_generator(Gen& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_next_generator_impl::get_next_generator(std::declval())) + { + return sprout::detail::get_next_generator_impl::get_next_generator(gen); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, + decltype(sprout::detail::get_next_generator_impl::get_next_generator(std::declval())) + >::type + get_next_generator(Gen&& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_next_generator_impl::get_next_generator(std::declval())) + { + return sprout::detail::get_next_generator_impl::get_next_generator(sprout::move(gen)); + } + template + inline SPROUT_CONSTEXPR decltype(sprout::detail::get_next_generator_impl::get_next_generator(std::declval())) + get_next_generator(Gen const& gen) + SPROUT_NOEXCEPT_IF_EXPR(sprout::detail::get_next_generator_impl::get_next_generator(std::declval())) + { + return sprout::detail::get_next_generator_impl::get_next_generator(gen); + } +} // namespace sprout_generator_detail + +#endif // #ifndef SPROUT_GENERATOR_DETAIL_NEXT_GENERATOR_HPP diff --git a/sprout/generator/generated_value.hpp b/sprout/generator/generated_value.hpp index ed4d9476..b0848576 100644 --- a/sprout/generator/generated_value.hpp +++ b/sprout/generator/generated_value.hpp @@ -20,11 +20,14 @@ namespace sprout { // generated_value // // effect: - // sprout::generators::generator_access_traits::type>::get_generated_value(t) + // sprout::generators::generator_access_traits::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().generated_value())>(sprout::as_const(cont).generated_value()) + // otherwise, callable t.generated_value() -> t.generated_value() // otherwise -> sprout::tuples::get<0>(t) // template diff --git a/sprout/generator/generator_access_traits.hpp b/sprout/generator/generator_access_traits.hpp index f8cc509b..7c34561f 100644 --- a/sprout/generator/generator_access_traits.hpp +++ b/sprout/generator/generator_access_traits.hpp @@ -9,166 +9,16 @@ #define SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP #include -#include #include -#include #include -#include -#include -#include -#include - -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 - struct has_mem_generated_value_test { - public: - template< - typename U = T, - typename = typename sprout::identity().generated_value())>::type - > - static sprout::true_type test(int); - static sprout::false_type test(...); - }; -#if defined(_MSC_VER) && (_MSC_VER > 1900) - template::test(0))>::type> - struct has_mem_generated_value - : public Base_ - {}; -#else - template - struct has_mem_generated_value - : public sprout::identity::test(0))>::type - {}; -#endif - - template - struct get_generated_value_helper; - template - struct get_generated_value_helper< - Gen, - typename std::enable_if::value>::type - > { - public: - static SPROUT_CONSTEXPR decltype(std::declval().generated_value()) - call(Gen&& t) - SPROUT_NOEXCEPT_IF_EXPR(std::declval().generated_value()) - { - return SPROUT_FORWARD(Gen, t).generated_value(); - } - }; - template - struct get_generated_value_helper< - Gen, - typename std::enable_if::value>::type - > { - public: - static SPROUT_CONSTEXPR decltype(sprout::tuples::get<0>(std::declval())) - call(Gen&& t) - SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<0>(std::declval())) - { - return sprout::tuples::get<0>(SPROUT_FORWARD(Gen, t)); - } - }; - template - inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_generated_value_helper::call(std::declval())) - get_generated_value_impl(Gen&& t) { - return sprout::generators::detail::get_generated_value_helper::call(SPROUT_FORWARD(Gen, t)); - } - - template - struct has_mem_next_generator_test { - public: - template< - typename U = T, - typename = typename sprout::identity().next_generator())>::type - > - static sprout::true_type test(int); - static sprout::false_type test(...); - }; -#if defined(_MSC_VER) && (_MSC_VER > 1900) - template::test(0))>::type> - struct has_mem_next_generator - : public Base_ - {}; -#else - template - struct has_mem_next_generator - : public sprout::identity::test(0))>::type - {}; -#endif - - template - struct get_next_generator_helper; - template - struct get_next_generator_helper< - Gen, - typename std::enable_if::value>::type - > { - public: - static SPROUT_CONSTEXPR decltype(std::declval().next_generator()) - call(Gen&& t) - SPROUT_NOEXCEPT_IF_EXPR(std::declval().next_generator()) - { - return t.next_generator(); - } - }; - template - struct get_next_generator_helper< - Gen, - typename std::enable_if::value>::type - > { - public: - static SPROUT_CONSTEXPR decltype(sprout::tuples::get<1>(std::declval())) - call(Gen&& t) - SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::get<1>(std::declval())) - { - return sprout::tuples::get<1>(SPROUT_FORWARD(Gen, t)); - } - }; - template - inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_next_generator_helper::call(std::declval())) - get_next_generator_impl(Gen&& t) { - return sprout::generators::detail::get_next_generator_helper::call(SPROUT_FORWARD(Gen, t)); - } - } // namespace detail - } // namespace generators -} // namespace sprout +#include +#include +#include namespace sprout_generator_detail { using sprout_adl::get_generated_value; using sprout_adl::get_next_generator; - template - inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_generated_value_impl(std::declval())) - get_generated_value(Gen& gen) - SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_generated_value_impl(std::declval())) - { - return sprout::generators::detail::get_generated_value_impl(gen); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if< - !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, - decltype(sprout::generators::detail::get_generated_value_impl(std::declval())) - >::type - get_generated_value(Gen&& gen) - SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_generated_value_impl(std::declval())) - { - return sprout::generators::detail::get_generated_value_impl(sprout::move(gen)); - } - template - inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_generated_value_impl(std::declval())) - get_generated_value(Gen const& gen) - SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_generated_value_impl(std::declval())) - { - return sprout::generators::detail::get_generated_value_impl(gen); - } template inline SPROUT_CONSTEXPR decltype(get_generated_value(std::declval())) call_get_generated_value(Gen&& gen) @@ -176,31 +26,6 @@ namespace sprout_generator_detail { { return get_generated_value(SPROUT_FORWARD(Gen, gen)); } - - template - inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_next_generator_impl(std::declval())) - get_next_generator(Gen& gen) - SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_next_generator_impl(std::declval())) - { - return sprout::generators::detail::get_next_generator_impl(gen); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if< - !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, - decltype(sprout::generators::detail::get_next_generator_impl(std::declval())) - >::type - get_next_generator(Gen&& gen) - SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_next_generator_impl(std::declval())) - { - return sprout::generators::detail::get_next_generator_impl(sprout::move(gen)); - } - template - inline SPROUT_CONSTEXPR decltype(sprout::generators::detail::get_next_generator_impl(std::declval())) - get_next_generator(Gen const& gen) - SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::detail::get_next_generator_impl(std::declval())) - { - return sprout::generators::detail::get_next_generator_impl(gen); - } template inline SPROUT_CONSTEXPR decltype(get_next_generator(std::declval())) call_get_next_generator(Gen&& gen) @@ -212,13 +37,33 @@ namespace sprout_generator_detail { namespace sprout { namespace generators { + namespace detail { + template + struct generator_access_traits_const_default { + public: + // get_generated_value + static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::get_generated_value(std::declval())) + get_generated_value(Gen const& t) + SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits::get_generated_value(std::declval())) + { + return sprout::generators::generator_access_traits::get_generated_value(t); + } + // get_next_generator + static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::get_next_generator(std::declval())) + get_next_generator(Gen const& t) + SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits::get_next_generator(std::declval())) + { + return sprout::generators::generator_access_traits::get_next_generator(t); + } + }; + } // namespace detail + // - // generator_access_traits + // generator_access_get_generated_value_default // template - 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())) get_generated_value(Gen& t) SPROUT_NOEXCEPT_IF_EXPR(sprout_generator_detail::call_get_generated_value(std::declval())) @@ -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 + struct generator_access_get_next_generator_default { + public: static SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_get_next_generator(std::declval())) get_next_generator(Gen& t) SPROUT_NOEXCEPT_IF_EXPR(sprout_generator_detail::call_get_next_generator(std::declval())) @@ -257,27 +108,28 @@ namespace sprout { return sprout_generator_detail::call_get_next_generator(t); } }; - template - struct generator_access_traits { - public: - // get_generated_value - static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::get_generated_value(std::declval())) - get_generated_value(Gen const& t) - SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits::get_generated_value(std::declval())) - { - return sprout::generators::generator_access_traits::get_generated_value(t); - } - // get_next_generator - static SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits::get_next_generator(std::declval())) - get_next_generator(Gen const& t) - SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits::get_next_generator(std::declval())) - { - return sprout::generators::generator_access_traits::get_next_generator(t); - } - }; - } // namespace generators - using sprout::generators::generator_access_traits; + // + // generator_access_traits_default + // + template + struct generator_access_traits_default + : public sprout::generators::generator_access_get_generated_value_default + , public sprout::generators::generator_access_get_next_generator_default + {}; + + // + // generator_access_traits + // + template + struct generator_access_traits + : public sprout::generators::generator_access_traits_default + {}; + template + struct generator_access_traits + : public sprout::generators::detail::generator_access_traits_const_default + {}; + } // namespace generators } // namespace sprout #endif // #ifndef SPROUT_GENERATOR_GENERATOR_ACCESS_TRAITS_HPP diff --git a/sprout/generator/next_generator.hpp b/sprout/generator/next_generator.hpp index ce11239a..f53275c8 100644 --- a/sprout/generator/next_generator.hpp +++ b/sprout/generator/next_generator.hpp @@ -20,11 +20,14 @@ namespace sprout { // next_generator // // effect: - // sprout::generators::generator_access_traits::type>::get_next_generator(t) + // sprout::generators::generator_access_traits::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().next_generator())>(sprout::as_const(cont).next_generator()) + // otherwise, callable t.next_generator() -> t.next_generator() // otherwise -> sprout::tuples::get<0>(t) // template diff --git a/sprout/generator/traits_fwd.hpp b/sprout/generator/traits_fwd.hpp new file mode 100644 index 00000000..676e8dab --- /dev/null +++ b/sprout/generator/traits_fwd.hpp @@ -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 + +namespace sprout { + namespace generators { + // + // generator_access_traits + // + template + struct generator_access_traits; + } // namespace generators + + using sprout::generators::generator_access_traits; +} // namespace sprout + +#endif // #ifndef SPROUT_GENERATOR_TRAITS_FWD_HPP