Perhaps a two parameter member function, along the lines of std::accumulate
?
template<typename Handle, typename Accumulator>
Accumulator Graph::parallelSumForNodes(Handle handle, Accumulator sum)
{
#pragma omp parallel for reduction(+:sum)
for (node v = 0; v < z; ++v) {
// call here
if (exists[v]) {
sum += handle(v);
}
}
return sum;
}
Note that this has the same caveat as std::accumulate
: you have to be careful with the type of the accumulator you pass it.