fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <numeric>
  5. #include <boost/accumulators/accumulators.hpp>
  6. #include <boost/accumulators/statistics/tail.hpp>
  7.  
  8. int func(const std::vector<int>& v)
  9. {
  10. using namespace boost::accumulators;
  11. accumulator_set<int, features<tag::tail<right> > > acc(tag::tail<right>::cache_size = 3);
  12. acc = for_each(v.begin(), v.end(), acc);
  13. return accumulate(tail(acc).begin(), tail(acc).end(), 0);
  14. }
  15. int main()
  16. {
  17. int data[] = {1,2,3,4,5,6,7,8,9,10,20,30};
  18. std::vector<int> v(data, data+sizeof data/sizeof *data);
  19. std::cout << func(v) << '\n';
  20. }
  21.  
Success #stdin #stdout 0.01s 2864KB
stdin
Standard input is empty
stdout
60