Skip to content

Commit 6d46f16

Browse files
committed
allow 'simdFor()' to return passed functor
1 parent 20d3a8a commit 6d46f16

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

examples/boost-simd-for-each.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class Accumulator
2929

3030
// [[Rcpp::export]]
3131
double vectorProd(NumericVector x) {
32-
Accumulator accumulator;
33-
simdFor(x.begin(), x.end(), accumulator);
34-
return accumulator;
32+
return simdFor(x.begin(), x.end(), Accumulator());
3533
}
3634

3735
/*** R

inst/include/RcppParallel/simd/algorithm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace RcppParallel {
55

66
template <typename T, typename F>
7-
void simdFor(const T* it, const T* end, F&& f)
7+
F simdFor(const T* it, const T* end, F&& f)
88
{
99
typedef boost::simd::pack<T> vT;
1010
static const std::size_t N = vT::static_size;
@@ -19,6 +19,8 @@ void simdFor(const T* it, const T* end, F&& f)
1919

2020
for (; it != end; ++it)
2121
f(*it);
22+
23+
return f;
2224
}
2325

2426
template <typename T, typename U, typename F>

0 commit comments

Comments
 (0)