#include <iostream> // std::cout
#include <functional> // std::minus, std::divides
#include <numeric> // std::inner_product
unsigned myaccumulator (unsigned x, unsigned y) {return x+y;}
unsigned myLessThan (unsigned x, unsigned y) {return x<y;}
int main () {
unsigned init = 0;
unsigned series1[] = {10,20,30};
unsigned series2[] = {1,2,3};
std::cout << "using default inner_product: ";
std::cout << std::inner_product(series1,series1+3,series2,init);
std::cout << '\n';
std::cout << "using custom functions: ";
std::cout << std::inner_product(series1,series1+2,series1 + 1,init,
myaccumulator,myLessThan);
std::cout << '\n';
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPiAgICAgLy8gc3RkOjpjb3V0CiNpbmNsdWRlIDxmdW5jdGlvbmFsPiAgIC8vIHN0ZDo6bWludXMsIHN0ZDo6ZGl2aWRlcwojaW5jbHVkZSA8bnVtZXJpYz4gICAgICAvLyBzdGQ6OmlubmVyX3Byb2R1Y3QKCnVuc2lnbmVkIG15YWNjdW11bGF0b3IgKHVuc2lnbmVkIHgsIHVuc2lnbmVkIHkpIHtyZXR1cm4geCt5O30KdW5zaWduZWQgbXlMZXNzVGhhbiAodW5zaWduZWQgeCwgdW5zaWduZWQgeSkge3JldHVybiB4PHk7fQoKaW50IG1haW4gKCkgewogIHVuc2lnbmVkIGluaXQgPSAwOwogIHVuc2lnbmVkIHNlcmllczFbXSA9IHsxMCwyMCwzMH07CiAgdW5zaWduZWQgc2VyaWVzMltdID0gezEsMiwzfTsKCiAgc3RkOjpjb3V0IDw8ICJ1c2luZyBkZWZhdWx0IGlubmVyX3Byb2R1Y3Q6ICI7CiAgc3RkOjpjb3V0IDw8IHN0ZDo6aW5uZXJfcHJvZHVjdChzZXJpZXMxLHNlcmllczErMyxzZXJpZXMyLGluaXQpOwogIHN0ZDo6Y291dCA8PCAnXG4nOwoKCiAgc3RkOjpjb3V0IDw8ICJ1c2luZyBjdXN0b20gZnVuY3Rpb25zOiAiOwogIHN0ZDo6Y291dCA8PCBzdGQ6OmlubmVyX3Byb2R1Y3Qoc2VyaWVzMSxzZXJpZXMxKzIsc2VyaWVzMSArIDEsaW5pdCwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG15YWNjdW11bGF0b3IsbXlMZXNzVGhhbik7CiAgc3RkOjpjb3V0IDw8ICdcbic7CgogIHJldHVybiAwOwp9