#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>
using namespace std;
class E
{
public:
E(char const *value) : value(value)
{
}
void show()
{
printf("%s\n", value);
}
void show_in(int width)
{
printf("%.*s\n", width, value);
}
private:
char const *value;
};
class C
{
public:
C()
{
v.push_back("first");
v.push_back("second");
v.push_back("third");
}
void show_each()
{
for_each(v.begin(), v.end(),
mem_fun_ref(&E::show));
}
void show_each_in(int width)
{
for_each(v.begin(), v.end(),
bind2nd(mem_fun1_ref(&E::show_in), width));
}
private:
vector<E> v;
};
int main()
{
C c;
c.show_each();
c.show_each_in(3);
return 0;
}
/* expected output:
first
second
third
fir
sec
thi
*/
End of Listing