proxygen
for_each.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 
20 
21 namespace folly {
22 namespace pushmi {
23 namespace detail {
24 
25 struct for_each_fn {
26  private:
27  template <class... PN>
28  struct subset {
29  using properties = property_set<PN...>;
30  };
31  template <class In, class Out>
32  struct Pull : Out {
33  explicit Pull(Out out) : Out(std::move(out)) {}
34  using properties =
36  std::function<void(std::ptrdiff_t)> pull;
37  template <class... VN>
38  void value(VN&&... vn) {
39  ::folly::pushmi::set_value(static_cast<Out&>(*this), (VN &&) vn...);
40  pull(1);
41  }
42  template <class E>
43  void error(E&& e) {
44  // break circular reference
45  pull = nullptr;
46  ::folly::pushmi::set_error(static_cast<Out&>(*this), (E &&) e);
47  }
48  void done() {
49  // break circular reference
50  pull = nullptr;
51  ::folly::pushmi::set_done(static_cast<Out&>(*this));
52  }
53  PUSHMI_TEMPLATE(class Up)
54  (requires Receiver<Up> && ReceiveValue<Up, std::ptrdiff_t>)
55  void starting(Up up) {
56  pull = [up = std::move(up)](std::ptrdiff_t requested) mutable {
57  ::folly::pushmi::set_value(up, requested);
58  };
59  pull(1);
60  }
61  PUSHMI_TEMPLATE(class Up)
62  (requires ReceiveValue<Up>)
63  void starting(Up) {}
64  };
65  template <class... AN>
66  struct fn {
67  std::tuple<AN...> args_;
68  PUSHMI_TEMPLATE(class In)
69  (requires Sender<In>&& Flow<In>&& Many<In>)
70  In operator()(In in) {
74  std::move(args_))};
75  using Out = decltype(out);
77  in,
79  Pull<In, Out>{std::move(out)}));
80  return in;
81  }
82  };
83 
84  public:
85  template <class... AN>
86  auto operator()(AN&&... an) const {
87  return for_each_fn::fn<AN...>{std::tuple<AN...>{(AN &&) an...}};
88  }
89 };
90 
91 } // namespace detail
92 
93 namespace operators {
95 } // namespace operators
96 
97 } // namespace pushmi
98 } // namespace folly
requires ReceiveValue< Up > void starting(Up)
Definition: for_each.h:63
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::for_each_fn for_each
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
PUSHMI_INLINE_VAR constexpr __adl::set_error_fn set_error
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
auto operator()(AN &&...an) const
Definition: for_each.h:86
typename std::enable_if_t< PropertySet< PS0 > &&PropertySet< PS1 >, detail::property_set_insert< PS0, PS1 >>::type property_set_insert_t
Definition: properties.h:153
requires Receiver< Up > &&ReceiveValue< Up, std::ptrdiff_t > void starting(Up up)
Definition: for_each.h:55
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
std::function< void(std::ptrdiff_t)> pull
Definition: for_each.h:36
#define PUSHMI_INLINE_VAR
Definition: concept_def.h:60
property_set_insert_t< properties_t< Out >, property_set< is_flow<>>> properties
Definition: for_each.h:35
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()
PUSHMI_INLINE_VAR constexpr __adl::set_done_fn set_done