Sprout/sprout/generator/generated_value.hpp

101 lines
4.1 KiB
C++
Raw Normal View History

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)
=============================================================================*/
#ifndef SPROUT_GENERATOR_GENERATED_VALUE_HPP
#define SPROUT_GENERATOR_GENERATED_VALUE_HPP
#include <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/generator/generator_access_traits.hpp>
#include <sprout/adl/not_found.hpp>
namespace sprout_adl {
2013-04-22 04:35:01 +00:00
sprout::not_found_via_adl get_generated_value(...);
} // namespace sprout_adl
namespace sprout_generator_detail {
2013-04-22 04:35:01 +00:00
using sprout_adl::get_generated_value;
template<typename Gen>
2013-04-22 04:35:01 +00:00
inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen>::get_generated_value(std::declval<Gen&>()))
get_generated_value(Gen& gen)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen>::get_generated_value(std::declval<Gen&>()))
{
2013-04-22 04:35:01 +00:00
return sprout::generators::generator_access_traits<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,
2013-04-22 04:35:01 +00:00
decltype(sprout::generators::generator_access_traits<typename std::remove_reference<Gen>::type>::get_generated_value(std::declval<Gen&&>()))
>::type
2013-04-22 04:35:01 +00:00
get_generated_value(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_generated_value(std::declval<Gen&&>()))
{
2013-04-22 04:35:01 +00:00
return sprout::generators::generator_access_traits<Gen>::get_generated_value(gen);
}
template<typename Gen>
2013-04-22 04:35:01 +00:00
inline SPROUT_CONSTEXPR decltype(sprout::generators::generator_access_traits<Gen const>::get_generated_value(std::declval<Gen const&>()))
get_generated_value(Gen const& gen)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(sprout::generators::generator_access_traits<Gen const>::get_generated_value(std::declval<Gen const&>()))
{
2013-04-22 04:35:01 +00:00
return sprout::generators::generator_access_traits<Gen const>::get_generated_value(gen);
}
template<typename Gen>
2013-04-22 04:35:01 +00:00
inline SPROUT_CONSTEXPR decltype(get_generated_value(std::declval<Gen&>()))
call_get_generated_value(Gen& gen)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(get_generated_value(std::declval<Gen&>()))
{
2013-04-22 04:35:01 +00:00
return 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,
2013-04-22 04:35:01 +00:00
decltype(get_generated_value(std::declval<Gen&&>()))
>::type
2013-04-22 04:35:01 +00:00
call_get_generated_value(Gen&& gen)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(get_generated_value(std::declval<Gen&&>()))
{
2013-04-22 04:35:01 +00:00
return get_generated_value(gen);
}
template<typename Gen>
2013-04-22 04:35:01 +00:00
inline SPROUT_CONSTEXPR decltype(get_generated_value(std::declval<Gen const&>()))
call_get_generated_value(Gen const& gen)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(get_generated_value(std::declval<Gen const&>()))
{
2013-04-22 04:35:01 +00:00
return get_generated_value(gen);
}
} // namespace sprout_generator_detail
namespace sprout {
namespace generators {
//
// generated_value
//
2013-04-22 14:55:30 +00:00
// effect:
// ADL callable get_generated_value(t) -> get_generated_value(t)
// otherwise -> sprout::generators::generator_access_traits<T>::get_generated_value(t)
// [default]
// member callable t.generated_value() -> t.generated_value()
// otherwise -> sprout::tuples::get<0>(t)
//
template<typename T>
2013-04-22 04:35:01 +00:00
inline SPROUT_CONSTEXPR decltype(sprout_generator_detail::call_get_generated_value(std::declval<T>()))
generated_value(T&& t)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(sprout_generator_detail::call_get_generated_value(std::declval<T>()))
{
return sprout_generator_detail::call_get_generated_value(SPROUT_FORWARD(T, t));
}
} // namespace generators
using sprout::generators::generated_value;
} // namespace sprout
#endif // #ifndef SPROUT_GENERATOR_GENERATED_VALUE_HPP