Commit 492ce4ff authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot

replace some lambdas with less-parameterized function objects

fbshipit-source-id: 78678cd0f18440a8ece264e83e303c568354bdaa
parent 4fdee04d
...@@ -7,35 +7,31 @@ ...@@ -7,35 +7,31 @@
#include <pushmi/single_deferred.h> #include <pushmi/single_deferred.h>
#if __cpp_deduction_guides >= 201703
#define MAKE(x) x MAKE_
#define MAKE_(...) {__VA_ARGS__}
#else
#define MAKE(x) make_ ## x
#endif
namespace pushmi { namespace pushmi {
namespace operators { namespace operators {
template<class F, class ShapeBegin, class ShapeEnd, class Target, class IF, class RS> PUSHMI_INLINE_VAR constexpr struct bulk_fn {
auto bulk( template<class F, class ShapeBegin, class ShapeEnd, class Target, class IF, class RS>
F&& func, auto operator()(
ShapeBegin sb, F&& func,
ShapeEnd se, ShapeBegin sb,
Target&& driver, ShapeEnd se,
IF&& initFunc, Target&& driver,
RS&& selector) { IF&& initFunc,
return [func, sb, se, driver, initFunc, selector](auto in){ RS&& selector) const {
return MAKE(single_deferred)([in, func, sb, se, driver, initFunc, selector](auto out) mutable { return [func, sb, se, driver, initFunc, selector](auto in){
submit(in, MAKE(single)(std::move(out), return make_single_deferred(
[func, sb, se, driver, initFunc, selector](auto& out, auto input){ [in, func, sb, se, driver, initFunc, selector](auto out) mutable {
driver(initFunc, selector, std::move(input), func, sb, se, std::move(out)); submit(in, make_single(std::move(out),
} [func, sb, se, driver, initFunc, selector](auto& out, auto input) {
)); driver(initFunc, selector, std::move(input), func, sb, se, std::move(out));
}); }
}; ));
});
};
} }
} bulk {};
} // namespace operators } // namespace operators
......
...@@ -11,22 +11,41 @@ ...@@ -11,22 +11,41 @@
namespace pushmi { namespace pushmi {
template<class ExecutionPolicy, class RandomAccessIterator, class Function> PUSHMI_INLINE_VAR constexpr struct for_each_fn {
void for_each( private:
ExecutionPolicy&& policy, template <class Function>
RandomAccessIterator begin, struct fn {
RandomAccessIterator end, Function f_;
Function f) template <class Cursor>
{ void operator()(detail::any, Cursor cursor) const {
operators::just(0) | f_(*cursor);
operators::bulk( }
[f](auto& acc, auto cursor){ f(*cursor); }, };
begin, struct identity {
end, template <class T>
policy, auto operator()(T&& t) const { return (T&&) t; }
[](auto&& args){ return args; }, };
[](auto&& acc){ return 0; }) | struct zero {
operators::blocking_submit(); int operator()(detail::any) const noexcept { return 0; }
} };
public:
template<class ExecutionPolicy, class RandomAccessIterator, class Function>
void operator()(
ExecutionPolicy&& policy,
RandomAccessIterator begin,
RandomAccessIterator end,
Function f) const {
operators::just(0) |
operators::bulk(
fn<Function>{f},
begin,
end,
policy,
identity{},
zero{}
) |
operators::blocking_submit();
}
} for_each {};
} // namespace pushmi } // namespace pushmi
...@@ -13,6 +13,11 @@ namespace detail { ...@@ -13,6 +13,11 @@ namespace detail {
struct no_fail_fn { struct no_fail_fn {
private: private:
struct on_error_impl {
void operator()(any, any) noexcept {
std::abort();
}
};
template <class In> template <class In>
struct out_impl { struct out_impl {
PUSHMI_TEMPLATE(class Out) PUSHMI_TEMPLATE(class Out)
...@@ -20,9 +25,7 @@ private: ...@@ -20,9 +25,7 @@ private:
auto operator()(Out out) const { auto operator()(Out out) const {
return ::pushmi::detail::out_from_fn<In>()( return ::pushmi::detail::out_from_fn<In>()(
std::move(out), std::move(out),
::pushmi::on_error([](auto&, auto&&) noexcept { ::pushmi::on_error(on_error_impl{})
std::abort();
})
); );
} }
}; };
......
...@@ -30,7 +30,7 @@ struct __pool_submit { ...@@ -30,7 +30,7 @@ struct __pool_submit {
PUSHMI_TEMPLATE(class TP, class Out) PUSHMI_TEMPLATE(class TP, class Out)
(requires Regular<TP> && Receiver<Out>) (requires Regular<TP> && Receiver<Out>)
void operator()(TP at, Out out) const { void operator()(TP at, Out out) const {
e.execute([e = this->e, at = std::move(at), out = std::move(out)]() mutable { e.execute([e = e, at = std::move(at), out = std::move(out)]() mutable {
auto tr = trampoline(); auto tr = trampoline();
::pushmi::submit(tr, std::move(at), std::move(out)); ::pushmi::submit(tr, std::move(at), std::move(out));
}); });
......
...@@ -11,22 +11,41 @@ ...@@ -11,22 +11,41 @@
namespace pushmi { namespace pushmi {
template<class ExecutionPolicy, class ForwardIt, class T, class BinaryOp> PUSHMI_INLINE_VAR constexpr struct reduce_fn {
T reduce( private:
ExecutionPolicy&& policy, template <class BinaryOp>
ForwardIt begin, struct fn {
ForwardIt end, BinaryOp binary_op_;
T init, template <class Acc, class Cursor>
BinaryOp binary_op){ void operator()(Acc& acc, Cursor cursor) const {
return operators::just(std::move(init)) | acc = binary_op_(acc, *cursor);
operators::bulk(
[binary_op](auto& acc, auto cursor){ acc = binary_op(acc, *cursor); },
begin,
end,
policy,
[](auto&& args){ return args; },
[](auto&& acc){ return acc; }) |
operators::get<T>;
} }
};
struct identity {
template <class T>
auto operator()(T&& t) const {
return (T&&) t;
}
};
public:
template<class ExecutionPolicy, class ForwardIt, class T, class BinaryOp>
T operator()(
ExecutionPolicy&& policy,
ForwardIt begin,
ForwardIt end,
T init,
BinaryOp binary_op) const {
return operators::just(std::move(init)) |
operators::bulk(
fn<BinaryOp>{binary_op},
begin,
end,
policy,
identity{},
identity{}
) |
operators::get<T>;
}
} reduce {};
} // namespace pushmi } // namespace pushmi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment