proxygen
for_each_3.cpp
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 #include <algorithm>
17 #include <cassert>
18 #include <iostream>
19 #include <vector>
20 
22 
23 using namespace folly::pushmi::aliases;
24 
26  return [](auto init,
27  auto selector,
28  auto input,
29  auto&& func,
30  auto sb,
31  auto se,
32  auto out) {
33  try {
34  auto acc = init(input);
35  for (decltype(sb) idx{sb}; idx != se; ++idx) {
36  func(acc, idx);
37  }
38  auto result = selector(std::move(acc));
39  mi::set_value(out, std::move(result));
40  } catch (...) {
41  mi::set_error(out, std::current_exception());
42  }
43  };
44 }
45 
46 int main() {
47  std::vector<int> vec(10);
48 
50  inline_bulk_target(), vec.begin(), vec.end(), [](int& x) { x = 42; });
51 
52  assert(
53  std::count(vec.begin(), vec.end(), 42) == static_cast<int>(vec.size()));
54 
55  std::cout << "OK" << std::endl;
56 }
Definition: InvokeTest.cpp:58
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const int x
PUSHMI_INLINE_VAR constexpr __adl::set_error_fn set_error
auto inline_bulk_target()
Definition: for_each_3.cpp:25
void init(int *argc, char ***argv, bool removeFlags)
Definition: Init.cpp:34
int * count
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
vector< string > vec
Definition: StringTest.cpp:35
void for_each(T const &range, Function< void(typename T::value_type const &) const > const &func)
int main()
Definition: for_each_3.cpp:46