#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
class Test {
int val;
public:
Test() { val = 0; }
Test(int x) { val = x; }
bool showval() const { std::cout << val << " "; return true; }
int doubleval() { val += val; return val; }
int addval(int i) { val += i; return val; }
};
int main() {
std::vector<Test *> v;
v.push_back(new Test(1));
v.push_back(new Test(2));
v.push_back(new Test(3));
v.push_back(new Test(4));
v.push_back(new Test(5));
for_each(v.begin(), v.end(), std::mem_fun(&Test::showval));
std::cout << std::endl;
for_each(v.begin(), v.end(), std::mem_fun(&Test::doubleval));
for_each(v.begin(), v.end(), std::mem_fun(&Test::showval));
std::cout << std::endl;
for_each(v.begin(), v.end(), std::bind2nd(std::mem_fun1(&Test::addval), 10));
for_each(v.begin(), v.end(), std::mem_fun(&Test::showval));
std::cout << std::endl;
std::vector<Test *>::iterator p = v.begin();
while (p != v.end()) {
delete *p;
p++;
}
return 0;
}
/* end */