// We show another definition of plus, as a function template. // A rather direct and more down-to-earth approach. #include #include #include // accumulate #include // binary_function template T plus_fn(T a, T b){ return a + b; } int main(){ std::list lst; for(int i = 1; i <= 10; i++) lst.push_back(i); // 1, 2, ..., 10 // We must make an object which serves as a binary plus function: double res = std::accumulate(lst.begin(), lst.end(), 0.0, plus_fn); std::cout << "The plus accumulation is: " << res << std::endl; // 55 }