#include #include #include #include #include using namespace std; int main() { vector v{1,2,3,4,5,6}; function f = [](string str, int x) -> string { string rslt=str+to_string(x) + " "; return rslt; }; cout << "reduce with f : " << accumulate(v.begin(), v.end(), string(" "), f) << endl; int count=0; string name="v"; function fc = [&](string str, int x) -> string { string rslt=str + name + "[" + to_string(count++) + "]=" + to_string(x) + " "; return rslt; }; cout << "reduce with fc : " << accumulate(v.begin(), v.end(), string(" "), fc) << endl; return 0; }