#include <iostream>
#include <list>
#include <algorithm>
#include <memory>

class Hoge {
public:
  std::shared_ptr<int> p;
  bool tobe_deleted;
  Hoge(int n) : p(std::make_shared<int>(n)) { tobe_deleted = (n % 3 == 0) ? true : false; }
};

// not used <functional>
class EraseP {
public:
  bool operator()(std::shared_ptr<Hoge> p) { return p->tobe_deleted; }
};

class Show {
public:
  void operator()(std::shared_ptr<Hoge> obj) { std::cout << *(obj->p) << std::endl; }
};

int main() {
  std::list<std::shared_ptr<Hoge> > mylist;
  try {
    for (int i = 0; i < 10; i++)
      mylist.push_back(std::make_shared<Hoge>(i));
    
    for_each(mylist.begin(), mylist.end(), Show());
    //  mylist.remove_if(EraseP());
    mylist.erase(remove_if(mylist.begin(), mylist.end(), EraseP()), mylist.end());
    for_each(mylist.begin(), mylist.end(), Show());
    return 0;
  } catch (...) { std::cout << "exception occured, something wrong.." << std::cout; }
}
/* end */
