#include #include #include #include int main() { std::vector v1(5); std::iota(begin(v1), end(v1), 0); for(const auto i: v1) { std::cout << i << ' '; } std::cout << std::endl; std::cout << std::accumulate(begin(v1), end(v1), 0) << std::endl; const std::vector v2 = { 2, 3, 4, 0, 1 }; std::cout << std::inner_product(begin(v1), end(v1), begin(v2), 0) << std::endl; // = 0 * 2 + 1 * 3 + 2 * 4 + 3 * 0 + 4 * 1 std::vector v3(v2.size()); std::adjacent_difference(begin(v1), end(v1), begin(v3)); for(const auto i: v3) { std::cout << i << ' '; } std::cout << std::endl; std::vector v4 { v2 }; std::adjacent_difference(begin(v4), end(v4), begin(v4)); for(const auto i: v4) { std::cout << i << ' '; } std::cout << std::endl; }