proxygen
reduce_3.cpp File Reference
#include <cassert>
#include <exception>
#include <iostream>
#include <numeric>
#include <vector>
#include <folly/experimental/pushmi/examples/reduce.h>

Go to the source code of this file.

Functions

auto inline_bulk_target ()
 
int main ()
 

Function Documentation

auto inline_bulk_target ( )

Definition at line 26 of file reduce_3.cpp.

References folly::init(), folly::gen::move, folly::pushmi::set_error, and folly::pushmi::set_value.

Referenced by main().

26  {
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 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::set_error_fn set_error
void init()
PUSHMI_INLINE_VAR constexpr __adl::set_value_fn set_value
int main ( void  )

Definition at line 47 of file reduce_3.cpp.

References folly::f14::accumulate(), inline_bulk_target(), and folly::pushmi::reduce.

47  {
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
auto inline_bulk_target()
Definition: reduce_3.cpp:26
Definition: Traits.h:588
vector< string > vec
Definition: StringTest.cpp:35
PUSHMI_INLINE_VAR constexpr struct folly::pushmi::reduce_fn reduce