Skip to content
Snippets Groups Projects
Verified Commit 06e82f80 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Simplification using std::accumulate

parent 2506e4f9
Branches
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "tl_exception.hh" #include "tl_exception.hh"
#include <iostream> #include <iostream>
#include <numeric>
int int
OrdSequence::operator[](int i) const OrdSequence::operator[](int i) const
...@@ -102,11 +103,8 @@ OrdSequence::has(int i) const ...@@ -102,11 +103,8 @@ OrdSequence::has(int i) const
double double
OrdSequence::average() const OrdSequence::average() const
{ {
double res = 0; TL_RAISE_IF(data.empty(), "Attempt to take average of empty class in OrdSequence::average");
for (int i : data) return std::accumulate(data.begin(), data.end(), 0.) / data.size();
res += i;
TL_RAISE_IF(data.size() == 0, "Attempt to take average of empty class in OrdSequence::average");
return res / data.size();
} }
/* Debug print. */ /* Debug print. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment