an example of using STL negate function object


👍 g++ generic_sum.cpp && ./a.out
-14
👍 cat generic_sum.cpp 
#include <iostream>
using namespace std;

template<typename F>
double sum(F f, int n, int m) {
  double result = 0;
  for (int i = n; i <= m; i++)
    result += f(i);
  return result;
}

int main() {
  // (-2) + (-3) + (-4) + (-5) = -14
  double s=sum(negate<double>(),2,5);
  cout << s << endl;
}