Skip to content

Commit

Permalink
Add friendship support to execution::blocking_adaptation property.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskohlhoff committed Jan 7, 2021
1 parent 55df450 commit 0106229
Showing 1 changed file with 127 additions and 51 deletions.
178 changes: 127 additions & 51 deletions asio/include/asio/execution/blocking_adaptation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,32 +202,85 @@ struct blocking_adaptation_t
{
}

template <typename T>
struct proxy
{
#if defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
struct type
{
template <typename P>
auto query(ASIO_MOVE_ARG(P) p) const
noexcept(
noexcept(
declval<typename conditional<true, T, P>::type>().query(
ASIO_MOVE_CAST(P)(p))
)
)
-> decltype(
declval<typename conditional<true, T, P>::type>().query(
ASIO_MOVE_CAST(P)(p))
);
};
#else // defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
typedef T type;
#endif // defined(ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
};

template <typename T>
struct static_proxy
{
#if defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
struct type
{
template <typename P>
static constexpr auto query(ASIO_MOVE_ARG(P) p)
noexcept(
noexcept(
conditional<true, T, P>::type::query(ASIO_MOVE_CAST(P)(p))
)
)
-> decltype(
conditional<true, T, P>::type::query(ASIO_MOVE_CAST(P)(p))
)
{
return T::query(ASIO_MOVE_CAST(P)(p));
}
};
#else // defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
typedef T type;
#endif // defined(ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
};

template <typename T>
struct query_member :
traits::query_member<typename proxy<T>::type, blocking_adaptation_t> {};

template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename static_proxy<T>::type, blocking_adaptation_t> {};

#if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static ASIO_CONSTEXPR
typename traits::query_static_constexpr_member<
T, blocking_adaptation_t>::result_type
typename query_static_constexpr_member<T>::result_type
static_query()
ASIO_NOEXCEPT_IF((
traits::query_static_constexpr_member<
T, blocking_adaptation_t
>::is_noexcept))
query_static_constexpr_member<T>::is_noexcept))
{
return traits::query_static_constexpr_member<
T, blocking_adaptation_t>::value();
return query_static_constexpr_member<T>::value();
}

template <typename T>
static ASIO_CONSTEXPR
typename traits::static_query<T, disallowed_t>::result_type
static_query(
typename enable_if<
!traits::query_static_constexpr_member<
T, blocking_adaptation_t>::is_valid
!query_static_constexpr_member<T>::is_valid
>::type* = 0,
typename enable_if<
!traits::query_member<T, blocking_adaptation_t>::is_valid
!query_member<T>::is_valid
>::type* = 0,
typename enable_if<
traits::static_query<T, disallowed_t>::is_valid
Expand All @@ -241,11 +294,10 @@ struct blocking_adaptation_t
typename traits::static_query<T, allowed_t>::result_type
static_query(
typename enable_if<
!traits::query_static_constexpr_member<
T, blocking_adaptation_t>::is_valid
!query_static_constexpr_member<T>::is_valid
>::type* = 0,
typename enable_if<
!traits::query_member<T, blocking_adaptation_t>::is_valid
!query_member<T>::is_valid
>::type* = 0,
typename enable_if<
!traits::static_query<T, disallowed_t>::is_valid
Expand Down Expand Up @@ -388,25 +440,37 @@ struct disallowed_t
{
}

template <typename T>
struct query_member :
traits::query_member<
typename blocking_adaptation_t<I>::template proxy<T>::type,
disallowed_t> {};

template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename blocking_adaptation_t<I>::template static_proxy<T>::type,
disallowed_t> {};

#if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static ASIO_CONSTEXPR
typename traits::query_static_constexpr_member<T, disallowed_t>::result_type
typename query_static_constexpr_member<T>::result_type
static_query()
ASIO_NOEXCEPT_IF((
traits::query_static_constexpr_member<T, disallowed_t>::is_noexcept))
query_static_constexpr_member<T>::is_noexcept))
{
return traits::query_static_constexpr_member<T, disallowed_t>::value();
return query_static_constexpr_member<T>::value();
}

template <typename T>
static ASIO_CONSTEXPR disallowed_t static_query(
typename enable_if<
!traits::query_static_constexpr_member<T, disallowed_t>::is_valid
!query_static_constexpr_member<T>::is_valid
>::type* = 0,
typename enable_if<
!traits::query_member<T, disallowed_t>::is_valid
!query_member<T>::is_valid
>::type* = 0,
typename enable_if<
!traits::query_free<T, disallowed_t>::is_valid
Expand Down Expand Up @@ -588,16 +652,28 @@ struct allowed_t
{
}

template <typename T>
struct query_member :
traits::query_member<
typename blocking_adaptation_t<I>::template proxy<T>::type,
allowed_t> {};

template <typename T>
struct query_static_constexpr_member :
traits::query_static_constexpr_member<
typename blocking_adaptation_t<I>::template static_proxy<T>::type,
allowed_t> {};

#if defined(ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
&& defined(ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
template <typename T>
static ASIO_CONSTEXPR
typename traits::query_static_constexpr_member<T, allowed_t>::result_type
typename query_static_constexpr_member<T>::result_type
static_query()
ASIO_NOEXCEPT_IF((
traits::query_static_constexpr_member<T, allowed_t>::is_noexcept))
query_static_constexpr_member<T>::is_noexcept))
{
return traits::query_static_constexpr_member<T, allowed_t>::value();
return query_static_constexpr_member<T>::value();
}

template <typename E, typename T = decltype(allowed_t::static_query<E>())>
Expand Down Expand Up @@ -809,30 +885,30 @@ struct query_free_default<T, execution::blocking_adaptation_t,
template <typename T>
struct static_query<T, execution::blocking_adaptation_t,
typename enable_if<
traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t>::is_valid
execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::is_valid
>::type>
{
ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);

typedef typename traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t>::result_type result_type;
typedef typename execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::result_type result_type;

static ASIO_CONSTEXPR result_type value()
{
return traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t>::value();
return execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::value();
}
};

template <typename T>
struct static_query<T, execution::blocking_adaptation_t,
typename enable_if<
!traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t>::is_valid
&& !traits::query_member<T,
execution::blocking_adaptation_t>::is_valid
!execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking_adaptation_t<0>::
query_member<T>::is_valid
&& traits::static_query<T,
execution::blocking_adaptation_t::disallowed_t>::is_valid
>::type>
Expand All @@ -853,10 +929,10 @@ struct static_query<T, execution::blocking_adaptation_t,
template <typename T>
struct static_query<T, execution::blocking_adaptation_t,
typename enable_if<
!traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t>::is_valid
&& !traits::query_member<T,
execution::blocking_adaptation_t>::is_valid
!execution::detail::blocking_adaptation_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking_adaptation_t<0>::
query_member<T>::is_valid
&& !traits::static_query<T,
execution::blocking_adaptation_t::disallowed_t>::is_valid
&& traits::static_query<T,
Expand All @@ -879,30 +955,30 @@ struct static_query<T, execution::blocking_adaptation_t,
template <typename T>
struct static_query<T, execution::blocking_adaptation_t::disallowed_t,
typename enable_if<
traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t::disallowed_t>::is_valid
execution::detail::blocking_adaptation::disallowed_t<0>::
query_static_constexpr_member<T>::is_valid
>::type>
{
ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);

typedef typename traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t::disallowed_t>::result_type result_type;
typedef typename execution::detail::blocking_adaptation::disallowed_t<0>::
query_static_constexpr_member<T>::result_type result_type;

static ASIO_CONSTEXPR result_type value()
{
return traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t::disallowed_t>::value();
return execution::detail::blocking_adaptation::disallowed_t<0>::
query_static_constexpr_member<T>::value();
}
};

template <typename T>
struct static_query<T, execution::blocking_adaptation_t::disallowed_t,
typename enable_if<
!traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t::disallowed_t>::is_valid
&& !traits::query_member<T,
execution::blocking_adaptation_t::disallowed_t>::is_valid
!execution::detail::blocking_adaptation::disallowed_t<0>::
query_static_constexpr_member<T>::is_valid
&& !execution::detail::blocking_adaptation::disallowed_t<0>::
query_member<T>::is_valid
&& !traits::query_free<T,
execution::blocking_adaptation_t::disallowed_t>::is_valid
&& !can_query<T, execution::blocking_adaptation_t::allowed_t>::value
Expand All @@ -922,20 +998,20 @@ struct static_query<T, execution::blocking_adaptation_t::disallowed_t,
template <typename T>
struct static_query<T, execution::blocking_adaptation_t::allowed_t,
typename enable_if<
traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t::allowed_t>::is_valid
execution::detail::blocking_adaptation::allowed_t<0>::
query_static_constexpr_member<T>::is_valid
>::type>
{
ASIO_STATIC_CONSTEXPR(bool, is_valid = true);
ASIO_STATIC_CONSTEXPR(bool, is_noexcept = true);

typedef typename traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t::allowed_t>::result_type result_type;
typedef typename execution::detail::blocking_adaptation::allowed_t<0>::
query_static_constexpr_member<T>::result_type result_type;

static ASIO_CONSTEXPR result_type value()
{
return traits::query_static_constexpr_member<T,
execution::blocking_adaptation_t::allowed_t>::value();
return execution::detail::blocking_adaptation::allowed_t<0>::
query_static_constexpr_member<T>::value();
}
};

Expand Down

0 comments on commit 0106229

Please sign in to comment.