#include #include #include using namespace std; template void print(vector v) { for(auto it = v.cbegin(); it!=v.cend(); it++) cout << *it << ", "; cout << endl; } class PrefixString { string prefix; public: PrefixString(string p): prefix(p) {} void operator()(string& str) { str = prefix + str; } }; int main() { vector colors; colors.push_back("red"); colors.push_back("green"); colors.push_back("blue"); print(colors); for_each(colors.begin(), colors.end(), PrefixString("light ")); print(colors); }