diff --git a/src/libslic3r/Execution/Execution.hpp b/src/libslic3r/Execution/Execution.hpp index 809cc45d3c..e4bad9f237 100644 --- a/src/libslic3r/Execution/Execution.hpp +++ b/src/libslic3r/Execution/Execution.hpp @@ -10,6 +10,7 @@ namespace Slic3r { +// Borrowed from C++20 template using remove_cvref_t = std::remove_reference_t>; @@ -31,7 +32,7 @@ template struct Traits {}; template using AsTraits = Traits>; // Each execution policy should declare two types of mutexes. A a spin lock and -// a blocking mutex. +// a blocking mutex. These types should satisfy the BasicLockable concept. template using SpinningMutex = typename Traits::SpinningMutex; template using BlockingMutex = typename Traits::BlockingMutex; @@ -75,13 +76,12 @@ T reduce(const EP & ep, } // An overload of reduce method to be used with iterators as 'from' and 'to' -// arguments. +// arguments. Access functor is omitted here. template, - class = IteratorOnly > + class = ExecutionPolicyOnly > T reduce(const EP &ep, I from, I to, @@ -91,7 +91,39 @@ T reduce(const EP &ep, { return reduce( ep, from, to, init, std::forward(mergefn), - [](typename I::value_type &i) { return i; }, granularity); + [](const auto &i) { return i; }, granularity); +} + +template> +T accumulate(const EP & ep, + I from, + I to, + const T & init, + AccessFn &&accessfn, + size_t granularity = 1) +{ + return reduce(ep, from, to, init, std::plus{}, + std::forward(accessfn), granularity); +} + + +template > +T accumulate(const EP &ep, + I from, + I to, + const T & init, + size_t granularity = 1) +{ + return reduce( + ep, from, to, init, std::plus{}, [](const auto &i) { return i; }, + granularity); } } // namespace execution_policy diff --git a/tests/sla_print/sla_print_tests.cpp b/tests/sla_print/sla_print_tests.cpp index bdd5731dcc..59c841468d 100644 --- a/tests/sla_print/sla_print_tests.cpp +++ b/tests/sla_print/sla_print_tests.cpp @@ -248,7 +248,7 @@ TEST_CASE("Test concurrency") double ref = std::accumulate(vals.begin(), vals.end(), 0.); - double s = sla::ccr_par::reduce(vals.begin(), vals.end(), 0., std::plus{}); + double s = execution::accumulate(ex_tbb, vals.begin(), vals.end(), 0.); REQUIRE(s == Approx(ref)); }