1 /*
2  * Copyright (c) 2021-2024 NVIDIA Corporation
3  *
4  * Licensed under the Apache License Version 2.0 with LLVM Exceptions
5  * (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  *
8  *   https://llvm.org/LICENSE.txt
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include "__meta.hpp"
19 
20 namespace stdexec
21 {
22 namespace __detail
23 {
24 template <class _Ty>
25 extern __q<__midentity> __name_of_v;
26 
27 template <class _Ty>
28 using __name_of_fn = decltype(__name_of_v<_Ty>);
29 
30 template <class _Ty>
31 using __name_of = __minvoke<__name_of_fn<_Ty>, _Ty>;
32 } // namespace __detail
33 
34 // A utility for pretty-printing type names in diagnostics
35 template <class _Ty>
36 using __name_of = __detail::__name_of<_Ty>;
37 
38 namespace __errs
39 {
40 inline constexpr __mstring __unrecognized_sender_type_diagnostic =
41     "The given type cannot be used as a sender with the given environment "
42     "because the attempt to compute the completion signatures failed."_mstr;
43 
44 template <class _Sender>
45 struct _WITH_SENDER_;
46 
47 template <class... _Senders>
48 struct _WITH_SENDERS_;
49 } // namespace __errs
50 
51 struct _WHERE_;
52 
53 struct _IN_ALGORITHM_;
54 
55 template <__mstring _Diagnostic = __errs::__unrecognized_sender_type_diagnostic>
56 struct _UNRECOGNIZED_SENDER_TYPE_;
57 
58 template <class _Sender>
59 using _WITH_SENDER_ = __errs::_WITH_SENDER_<__name_of<_Sender>>;
60 
61 template <class... _Senders>
62 using _WITH_SENDERS_ = __errs::_WITH_SENDERS_<__name_of<_Senders>...>;
63 
64 template <class _Env>
65 struct _WITH_ENVIRONMENT_;
66 
67 template <class _Ty>
68 struct _WITH_TYPE_;
69 
70 template <class _Receiver>
71 struct _WITH_RECEIVER_;
72 
73 template <class _Sig>
74 struct _MISSING_COMPLETION_SIGNAL_;
75 
76 template <class _Sig>
77 struct _WITH_COMPLETION_SIGNATURE_;
78 
79 template <class _Fun>
80 struct _WITH_FUNCTION_;
81 
82 template <class... _Args>
83 struct _WITH_ARGUMENTS_;
84 
85 template <class _Tag>
86 struct _WITH_QUERY_;
87 
88 struct _SENDER_TYPE_IS_NOT_COPYABLE_;
89 
90 inline constexpr __mstring __not_callable_diag =
91     "The specified function is not callable with the arguments provided."_mstr;
92 
93 template <__mstring _Context, __mstring _Diagnostic = __not_callable_diag>
94 struct _NOT_CALLABLE_;
95 
96 template <auto _Reason = "You cannot pipe one sender into another."_mstr>
97 struct _CANNOT_PIPE_INTO_A_SENDER_
98 {};
99 
100 template <class _Sender>
101 using __bad_pipe_sink_t =
102     __mexception<_CANNOT_PIPE_INTO_A_SENDER_<>, _WITH_SENDER_<_Sender>>;
103 
104 template <__mstring _Context>
105 struct __callable_error
106 {
107     template <class _Fun, class... _Args>
108     using __f =       //
109         __mexception< //
110             _NOT_CALLABLE_<_Context>, _WITH_FUNCTION_<_Fun>,
111             _WITH_ARGUMENTS_<_Args...>>;
112 };
113 } // namespace stdexec
114