A fold function for C++

T accumulate(InputIt first, InputIt last, T init)

Usage

std::vector<int> v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 
int sum = std::accumulate(v.begin(), v.end(), 0);