proxygen
transform.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 
22 
23 namespace folly {
24 namespace pushmi {
25 
26 namespace detail {
27 
28 template <class F, class Tag, bool IsFlow = false>
29 struct transform_on;
30 
31 template <class F>
32 struct transform_on<F, is_single<>> {
33  F f_;
34  transform_on() = default;
35  constexpr explicit transform_on(F f) : f_(std::move(f)) {}
36  struct value_fn {
37  F f_;
38  value_fn() = default;
39  constexpr explicit value_fn(F f) : f_(std::move(f)) {}
40  template <class Out, class V0, class... VN>
41  auto operator()(Out& out, V0&& v0, VN&&... vn) {
42  using Result = ::folly::pushmi::invoke_result_t<F, V0, VN...>;
43  static_assert(
44  ::folly::pushmi::SemiMovable<Result>,
45  "none of the functions supplied to transform can convert this value");
46  static_assert(
47  ::folly::pushmi::ReceiveValue<Out, Result>,
48  "Result of value transform cannot be delivered to Out");
49  set_value(out, f_((V0 &&) v0, (VN &&) vn...));
50  }
51  };
52  template <class Out>
53  auto operator()(Out out) const {
55  }
56 };
57 
58 template <class F>
59 struct transform_on<F, is_single<>, true> {
60  F f_;
61  transform_on() = default;
62  constexpr explicit transform_on(F f) : f_(std::move(f)) {}
63  template <class Out>
64  auto operator()(Out out) const {
65  return make_flow_single(std::move(out), on_value(*this));
66  }
67  template <class Out, class V0, class... VN>
68  auto operator()(Out& out, V0&& v0, VN&&... vn) {
69  using Result = ::folly::pushmi::invoke_result_t<F, V0, VN...>;
70  static_assert(
71  ::folly::pushmi::SemiMovable<Result>,
72  "none of the functions supplied to transform can convert this value");
73  static_assert(
74  ::folly::pushmi::Flow<Out> &&
75  ::folly::pushmi::ReceiveValue<Out, Result>,
76  "Result of value transform cannot be delivered to Out");
77  set_value(out, f_((V0 &&) v0, (VN &&) vn...));
78  }
79 };
80 
81 template <class F>
82 struct transform_on<F, is_many<>> {
83  F f_;
84  transform_on() = default;
85  constexpr explicit transform_on(F f) : f_(std::move(f)) {}
86  template <class Out>
87  auto operator()(Out out) const {
89  }
90  template <class Out, class V0, class... VN>
91  auto operator()(Out& out, V0&& v0, VN&&... vn) {
92  using Result = ::folly::pushmi::invoke_result_t<F, V0, VN...>;
93  static_assert(
94  ::folly::pushmi::SemiMovable<Result>,
95  "none of the functions supplied to transform can convert this value");
96  static_assert(
97  ::folly::pushmi::ReceiveValue<Out, Result>,
98  "Result of value transform cannot be delivered to Out");
99  set_value(out, f_((V0 &&) v0, (VN &&) vn...));
100  }
101 };
102 
103 template <class F>
104 struct transform_on<F, is_many<>, true> {
105  F f_;
106  transform_on() = default;
107  constexpr explicit transform_on(F f) : f_(std::move(f)) {}
108  template <class Out>
109  auto operator()(Out out) const {
110  return make_flow_receiver(std::move(out), on_value(*this));
111  }
112  template <class Out, class V0, class... VN>
113  auto operator()(Out& out, V0&& v0, VN&&... vn) {
114  using Result = ::folly::pushmi::invoke_result_t<F, V0, VN...>;
115  static_assert(
116  ::folly::pushmi::SemiMovable<Result>,
117  "none of the functions supplied to transform can convert this value");
118  static_assert(
119  ::folly::pushmi::Flow<Out> &&
120  ::folly::pushmi::ReceiveValue<Out, Result>,
121  "Result of value transform cannot be delivered to Out");
122  set_value(out, f_((V0 &&) v0, (VN &&) vn...));
123  }
124 };
125 
126 struct transform_fn {
127  private:
128  template <class F>
129  struct impl {
130  F f_;
131  PUSHMI_TEMPLATE(class In)
132  (requires Sender<In>)
133  auto operator()(In in) const {
136  std::move(in),
137  ::folly::pushmi::detail::submit_transform_out<In>(
138  // copy 'f_' to allow multiple calls to connect to multiple 'in'
139  transform_on<
140  F,
141  Cardinality,
143  }
144  };
145 
146  public:
147  template <class... FN>
148  auto operator()(FN... fn) const {
149  auto f = ::folly::pushmi::overload(std::move(fn)...);
150  using F = decltype(f);
151  return impl<F>{std::move(f)};
152  }
153 };
154 
155 } // namespace detail
156 
157 namespace operators {
159 } // namespace operators
160 
161 } // namespace pushmi
162 } // namespace folly
auto operator()(Out &out, V0 &&v0, VN &&...vn)
Definition: transform.h:91
auto f
auto operator()(FN...fn) const
Definition: transform.h:148
auto overload(Fns...fns) -> overload_fn< Fns... >
Definition: boosters.h:251
auto on_value(Fns...fns) -> on_value_fn< Fns... >
Definition: boosters.h:262
std::enable_if_t< PropertySet< __properties_t< property_set_traits< T >>>, __properties_t< property_set_traits< T >>> properties_t
Definition: properties.h:105
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto operator()(Out &out, V0 &&v0, VN &&...vn)
Definition: transform.h:68
STL namespace.
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
PUSHMI_INLINE_VAR constexpr detail::transform_fn transform
Definition: transform.h:158
PUSHMI_INLINE_VAR constexpr bool property_query_v
Definition: properties.h:176
auto operator()(Out &out, V0 &&v0, VN &&...vn)
Definition: transform.h:113
requires requires(::folly::pushmi::invoke(std::declval< F >(), std::get< Is >(std::declval< Tuple >())...))) const expr decltype(auto) apply_impl(F &&f
std::enable_if_t< PropertySet< PS > &&Property< P >, decltype(detail::__property_set_index_fn< P >(PS{}))> property_set_index_t
Definition: properties.h:148
#define PUSHMI_INLINE_VAR
Definition: concept_def.h:60
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_flow_receiver_fn make_flow_receiver
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::detail::sender_from_fn sender_from
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
PUSHMI_TEMPLATE(class In, class Out, bool SenderRequires, bool SingleSenderRequires, bool TimeSingleSenderRequires)(requires Sender< In > &&Receiver< Out >) constexpr bool sender_requires_from()
decltype(folly::pushmi::invoke(std::declval< F >(), std::declval< As >()...)) invoke_result_t
Definition: functional.h:47
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::make_receiver_fn make_receiver