proxygen
reduce_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 <cassert>
17 #include <exception>
18 #include <iostream>
19 #include <numeric>
20 #include <vector>
21 
23 
24 using namespace folly::pushmi::aliases;
25 
27  return [](auto init,
28  auto selector,
29  auto input,
30  auto&& func,
31  auto sb,
32  auto se,
33  auto out) {
34  try {
35  auto acc = init(input);
36  for (decltype(sb) idx{sb}; idx != se; ++idx) {
37  func(acc, idx);
38  }
39  auto result = selector(std::move(acc));
40  mi::set_value(out, std::move(result));
41  } catch (...) {
42  mi::set_error(out, std::current_exception());
43  }
44  };
45 }
46 
47 int main() {
48  std::vector<int> vec(10);
49  std::fill(vec.begin(), vec.end(), 4);
50 
51  auto fortyTwo = mi::reduce(
52  inline_bulk_target(), vec.begin(), vec.end(), 2, std::plus<>{});
53 
54  assert(std::accumulate(vec.begin(), vec.end(), 2) == fortyTwo);
55 
56  std::cout << fortyTwo << std::endl;
57 
58  std::cout << "OK" << std::endl;
59 }
void accumulate(std::vector< std::size_t > &a, std::vector< std::size_t > const &d)
Definition: F14TestUtil.h:58
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::set_error_fn set_error
int main()
Definition: reduce_3.cpp:47
void init(int *argc, char ***argv, bool removeFlags)
Definition: Init.cpp:34
auto inline_bulk_target()
Definition: reduce_3.cpp:26
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
vector< string > vec
Definition: StringTest.cpp:35
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::reduce_fn reduce