2012-09-21 06:43:30 +00:00
|
|
|
#ifndef SPROUT_GENERATOR_GENERATED_VALUE_HPP
|
|
|
|
#define SPROUT_GENERATOR_GENERATED_VALUE_HPP
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/utility/forward.hpp>
|
|
|
|
#include <sprout/type_traits/enabler_if.hpp>
|
|
|
|
#include <sprout/tuple/tuple/get.hpp>
|
2012-09-29 08:10:46 +00:00
|
|
|
#include <sprout/adl/not_found.hpp>
|
|
|
|
|
|
|
|
namespace sprout_adl {
|
2012-09-29 14:39:00 +00:00
|
|
|
sprout::not_found_via_adl generated_value(...);
|
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 {
|
2012-09-27 05:19:25 +00:00
|
|
|
using sprout::tuples::get;
|
2012-09-29 08:10:46 +00:00
|
|
|
using sprout_adl::generated_value;
|
2012-09-21 06:43:30 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct has_adl_generated_value_test {
|
2012-09-21 06:43:30 +00:00
|
|
|
public:
|
|
|
|
template<
|
|
|
|
typename U = T,
|
2012-09-30 02:09:44 +00:00
|
|
|
typename sprout::enabler_if<
|
|
|
|
sprout::is_found_via_adl<decltype(generated_value(std::declval<U>()))>::value
|
|
|
|
>::type = sprout::enabler
|
2012-09-21 06:43:30 +00:00
|
|
|
>
|
|
|
|
static std::true_type test(int);
|
|
|
|
static std::false_type test(...);
|
|
|
|
};
|
2012-12-17 11:10:17 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
template<typename T, typename Base_ = decltype(sprout_generator_detail::has_adl_generated_value_test<T>::test(0))>
|
|
|
|
struct has_adl_generated_value
|
|
|
|
: public Base_
|
|
|
|
{};
|
|
|
|
#else
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct has_adl_generated_value
|
|
|
|
: public decltype(sprout_generator_detail::has_adl_generated_value_test<T>::test(0))
|
2012-09-21 06:43:30 +00:00
|
|
|
{};
|
2012-12-17 11:10:17 +00:00
|
|
|
#endif
|
2012-09-21 06:43:30 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct has_mem_generated_value_test {
|
2012-09-21 06:43:30 +00:00
|
|
|
public:
|
|
|
|
template<
|
|
|
|
typename U = T,
|
2012-09-30 02:09:44 +00:00
|
|
|
typename = decltype(std::declval<U>().generated_value())
|
2012-09-21 06:43:30 +00:00
|
|
|
>
|
|
|
|
static std::true_type test(int);
|
|
|
|
static std::false_type test(...);
|
|
|
|
};
|
2012-12-17 11:10:17 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
template<typename T, typename Base_ = decltype(sprout_generator_detail::has_mem_generated_value_test<T>::test(0))>
|
|
|
|
struct has_mem_generated_value
|
|
|
|
: public Base_
|
|
|
|
{};
|
|
|
|
#else
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct has_mem_generated_value
|
|
|
|
: public decltype(sprout_generator_detail::has_mem_generated_value_test<T>::test(0))
|
2012-09-21 06:43:30 +00:00
|
|
|
{};
|
2012-12-17 11:10:17 +00:00
|
|
|
#endif
|
2012-09-21 06:43:30 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2012-09-27 05:19:25 +00:00
|
|
|
struct has_get_generated_value_test {
|
2012-09-21 06:43:30 +00:00
|
|
|
public:
|
|
|
|
template<
|
|
|
|
typename U = T,
|
2012-09-27 05:19:25 +00:00
|
|
|
typename = decltype(get<0>(std::declval<U>()))
|
2012-09-21 06:43:30 +00:00
|
|
|
>
|
|
|
|
static std::true_type test(int);
|
|
|
|
static std::false_type test(...);
|
|
|
|
};
|
2012-12-17 11:10:17 +00:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
template<typename T, typename Base_ = decltype(sprout_generator_detail::has_get_generated_value_test<T>::test(0))>
|
|
|
|
struct has_get_generated_value
|
|
|
|
: public Base_
|
|
|
|
{};
|
|
|
|
#else
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename T>
|
2012-09-27 05:19:25 +00:00
|
|
|
struct has_get_generated_value
|
|
|
|
: public decltype(sprout_generator_detail::has_get_generated_value_test<T>::test(0))
|
2012-09-21 06:43:30 +00:00
|
|
|
{};
|
2012-12-17 11:10:17 +00:00
|
|
|
#endif
|
2012-09-21 06:43:30 +00:00
|
|
|
|
|
|
|
template<typename T, typename Enable = void>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct select_adl_generated_value;
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct select_adl_generated_value<
|
2012-09-21 06:43:30 +00:00
|
|
|
T,
|
2012-09-30 02:09:44 +00:00
|
|
|
typename std::enable_if<
|
|
|
|
sprout_generator_detail::has_adl_generated_value<T>::value
|
|
|
|
>::type
|
2012-09-21 06:43:30 +00:00
|
|
|
>
|
|
|
|
: public std::true_type
|
|
|
|
{};
|
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct select_adl_generated_value<
|
2012-09-21 06:43:30 +00:00
|
|
|
T,
|
2012-09-30 02:09:44 +00:00
|
|
|
typename std::enable_if<!(
|
|
|
|
sprout_generator_detail::has_adl_generated_value<T>::value
|
|
|
|
)>::type
|
2012-09-21 06:43:30 +00:00
|
|
|
>
|
|
|
|
: public std::false_type
|
|
|
|
{};
|
|
|
|
|
|
|
|
template<typename T, typename Enable = void>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct select_mem_generated_value;
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct select_mem_generated_value<
|
2012-09-21 06:43:30 +00:00
|
|
|
T,
|
|
|
|
typename std::enable_if<
|
2012-09-30 02:09:44 +00:00
|
|
|
sprout_generator_detail::has_mem_generated_value<T>::value
|
|
|
|
&& !sprout_generator_detail::has_adl_generated_value<T>::value
|
2012-09-21 06:43:30 +00:00
|
|
|
>::type
|
|
|
|
>
|
|
|
|
: public std::true_type
|
|
|
|
{};
|
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct select_mem_generated_value<
|
2012-09-21 06:43:30 +00:00
|
|
|
T,
|
|
|
|
typename std::enable_if<!(
|
2012-09-30 02:09:44 +00:00
|
|
|
sprout_generator_detail::has_mem_generated_value<T>::value
|
|
|
|
&& !sprout_generator_detail::has_adl_generated_value<T>::value
|
2012-09-21 06:43:30 +00:00
|
|
|
)>::type
|
|
|
|
>
|
|
|
|
: public std::false_type
|
|
|
|
{};
|
|
|
|
|
|
|
|
template<typename T, typename Enable = void>
|
2012-09-27 05:19:25 +00:00
|
|
|
struct select_get_generated_value;
|
2012-09-21 06:43:30 +00:00
|
|
|
template<typename T>
|
2012-09-27 05:19:25 +00:00
|
|
|
struct select_get_generated_value<
|
2012-09-21 06:43:30 +00:00
|
|
|
T,
|
|
|
|
typename std::enable_if<
|
2012-09-27 05:19:25 +00:00
|
|
|
sprout_generator_detail::has_get_generated_value<T>::value
|
2012-09-26 09:42:43 +00:00
|
|
|
&& !sprout_generator_detail::has_adl_generated_value<T>::value
|
2012-09-30 02:09:44 +00:00
|
|
|
&& !sprout_generator_detail::has_mem_generated_value<T>::value
|
2012-09-21 06:43:30 +00:00
|
|
|
>::type
|
|
|
|
>
|
|
|
|
: public std::true_type
|
|
|
|
{};
|
|
|
|
template<typename T>
|
2012-09-27 05:19:25 +00:00
|
|
|
struct select_get_generated_value<
|
2012-09-21 06:43:30 +00:00
|
|
|
T,
|
|
|
|
typename std::enable_if<!(
|
2012-09-27 05:19:25 +00:00
|
|
|
sprout_generator_detail::has_get_generated_value<T>::value
|
2012-09-26 09:42:43 +00:00
|
|
|
&& !sprout_generator_detail::has_adl_generated_value<T>::value
|
2012-09-30 02:09:44 +00:00
|
|
|
&& !sprout_generator_detail::has_mem_generated_value<T>::value
|
2012-09-21 06:43:30 +00:00
|
|
|
)>::type
|
|
|
|
>
|
|
|
|
: public std::false_type
|
|
|
|
{};
|
|
|
|
|
|
|
|
template<typename T, typename = void>
|
|
|
|
struct noexcept_generated_value;
|
|
|
|
template<typename T>
|
2012-09-26 09:42:43 +00:00
|
|
|
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type>
|
|
|
|
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(generated_value(std::declval<T>()), false)>
|
|
|
|
{};
|
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_mem_generated_value<T>::value>::type>
|
|
|
|
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::declval<T>().generated_value(), false)>
|
|
|
|
{};
|
|
|
|
template<typename T>
|
2012-09-27 05:19:25 +00:00
|
|
|
struct noexcept_generated_value<T, typename std::enable_if<sprout_generator_detail::select_get_generated_value<T>::value>::type>
|
|
|
|
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(get<0>(std::declval<T>()), false)>
|
2012-09-21 06:43:30 +00:00
|
|
|
{};
|
|
|
|
|
|
|
|
template<typename T, typename = void>
|
|
|
|
struct generated_value_result;
|
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type> {
|
2012-09-21 06:43:30 +00:00
|
|
|
public:
|
2012-09-30 02:09:44 +00:00
|
|
|
typedef decltype(generated_value(std::declval<T>())) type;
|
2012-09-21 06:43:30 +00:00
|
|
|
};
|
|
|
|
template<typename T>
|
2012-09-30 02:09:44 +00:00
|
|
|
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_mem_generated_value<T>::value>::type> {
|
2012-09-26 09:42:43 +00:00
|
|
|
public:
|
2012-09-30 02:09:44 +00:00
|
|
|
typedef decltype(std::declval<T>().generated_value()) type;
|
2012-09-26 09:42:43 +00:00
|
|
|
};
|
|
|
|
template<typename T>
|
2012-09-27 05:19:25 +00:00
|
|
|
struct generated_value_result<T, typename std::enable_if<sprout_generator_detail::select_get_generated_value<T>::value>::type> {
|
2012-09-21 06:43:30 +00:00
|
|
|
public:
|
2012-09-27 05:19:25 +00:00
|
|
|
typedef decltype(get<0>(std::declval<T>())) type;
|
2012-09-21 06:43:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<
|
|
|
|
typename T,
|
2012-09-30 02:09:44 +00:00
|
|
|
typename sprout::enabler_if<sprout_generator_detail::select_adl_generated_value<T>::value>::type = sprout::enabler
|
2012-09-21 06:43:30 +00:00
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type
|
|
|
|
generated_value_impl(T&& t)
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value))
|
2012-09-21 06:43:30 +00:00
|
|
|
{
|
2012-09-30 02:09:44 +00:00
|
|
|
return generated_value(sprout::forward<T>(t));
|
2012-09-21 06:43:30 +00:00
|
|
|
}
|
2012-09-26 09:42:43 +00:00
|
|
|
template<
|
|
|
|
typename T,
|
2012-09-30 02:09:44 +00:00
|
|
|
typename sprout::enabler_if<sprout_generator_detail::select_mem_generated_value<T>::value>::type = sprout::enabler
|
2012-09-26 09:42:43 +00:00
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type
|
|
|
|
generated_value_impl(T&& t)
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value))
|
2012-09-26 09:42:43 +00:00
|
|
|
{
|
2012-09-30 02:09:44 +00:00
|
|
|
return sprout::forward<T>(t).generated_value();
|
2012-09-26 09:42:43 +00:00
|
|
|
}
|
2012-09-21 06:43:30 +00:00
|
|
|
template<
|
|
|
|
typename T,
|
2012-09-27 05:19:25 +00:00
|
|
|
typename sprout::enabler_if<sprout_generator_detail::select_get_generated_value<T>::value>::type = sprout::enabler
|
2012-09-21 06:43:30 +00:00
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type
|
|
|
|
generated_value_impl(T&& t)
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value))
|
2012-09-21 06:43:30 +00:00
|
|
|
{
|
2012-09-27 05:19:25 +00:00
|
|
|
return get<0>(sprout::forward<T>(t));
|
2012-09-21 06:43:30 +00:00
|
|
|
}
|
|
|
|
} // namespace sprout_generator_detail
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace generators {
|
|
|
|
//
|
|
|
|
// generated_value
|
|
|
|
//
|
|
|
|
template<typename T>
|
|
|
|
inline SPROUT_CONSTEXPR typename sprout_generator_detail::generated_value_result<T>::type
|
|
|
|
generated_value(T&& t)
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR((sprout_generator_detail::noexcept_generated_value<T>::value))
|
2012-09-21 06:43:30 +00:00
|
|
|
{
|
|
|
|
return sprout_generator_detail::generated_value_impl(sprout::forward<T>(t));
|
|
|
|
}
|
|
|
|
} // namespace generators
|
|
|
|
|
|
|
|
using sprout::generators::generated_value;
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_GENERATOR_GENERATED_VALUE_HPP
|