1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/tail.hpp>
int func(const std::vector<int>& v)
{
using namespace boost::accumulators;
accumulator_set<int, features<tag::tail<right>>> acc(tag::tail<right>::cache_size = 3);
acc = for_each(v.begin(), v.end(), acc);
return accumulate(tail(acc).begin(), tail(acc).end(), 0);
}
int main()
{
std::cout << func({1,2,3,4,5,6,7,8,9,10,20,30}) << '\n';
}
|