21
21
#include " asio/detail/push_options.hpp"
22
22
23
23
namespace asio {
24
-
25
- #if defined(ASIO_HAS_CONCEPTS)
26
-
27
24
namespace detail {
28
25
29
26
template <typename T>
@@ -70,6 +67,12 @@ struct are_completion_signatures : false_type
70
67
{
71
68
};
72
69
70
+ template <>
71
+ struct are_completion_signatures <>
72
+ : true_type
73
+ {
74
+ };
75
+
73
76
template <typename T0>
74
77
struct are_completion_signatures <T0>
75
78
: is_completion_signature<T0>
@@ -84,6 +87,12 @@ struct are_completion_signatures<T0, TN...>
84
87
{
85
88
};
86
89
90
+ } // namespace detail
91
+
92
+ #if defined(ASIO_HAS_CONCEPTS)
93
+
94
+ namespace detail {
95
+
87
96
template <typename T, typename ... Args>
88
97
ASIO_CONCEPT callable_with = requires(T&& t, Args&&... args)
89
98
{
@@ -606,14 +615,36 @@ template <typename CompletionToken,
606
615
typename Initiation, typename ... Args>
607
616
inline auto async_initiate (Initiation&& initiation,
608
617
type_identity_t <CompletionToken>& token, Args&&... args)
609
- -> constraint_t<
610
- detail::async_result_has_initiate_memfn<
611
- CompletionToken, Signatures...>::value,
612
- decltype(
613
- async_result<decay_t <CompletionToken>, Signatures...>::initiate(
614
- static_cast <Initiation&&>(initiation),
615
- static_cast<CompletionToken&&>(token),
616
- static_cast<Args&&>(args)...))>
618
+ -> decltype(enable_if_t <
619
+ enable_if_t <
620
+ detail::are_completion_signatures<Signatures...>::value,
621
+ detail::async_result_has_initiate_memfn<
622
+ CompletionToken, Signatures...>>::value,
623
+ async_result<decay_t <CompletionToken>, Signatures...>>::initiate(
624
+ static_cast <Initiation&&>(initiation),
625
+ static_cast<CompletionToken&&>(token),
626
+ static_cast<Args&&>(args)...))
627
+ {
628
+ return async_result<decay_t <CompletionToken>, Signatures...>::initiate (
629
+ static_cast <Initiation&&>(initiation),
630
+ static_cast <CompletionToken&&>(token),
631
+ static_cast <Args&&>(args)...);
632
+ }
633
+
634
+ template <
635
+ ASIO_COMPLETION_SIGNATURE... Signatures,
636
+ typename CompletionToken, typename Initiation, typename ... Args>
637
+ inline auto async_initiate (Initiation&& initiation,
638
+ CompletionToken&& token, Args&&... args)
639
+ -> decltype(enable_if_t <
640
+ enable_if_t <
641
+ detail::are_completion_signatures<Signatures...>::value,
642
+ detail::async_result_has_initiate_memfn<
643
+ CompletionToken, Signatures...>>::value,
644
+ async_result<decay_t <CompletionToken>, Signatures...>>::initiate(
645
+ static_cast <Initiation&&>(initiation),
646
+ static_cast<CompletionToken&&>(token),
647
+ static_cast<Args&&>(args)...))
617
648
{
618
649
return async_result<decay_t <CompletionToken>, Signatures...>::initiate (
619
650
static_cast <Initiation&&>(initiation),
@@ -624,10 +655,13 @@ inline auto async_initiate(Initiation&& initiation,
624
655
template <typename CompletionToken,
625
656
ASIO_COMPLETION_SIGNATURE... Signatures,
626
657
typename Initiation, typename ... Args>
627
- inline constraint_t <
628
- !detail::async_result_has_initiate_memfn<
629
- CompletionToken, Signatures...>::value,
630
- typename async_result<decay_t <CompletionToken>, Signatures...>::return_type>
658
+ inline typename enable_if_t <
659
+ !enable_if_t <
660
+ detail::are_completion_signatures<Signatures...>::value,
661
+ detail::async_result_has_initiate_memfn<
662
+ CompletionToken, Signatures...>>::value,
663
+ async_result<decay_t <CompletionToken>, Signatures...>
664
+ >::return_type
631
665
async_initiate (Initiation&& initiation,
632
666
type_identity_t <CompletionToken>& token, Args&&... args)
633
667
{
@@ -643,6 +677,29 @@ async_initiate(Initiation&& initiation,
643
677
return completion.result .get ();
644
678
}
645
679
680
+ template <ASIO_COMPLETION_SIGNATURE... Signatures,
681
+ typename CompletionToken, typename Initiation, typename ... Args>
682
+ inline typename enable_if_t <
683
+ !enable_if_t <
684
+ detail::are_completion_signatures<Signatures...>::value,
685
+ detail::async_result_has_initiate_memfn<
686
+ CompletionToken, Signatures...>>::value,
687
+ async_result<decay_t <CompletionToken>, Signatures...>
688
+ >::return_type
689
+ async_initiate (Initiation&& initiation, CompletionToken&& token, Args&&... args)
690
+ {
691
+ async_completion<CompletionToken, Signatures...> completion (token);
692
+
693
+ static_cast <Initiation&&>(initiation)(
694
+ static_cast <
695
+ typename async_result<decay_t <CompletionToken>,
696
+ Signatures...>::completion_handler_type&&>(
697
+ completion.completion_handler ),
698
+ static_cast <Args&&>(args)...);
699
+
700
+ return completion.result .get ();
701
+ }
702
+
646
703
#endif // defined(GENERATING_DOCUMENTATION)
647
704
648
705
#if defined(ASIO_HAS_CONCEPTS)
@@ -882,61 +939,10 @@ template <typename T, typename... Args>
882
939
using completion_signature_of_t =
883
940
typename completion_signature_of<T, Args...>::type;
884
941
885
- namespace detail {
886
-
887
- template <typename T, typename = void >
888
- struct default_completion_token_impl
889
- {
890
- typedef void type;
891
- };
892
-
893
- template <typename T>
894
- struct default_completion_token_impl <T,
895
- void_t <typename T::default_completion_token_type>
896
- >
897
- {
898
- typedef typename T::default_completion_token_type type;
899
- };
900
-
901
- } // namespace detail
902
-
903
- #if defined(GENERATING_DOCUMENTATION)
904
-
905
- // / Traits type used to determine the default completion token type associated
906
- // / with a type (such as an executor).
907
- /* *
908
- * A program may specialise this traits type if the @c T template parameter in
909
- * the specialisation is a user-defined type.
910
- *
911
- * Specialisations of this trait may provide a nested typedef @c type, which is
912
- * a default-constructible completion token type.
913
- */
914
- template <typename T>
915
- struct default_completion_token
916
- {
917
- // / If @c T has a nested type @c default_completion_token_type,
918
- // / <tt>T::default_completion_token_type</tt>. Otherwise the typedef @c type
919
- // / is not defined.
920
- typedef see_below type;
921
- };
922
- #else
923
- template <typename T>
924
- struct default_completion_token
925
- : detail::default_completion_token_impl<T>
926
- {
927
- };
928
- #endif
929
-
930
- template <typename T>
931
- using default_completion_token_t = typename default_completion_token<T>::type;
932
-
933
- #define ASIO_DEFAULT_COMPLETION_TOKEN_TYPE (e ) \
934
- = typename ::asio::default_completion_token<e>::type
935
- #define ASIO_DEFAULT_COMPLETION_TOKEN (e ) \
936
- = typename ::asio::default_completion_token<e>::type()
937
-
938
942
} // namespace asio
939
943
940
944
#include " asio/detail/pop_options.hpp"
941
945
946
+ #include " asio/default_completion_token.hpp"
947
+
942
948
#endif // ASIO_ASYNC_RESULT_HPP
0 commit comments