关于如何为模板做的任何想法?感谢
例如,Combine(<list containing 6,3,1,9,7>, std::plus<int>())
应该计算((((6+3)+1)+9)+7)
。
Combine(const Container& c, Function fn) throw (NotEnoughElements)
{
your code goes here
}
答案 0 :(得分:2)
return
std::accumulate
(c.begin()+1, c.end(), *(c.begin()), fn);
(错误处理留作OP和读者的练习。)