Commit 8fa5f36d authored by Max Lyon's avatar Max Lyon

make SmartRange sum and avg compatible with Eigen vectors

parent 04e79892
......@@ -78,13 +78,13 @@ struct SmartRangeT
* @param f Functor that is applied to all elements before computing the sum
*/
template <typename Functor>
auto sum(Functor&& f) -> decltype (f(std::declval<HandleT>())+f(std::declval<HandleT>()))
auto sum(Functor&& f) -> decltype (f(std::declval<HandleT>()))
{
auto range = static_cast<const RangeT*>(this);
auto begin = range->begin();
auto end = range->end();
assert(begin != end);
decltype (f(*begin) + f(*begin)) sum = f(*begin);
decltype (f(*begin)) sum = f(*begin);
auto it = begin;
++it;
for (; it != end; ++it)
......@@ -99,13 +99,13 @@ struct SmartRangeT
* @param f Functor that is applied to all elements before computing the average.
*/
template <typename Functor>
auto avg(Functor&& f) -> decltype (1.0 * (f(std::declval<HandleT>())+f(std::declval<HandleT>())))
auto avg(Functor&& f) -> decltype (f(std::declval<HandleT>()))
{
auto range = static_cast<const RangeT*>(this);
auto begin = range->begin();
auto end = range->end();
assert(begin != end);
decltype (f(*begin) + f(*begin)) sum = f(*begin);
decltype (f(*begin)) sum = f(*begin);
auto it = begin;
++it;
int n_elements = 1;
......
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