fork download
  1. #include <iostream> // std::cout
  2. #include <functional> // std::minus, std::divides
  3. #include <numeric> // std::inner_product
  4.  
  5. unsigned myaccumulator (unsigned x, unsigned y) {return x+y;}
  6. unsigned myLessThan (unsigned x, unsigned y) {return x<y;}
  7.  
  8. int main () {
  9. unsigned init = 0;
  10. unsigned series1[] = {10,20,30};
  11. unsigned series2[] = {1,2,3};
  12.  
  13. std::cout << "using default inner_product: ";
  14. std::cout << std::inner_product(series1,series1+3,series2,init);
  15. std::cout << '\n';
  16.  
  17.  
  18. std::cout << "using custom functions: ";
  19. std::cout << std::inner_product(series1,series1+2,series1 + 1,init,
  20. myaccumulator,myLessThan);
  21. std::cout << '\n';
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
using default inner_product: 140
using custom functions: 2