xref: /openbmc/sdbusplus/include/sdbusplus/async/stdexec/__detail/__just.hpp (revision 06f265f6f18e22b1fb68761edb50ecd6722c2a47)
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 "__basic_sender.hpp"
19  #include "__completion_signatures.hpp"
20  #include "__execution_fwd.hpp"
21  #include "__meta.hpp"
22  #include "__receivers.hpp"
23  #include "__type_traits.hpp"
24  
25  STDEXEC_PRAGMA_PUSH()
26  STDEXEC_PRAGMA_IGNORE_GNU("-Wmissing-braces")
27  
28  namespace stdexec
29  {
30  /////////////////////////////////////////////////////////////////////////////
31  // [execution.senders.factories]
32  namespace __just
33  {
34  template <class _JustTag>
35  struct __impl : __sexpr_defaults
36  {
37      using __tag_t = typename _JustTag::__tag_t;
38  
39      static constexpr auto get_completion_signatures =
40          []<class _Sender>(_Sender&&, auto&&...) noexcept {
41              static_assert(sender_expr_for<_Sender, _JustTag>);
42              return completion_signatures<
43                  __mapply<__qf<__tag_t>, __decay_t<__data_of<_Sender>>>>{};
44          };
45  
46      static constexpr auto start =
47          []<class _State, class _Receiver>(_State& __state,
48                                            _Receiver& __rcvr) noexcept -> void {
49          __state.apply(
50              [&]<class... _Ts>(_Ts&... __ts) noexcept {
51                  __tag_t()(static_cast<_Receiver&&>(__rcvr),
52                            static_cast<_Ts&&>(__ts)...);
53              },
54              __state);
55      };
56  };
57  
58  struct just_t
59  {
60      using __tag_t = set_value_t;
61  
62      template <__movable_value... _Ts>
63      STDEXEC_ATTRIBUTE((host, device))
operator ()stdexec::__just::just_t64      auto operator()(_Ts&&... __ts) const
65          noexcept((__nothrow_decay_copyable<_Ts> && ...))
66      {
67          return __make_sexpr<just_t>(__tuple{static_cast<_Ts&&>(__ts)...});
68      }
69  };
70  
71  struct just_error_t
72  {
73      using __tag_t = set_error_t;
74  
75      template <__movable_value _Error>
76      STDEXEC_ATTRIBUTE((host, device))
operator ()stdexec::__just::just_error_t77      auto operator()(_Error&& __err) const
78          noexcept(__nothrow_decay_copyable<_Error>)
79      {
80          return __make_sexpr<just_error_t>(
81              __tuple{static_cast<_Error&&>(__err)});
82      }
83  };
84  
85  struct just_stopped_t
86  {
87      using __tag_t = set_stopped_t;
88  
89      template <class _Tag = just_stopped_t>
90      STDEXEC_ATTRIBUTE((host, device))
operator ()stdexec::__just::just_stopped_t91      auto operator()() const noexcept
92      {
93          return __make_sexpr<_Tag>(__tuple{});
94      }
95  };
96  } // namespace __just
97  
98  using __just::just_error_t;
99  using __just::just_stopped_t;
100  using __just::just_t;
101  
102  template <>
103  struct __sexpr_impl<just_t> : __just::__impl<just_t>
104  {};
105  
106  template <>
107  struct __sexpr_impl<just_error_t> : __just::__impl<just_error_t>
108  {};
109  
110  template <>
111  struct __sexpr_impl<just_stopped_t> : __just::__impl<just_stopped_t>
112  {};
113  
114  inline constexpr just_t just{};
115  inline constexpr just_error_t just_error{};
116  inline constexpr just_stopped_t just_stopped{};
117  } // namespace stdexec
118  
119  STDEXEC_PRAGMA_POP()
120