I'm trying to learn the new features of C++11 and I have this code:
void print(int t, string separator)
{
cout << t << separator;
}
int elements[] = { 10, 20, 30, 40, 50, 60, 40 };
string delim = " - ";
for_each(elements, elements + 7, bind2nd(ptr_fun(print), delim));
Output:
10 - 20 - 30 - 40 - 50 - 60 - 40 -
About ptr_fun, this site says:
This function and the related types are deprecated as of C++11 in favor of the more general std::function and std::ref, both of which create callable adapter-compatible function objects from plain functions.
Can someone rewrite the example above without ptr_fun and with the functions recomended for C++11?
Thank you