diff --git a/code/header_units/main.cpp b/code/header_units/main.cpp index b545a696..b0beddda 100644 --- a/code/header_units/main.cpp +++ b/code/header_units/main.cpp @@ -24,9 +24,9 @@ void compute(int len, T initial, T step) { std::adjacent_difference(v.begin(), v.end(), diffs.begin()); // compute standard deviation of it - const T sum = std::reduce(diffs.begin()+1, diffs.end(), T()); - const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(), - [](const T& s, const T& a) { return s + a * a; }); + const T sum = std::reduce(diffs.begin()+1, diffs.end()); + const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(), + [](const T& s, const T& a) { return s + a * a; }); const T mean = sum/len; const T variance = sumsq/len - mean*mean; diff --git a/code/header_units/solution/main.cpp b/code/header_units/solution/main.cpp index 0afc0306..55110c9f 100644 --- a/code/header_units/solution/main.cpp +++ b/code/header_units/solution/main.cpp @@ -22,9 +22,9 @@ void compute(int len, T initial, T step) { std::adjacent_difference(v.begin(), v.end(), diffs.begin()); // compute standard deviation of it - const T sum = std::reduce(diffs.begin()+1, diffs.end(), T()); - const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(), - [](const T& s, const T& a) { return s + a * a; }); + const T sum = std::reduce(diffs.begin()+1, diffs.end()); + const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(), + [](const T& s, const T& a) { return s + a * a; }); const T mean = sum/len; const T variance = sumsq/len - mean*mean; diff --git a/code/modules/main.cpp b/code/modules/main.cpp index b545a696..b0beddda 100644 --- a/code/modules/main.cpp +++ b/code/modules/main.cpp @@ -24,9 +24,9 @@ void compute(int len, T initial, T step) { std::adjacent_difference(v.begin(), v.end(), diffs.begin()); // compute standard deviation of it - const T sum = std::reduce(diffs.begin()+1, diffs.end(), T()); - const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(), - [](const T& s, const T& a) { return s + a * a; }); + const T sum = std::reduce(diffs.begin()+1, diffs.end()); + const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(), + [](const T& s, const T& a) { return s + a * a; }); const T mean = sum/len; const T variance = sumsq/len - mean*mean; diff --git a/code/modules/solution/main.cpp b/code/modules/solution/main.cpp index d8a1e404..23bcc795 100644 --- a/code/modules/solution/main.cpp +++ b/code/modules/solution/main.cpp @@ -25,9 +25,9 @@ void compute(int len, T initial, T step) { std::adjacent_difference(v.begin(), v.end(), diffs.begin()); // compute standard deviation of it - const T sum = std::reduce(diffs.begin()+1, diffs.end(), T()); - const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(), - [](const T& s, const T& a) { return s + a * a; }); + const T sum = std::reduce(diffs.begin()+1, diffs.end()); + const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(), + [](const T& s, const T& a) { return s + a * a; }); const T mean = sum/len; const T variance = sumsq/len - mean*mean; diff --git a/code/smartPointers/smartPointers.cpp b/code/smartPointers/smartPointers.cpp index c6f6d0ac..3218d5e2 100644 --- a/code/smartPointers/smartPointers.cpp +++ b/code/smartPointers/smartPointers.cpp @@ -39,7 +39,7 @@ double sumEntries(std::span range) { // Simulate an error throw std::invalid_argument("Error when summing over data."); - return std::reduce(range.begin(), range.end(), 0.); + return std::reduce(range.begin(), range.end()); } // Often, data are owned by one entity, and merely used by others. In this case, we hand the data to diff --git a/code/smartPointers/solution/smartPointers.sol.cpp b/code/smartPointers/solution/smartPointers.sol.cpp index c7b95a9a..2c953c9a 100644 --- a/code/smartPointers/solution/smartPointers.sol.cpp +++ b/code/smartPointers/solution/smartPointers.sol.cpp @@ -40,7 +40,7 @@ double sumEntries(std::span range) { // Simulate an error throw std::invalid_argument("Error when summing over data."); - return std::reduce(range.begin(), range.end(), 0.); + return std::reduce(range.begin(), range.end()); } // Often, data are owned by one entity, and merely used by others. In this case, we hand the data to diff --git a/code/stl/randomize.cpp b/code/stl/randomize.cpp index d5777899..a43b287e 100644 --- a/code/stl/randomize.cpp +++ b/code/stl/randomize.cpp @@ -19,7 +19,7 @@ void compute(int len, T initial, T step) { // compute standard deviation of all differences const T sum = std::reduce(...); - const T sumsq = std::reduce(..., [](...) { ...; }); + const T sumsq = std::accumulate(..., [](...) { ...; }); const T mean = sum/len; const T variance = sumsq/len - mean*mean; diff --git a/code/stl/solution/randomize.sol.cpp b/code/stl/solution/randomize.sol.cpp index e4b1562b..1713f128 100644 --- a/code/stl/solution/randomize.sol.cpp +++ b/code/stl/solution/randomize.sol.cpp @@ -42,11 +42,11 @@ void compute(int len, T initial, T step) { // compute standard deviation of all differences. // Note that the first element is just the original element itself, so we need to skip it. - const T sum = std::reduce(diffs.begin()+1, diffs.end(), T()); - const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(), sumsquare()); + const T sum = std::reduce(diffs.begin()+1, diffs.end()); + const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(), sumsquare()); // Alternatively: - // const T sumsq = std::reduce(diffs.begin()+1, diffs.end(), T(), - // [](const T& s, const T& a) { return s + a * a; }); + // const T sumsq = std::accumulate(diffs.begin()+1, diffs.end(), T(), + // [](const T& s, const T& a) { return s + a * a; }); const T mean = sum/len; const T variance = sumsq/len - mean*mean;