File indexing completed on 2025-12-16 09:43:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_EXECUTION_RELATIONSHIP_HPP
0012 #define BOOST_ASIO_EXECUTION_RELATIONSHIP_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/type_traits.hpp>
0020 #include <boost/asio/execution/executor.hpp>
0021 #include <boost/asio/is_applicable_property.hpp>
0022 #include <boost/asio/query.hpp>
0023 #include <boost/asio/traits/query_free.hpp>
0024 #include <boost/asio/traits/query_member.hpp>
0025 #include <boost/asio/traits/query_static_constexpr_member.hpp>
0026 #include <boost/asio/traits/static_query.hpp>
0027 #include <boost/asio/traits/static_require.hpp>
0028
0029 #include <boost/asio/detail/push_options.hpp>
0030
0031 namespace boost {
0032 namespace asio {
0033
0034 #if defined(GENERATING_DOCUMENTATION)
0035
0036 namespace execution {
0037
0038
0039
0040 struct relationship_t
0041 {
0042
0043 template <typename T>
0044 static constexpr bool is_applicable_property_v = is_executor_v<T>;
0045
0046
0047 static constexpr bool is_requirable = false;
0048
0049
0050 static constexpr bool is_preferable = false;
0051
0052
0053 typedef relationship_t polymorphic_query_result_type;
0054
0055
0056
0057 struct fork_t
0058 {
0059
0060 template <typename T>
0061 static constexpr bool is_applicable_property_v = is_executor_v<T>;
0062
0063
0064 static constexpr bool is_requirable = true;
0065
0066
0067 static constexpr bool is_preferable = true;
0068
0069
0070 typedef relationship_t polymorphic_query_result_type;
0071
0072
0073 constexpr fork_t();
0074
0075
0076
0077
0078
0079 static constexpr relationship_t value();
0080 };
0081
0082
0083
0084 struct continuation_t
0085 {
0086
0087 template <typename T>
0088 static constexpr bool is_applicable_property_v = is_executor_v<T>;
0089
0090
0091 static constexpr bool is_requirable = true;
0092
0093
0094 static constexpr bool is_preferable = true;
0095
0096
0097 typedef relationship_t polymorphic_query_result_type;
0098
0099
0100 constexpr continuation_t();
0101
0102
0103
0104
0105
0106 static constexpr relationship_t value();
0107 };
0108
0109
0110 static constexpr fork_t fork;
0111
0112
0113
0114 static constexpr continuation_t continuation;
0115
0116
0117 constexpr relationship_t();
0118
0119
0120 constexpr relationship_t(fork_t);
0121
0122
0123 constexpr relationship_t(continuation_t);
0124
0125
0126 friend constexpr bool operator==(
0127 const relationship_t& a, const relationship_t& b) noexcept;
0128
0129
0130 friend constexpr bool operator!=(
0131 const relationship_t& a, const relationship_t& b) noexcept;
0132 };
0133
0134
0135 constexpr relationship_t relationship;
0136
0137 }
0138
0139 #else
0140
0141 namespace execution {
0142 namespace detail {
0143 namespace relationship {
0144
0145 template <int I> struct fork_t;
0146 template <int I> struct continuation_t;
0147
0148 }
0149
0150 template <int I = 0>
0151 struct relationship_t
0152 {
0153 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0154 template <typename T>
0155 static constexpr bool is_applicable_property_v = is_executor<T>::value;
0156 #endif
0157
0158 static constexpr bool is_requirable = false;
0159 static constexpr bool is_preferable = false;
0160 typedef relationship_t polymorphic_query_result_type;
0161
0162 typedef detail::relationship::fork_t<I> fork_t;
0163 typedef detail::relationship::continuation_t<I> continuation_t;
0164
0165 constexpr relationship_t()
0166 : value_(-1)
0167 {
0168 }
0169
0170 constexpr relationship_t(fork_t)
0171 : value_(0)
0172 {
0173 }
0174
0175 constexpr relationship_t(continuation_t)
0176 : value_(1)
0177 {
0178 }
0179
0180 template <typename T>
0181 struct proxy
0182 {
0183 #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_MEMBER_TRAIT)
0184 struct type
0185 {
0186 template <typename P>
0187 auto query(P&& p) const
0188 noexcept(
0189 noexcept(
0190 declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
0191 )
0192 )
0193 -> decltype(
0194 declval<conditional_t<true, T, P>>().query(static_cast<P&&>(p))
0195 );
0196 };
0197 #else
0198 typedef T type;
0199 #endif
0200 };
0201
0202 template <typename T>
0203 struct static_proxy
0204 {
0205 #if defined(BOOST_ASIO_HAS_DEDUCED_QUERY_STATIC_CONSTEXPR_MEMBER_TRAIT)
0206 struct type
0207 {
0208 template <typename P>
0209 static constexpr auto query(P&& p)
0210 noexcept(
0211 noexcept(
0212 conditional_t<true, T, P>::query(static_cast<P&&>(p))
0213 )
0214 )
0215 -> decltype(
0216 conditional_t<true, T, P>::query(static_cast<P&&>(p))
0217 )
0218 {
0219 return T::query(static_cast<P&&>(p));
0220 }
0221 };
0222 #else
0223 typedef T type;
0224 #endif
0225 };
0226
0227 template <typename T>
0228 struct query_member :
0229 traits::query_member<typename proxy<T>::type, relationship_t> {};
0230
0231 template <typename T>
0232 struct query_static_constexpr_member :
0233 traits::query_static_constexpr_member<
0234 typename static_proxy<T>::type, relationship_t> {};
0235
0236 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0237 && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0238 template <typename T>
0239 static constexpr
0240 typename query_static_constexpr_member<T>::result_type
0241 static_query()
0242 noexcept(query_static_constexpr_member<T>::is_noexcept)
0243 {
0244 return query_static_constexpr_member<T>::value();
0245 }
0246
0247 template <typename T>
0248 static constexpr
0249 typename traits::static_query<T, fork_t>::result_type
0250 static_query(
0251 enable_if_t<
0252 !query_static_constexpr_member<T>::is_valid
0253 >* = 0,
0254 enable_if_t<
0255 !query_member<T>::is_valid
0256 >* = 0,
0257 enable_if_t<
0258 traits::static_query<T, fork_t>::is_valid
0259 >* = 0) noexcept
0260 {
0261 return traits::static_query<T, fork_t>::value();
0262 }
0263
0264 template <typename T>
0265 static constexpr
0266 typename traits::static_query<T, continuation_t>::result_type
0267 static_query(
0268 enable_if_t<
0269 !query_static_constexpr_member<T>::is_valid
0270 >* = 0,
0271 enable_if_t<
0272 !query_member<T>::is_valid
0273 >* = 0,
0274 enable_if_t<
0275 !traits::static_query<T, fork_t>::is_valid
0276 >* = 0,
0277 enable_if_t<
0278 traits::static_query<T, continuation_t>::is_valid
0279 >* = 0) noexcept
0280 {
0281 return traits::static_query<T, continuation_t>::value();
0282 }
0283
0284 template <typename E,
0285 typename T = decltype(relationship_t::static_query<E>())>
0286 static constexpr const T static_query_v
0287 = relationship_t::static_query<E>();
0288 #endif
0289
0290
0291 friend constexpr bool operator==(
0292 const relationship_t& a, const relationship_t& b)
0293 {
0294 return a.value_ == b.value_;
0295 }
0296
0297 friend constexpr bool operator!=(
0298 const relationship_t& a, const relationship_t& b)
0299 {
0300 return a.value_ != b.value_;
0301 }
0302
0303 struct convertible_from_relationship_t
0304 {
0305 constexpr convertible_from_relationship_t(relationship_t)
0306 {
0307 }
0308 };
0309
0310 template <typename Executor>
0311 friend constexpr relationship_t query(
0312 const Executor& ex, convertible_from_relationship_t,
0313 enable_if_t<
0314 can_query<const Executor&, fork_t>::value
0315 >* = 0)
0316 #if !defined(__clang__)
0317 #if defined(BOOST_ASIO_MSVC)
0318 noexcept(is_nothrow_query<const Executor&, relationship_t<>::fork_t>::value)
0319 #else
0320 noexcept(is_nothrow_query<const Executor&, fork_t>::value)
0321 #endif
0322 #endif
0323 {
0324 return boost::asio::query(ex, fork_t());
0325 }
0326
0327 template <typename Executor>
0328 friend constexpr relationship_t query(
0329 const Executor& ex, convertible_from_relationship_t,
0330 enable_if_t<
0331 !can_query<const Executor&, fork_t>::value
0332 >* = 0,
0333 enable_if_t<
0334 can_query<const Executor&, continuation_t>::value
0335 >* = 0)
0336 #if !defined(__clang__)
0337 #if defined(BOOST_ASIO_MSVC)
0338 noexcept(is_nothrow_query<const Executor&,
0339 relationship_t<>::continuation_t>::value)
0340 #else
0341 noexcept(is_nothrow_query<const Executor&, continuation_t>::value)
0342 #endif
0343 #endif
0344 {
0345 return boost::asio::query(ex, continuation_t());
0346 }
0347
0348 BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(fork_t, fork);
0349 BOOST_ASIO_STATIC_CONSTEXPR_DEFAULT_INIT(continuation_t, continuation);
0350
0351 private:
0352 int value_;
0353 };
0354
0355 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0356 && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0357 template <int I> template <typename E, typename T>
0358 const T relationship_t<I>::static_query_v;
0359 #endif
0360
0361
0362 template <int I>
0363 const typename relationship_t<I>::fork_t relationship_t<I>::fork;
0364
0365 template <int I>
0366 const typename relationship_t<I>::continuation_t
0367 relationship_t<I>::continuation;
0368
0369 namespace relationship {
0370
0371 template <int I = 0>
0372 struct fork_t
0373 {
0374 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0375 template <typename T>
0376 static constexpr bool is_applicable_property_v = is_executor<T>::value;
0377 #endif
0378
0379 static constexpr bool is_requirable = true;
0380 static constexpr bool is_preferable = true;
0381 typedef relationship_t<I> polymorphic_query_result_type;
0382
0383 constexpr fork_t()
0384 {
0385 }
0386
0387 template <typename T>
0388 struct query_member :
0389 traits::query_member<
0390 typename relationship_t<I>::template proxy<T>::type, fork_t> {};
0391
0392 template <typename T>
0393 struct query_static_constexpr_member :
0394 traits::query_static_constexpr_member<
0395 typename relationship_t<I>::template static_proxy<T>::type, fork_t> {};
0396
0397 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0398 && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0399 template <typename T>
0400 static constexpr typename query_static_constexpr_member<T>::result_type
0401 static_query()
0402 noexcept(query_static_constexpr_member<T>::is_noexcept)
0403 {
0404 return query_static_constexpr_member<T>::value();
0405 }
0406
0407 template <typename T>
0408 static constexpr fork_t static_query(
0409 enable_if_t<
0410 !query_static_constexpr_member<T>::is_valid
0411 >* = 0,
0412 enable_if_t<
0413 !query_member<T>::is_valid
0414 >* = 0,
0415 enable_if_t<
0416 !traits::query_free<T, fork_t>::is_valid
0417 >* = 0,
0418 enable_if_t<
0419 !can_query<T, continuation_t<I>>::value
0420 >* = 0) noexcept
0421 {
0422 return fork_t();
0423 }
0424
0425 template <typename E, typename T = decltype(fork_t::static_query<E>())>
0426 static constexpr const T static_query_v
0427 = fork_t::static_query<E>();
0428 #endif
0429
0430
0431 static constexpr relationship_t<I> value()
0432 {
0433 return fork_t();
0434 }
0435
0436 friend constexpr bool operator==(const fork_t&, const fork_t&)
0437 {
0438 return true;
0439 }
0440
0441 friend constexpr bool operator!=(const fork_t&, const fork_t&)
0442 {
0443 return false;
0444 }
0445
0446 friend constexpr bool operator==(const fork_t&, const continuation_t<I>&)
0447 {
0448 return false;
0449 }
0450
0451 friend constexpr bool operator!=(const fork_t&, const continuation_t<I>&)
0452 {
0453 return true;
0454 }
0455 };
0456
0457 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0458 && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0459 template <int I> template <typename E, typename T>
0460 const T fork_t<I>::static_query_v;
0461 #endif
0462
0463
0464 template <int I = 0>
0465 struct continuation_t
0466 {
0467 #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0468 template <typename T>
0469 static constexpr bool is_applicable_property_v = is_executor<T>::value;
0470 #endif
0471
0472 static constexpr bool is_requirable = true;
0473 static constexpr bool is_preferable = true;
0474 typedef relationship_t<I> polymorphic_query_result_type;
0475
0476 constexpr continuation_t()
0477 {
0478 }
0479
0480 template <typename T>
0481 struct query_member :
0482 traits::query_member<
0483 typename relationship_t<I>::template proxy<T>::type, continuation_t> {};
0484
0485 template <typename T>
0486 struct query_static_constexpr_member :
0487 traits::query_static_constexpr_member<
0488 typename relationship_t<I>::template static_proxy<T>::type,
0489 continuation_t> {};
0490
0491 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0492 && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0493 template <typename T>
0494 static constexpr typename query_static_constexpr_member<T>::result_type
0495 static_query()
0496 noexcept(query_static_constexpr_member<T>::is_noexcept)
0497 {
0498 return query_static_constexpr_member<T>::value();
0499 }
0500
0501 template <typename E,
0502 typename T = decltype(continuation_t::static_query<E>())>
0503 static constexpr const T static_query_v
0504 = continuation_t::static_query<E>();
0505 #endif
0506
0507
0508 static constexpr relationship_t<I> value()
0509 {
0510 return continuation_t();
0511 }
0512
0513 friend constexpr bool operator==(const continuation_t&, const continuation_t&)
0514 {
0515 return true;
0516 }
0517
0518 friend constexpr bool operator!=(const continuation_t&, const continuation_t&)
0519 {
0520 return false;
0521 }
0522
0523 friend constexpr bool operator==(const continuation_t&, const fork_t<I>&)
0524 {
0525 return false;
0526 }
0527
0528 friend constexpr bool operator!=(const continuation_t&, const fork_t<I>&)
0529 {
0530 return true;
0531 }
0532 };
0533
0534 #if defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0535 && defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0536 template <int I> template <typename E, typename T>
0537 const T continuation_t<I>::static_query_v;
0538 #endif
0539
0540
0541 }
0542 }
0543
0544 typedef detail::relationship_t<> relationship_t;
0545
0546 BOOST_ASIO_INLINE_VARIABLE constexpr relationship_t relationship;
0547
0548 }
0549
0550 #if !defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
0551
0552 template <typename T>
0553 struct is_applicable_property<T, execution::relationship_t>
0554 : integral_constant<bool, execution::is_executor<T>::value>
0555 {
0556 };
0557
0558 template <typename T>
0559 struct is_applicable_property<T, execution::relationship_t::fork_t>
0560 : integral_constant<bool, execution::is_executor<T>::value>
0561 {
0562 };
0563
0564 template <typename T>
0565 struct is_applicable_property<T, execution::relationship_t::continuation_t>
0566 : integral_constant<bool, execution::is_executor<T>::value>
0567 {
0568 };
0569
0570 #endif
0571
0572 namespace traits {
0573
0574 #if !defined(BOOST_ASIO_HAS_DEDUCED_QUERY_FREE_TRAIT)
0575
0576 template <typename T>
0577 struct query_free_default<T, execution::relationship_t,
0578 enable_if_t<
0579 can_query<T, execution::relationship_t::fork_t>::value
0580 >>
0581 {
0582 static constexpr bool is_valid = true;
0583 static constexpr bool is_noexcept =
0584 is_nothrow_query<T, execution::relationship_t::fork_t>::value;
0585
0586 typedef execution::relationship_t result_type;
0587 };
0588
0589 template <typename T>
0590 struct query_free_default<T, execution::relationship_t,
0591 enable_if_t<
0592 !can_query<T, execution::relationship_t::fork_t>::value
0593 && can_query<T, execution::relationship_t::continuation_t>::value
0594 >>
0595 {
0596 static constexpr bool is_valid = true;
0597 static constexpr bool is_noexcept =
0598 is_nothrow_query<T, execution::relationship_t::continuation_t>::value;
0599
0600 typedef execution::relationship_t result_type;
0601 };
0602
0603 #endif
0604
0605 #if !defined(BOOST_ASIO_HAS_DEDUCED_STATIC_QUERY_TRAIT) \
0606 || !defined(BOOST_ASIO_HAS_SFINAE_VARIABLE_TEMPLATES)
0607
0608 template <typename T>
0609 struct static_query<T, execution::relationship_t,
0610 enable_if_t<
0611 execution::detail::relationship_t<0>::
0612 query_static_constexpr_member<T>::is_valid
0613 >>
0614 {
0615 static constexpr bool is_valid = true;
0616 static constexpr bool is_noexcept = true;
0617
0618 typedef typename execution::detail::relationship_t<0>::
0619 query_static_constexpr_member<T>::result_type result_type;
0620
0621 static constexpr result_type value()
0622 {
0623 return execution::detail::relationship_t<0>::
0624 query_static_constexpr_member<T>::value();
0625 }
0626 };
0627
0628 template <typename T>
0629 struct static_query<T, execution::relationship_t,
0630 enable_if_t<
0631 !execution::detail::relationship_t<0>::
0632 query_static_constexpr_member<T>::is_valid
0633 && !execution::detail::relationship_t<0>::
0634 query_member<T>::is_valid
0635 && traits::static_query<T,
0636 execution::relationship_t::fork_t>::is_valid
0637 >>
0638 {
0639 static constexpr bool is_valid = true;
0640 static constexpr bool is_noexcept = true;
0641
0642 typedef typename traits::static_query<T,
0643 execution::relationship_t::fork_t>::result_type result_type;
0644
0645 static constexpr result_type value()
0646 {
0647 return traits::static_query<T,
0648 execution::relationship_t::fork_t>::value();
0649 }
0650 };
0651
0652 template <typename T>
0653 struct static_query<T, execution::relationship_t,
0654 enable_if_t<
0655 !execution::detail::relationship_t<0>::
0656 query_static_constexpr_member<T>::is_valid
0657 && !execution::detail::relationship_t<0>::
0658 query_member<T>::is_valid
0659 && !traits::static_query<T,
0660 execution::relationship_t::fork_t>::is_valid
0661 && traits::static_query<T,
0662 execution::relationship_t::continuation_t>::is_valid
0663 >>
0664 {
0665 static constexpr bool is_valid = true;
0666 static constexpr bool is_noexcept = true;
0667
0668 typedef typename traits::static_query<T,
0669 execution::relationship_t::continuation_t>::result_type result_type;
0670
0671 static constexpr result_type value()
0672 {
0673 return traits::static_query<T,
0674 execution::relationship_t::continuation_t>::value();
0675 }
0676 };
0677
0678 template <typename T>
0679 struct static_query<T, execution::relationship_t::fork_t,
0680 enable_if_t<
0681 execution::detail::relationship::fork_t<0>::
0682 query_static_constexpr_member<T>::is_valid
0683 >>
0684 {
0685 static constexpr bool is_valid = true;
0686 static constexpr bool is_noexcept = true;
0687
0688 typedef typename execution::detail::relationship::fork_t<0>::
0689 query_static_constexpr_member<T>::result_type result_type;
0690
0691 static constexpr result_type value()
0692 {
0693 return execution::detail::relationship::fork_t<0>::
0694 query_static_constexpr_member<T>::value();
0695 }
0696 };
0697
0698 template <typename T>
0699 struct static_query<T, execution::relationship_t::fork_t,
0700 enable_if_t<
0701 !execution::detail::relationship::fork_t<0>::
0702 query_static_constexpr_member<T>::is_valid
0703 && !execution::detail::relationship::fork_t<0>::
0704 query_member<T>::is_valid
0705 && !traits::query_free<T,
0706 execution::relationship_t::fork_t>::is_valid
0707 && !can_query<T, execution::relationship_t::continuation_t>::value
0708 >>
0709 {
0710 static constexpr bool is_valid = true;
0711 static constexpr bool is_noexcept = true;
0712
0713 typedef execution::relationship_t::fork_t result_type;
0714
0715 static constexpr result_type value()
0716 {
0717 return result_type();
0718 }
0719 };
0720
0721 template <typename T>
0722 struct static_query<T, execution::relationship_t::continuation_t,
0723 enable_if_t<
0724 execution::detail::relationship::continuation_t<0>::
0725 query_static_constexpr_member<T>::is_valid
0726 >>
0727 {
0728 static constexpr bool is_valid = true;
0729 static constexpr bool is_noexcept = true;
0730
0731 typedef typename execution::detail::relationship::continuation_t<0>::
0732 query_static_constexpr_member<T>::result_type result_type;
0733
0734 static constexpr result_type value()
0735 {
0736 return execution::detail::relationship::continuation_t<0>::
0737 query_static_constexpr_member<T>::value();
0738 }
0739 };
0740
0741 #endif
0742
0743
0744 }
0745
0746 #endif
0747
0748 }
0749 }
0750
0751 #include <boost/asio/detail/pop_options.hpp>
0752
0753 #endif