[ create a new paste ] login | about

Link: http://codepad.org/68IKNmNf    [ raw code | output | fork ]

C++, pasted on Jan 28:
#include <iostream>
#include <list>
#include <algorithm>
#include <memory>

class Hoge {
public:
  int *hoge;
  struct {
    int hoge;
  } hage;
  Hoge(int hoge) {
    this->hoge = new(std::nothrow) int;
    if (this->hoge)
      *(this->hoge) = hoge;
    hage.hoge = (hoge % 3 == 0) ? true : false;
  }
  ~Hoge() { delete hoge; }
};

// not used <functional>
class HogeP {
public:
  bool operator()(Hoge *hoge) {
    struct Hage {
      bool hoge;
    } hage;
    if ((hage.hoge = hoge->hage.hoge) == true) delete hoge;
    return hage.hoge;
  }
};

class HogeS {
public:
  void operator()(Hoge *hoge) { std::cout << *(hoge->hoge) << std::endl; }
};

int main() {
  struct {
    int hoge;
  } hage;
  std::list<Hoge *> hoge;
  for (hage.hoge = 0; hage.hoge < 10; hage.hoge++)
    hoge.push_back(new(std::nothrow) Hoge(hage.hoge));


  for_each(hoge.begin(), hoge.end(), HogeS());
  hoge.remove_if(HogeP());
  hoge.erase(remove_if(hoge.begin(), hoge.end(), HogeP()), hoge.end());
  for_each(hoge.begin(), hoge.end(), HogeS());
  while (!hoge.empty()) {
    delete *(hoge.begin());
    hoge.pop_front();
  }
  
  return 0;
}
/* end */


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
0
1
2
3
4
5
6
7
8
9
1
2
4
5
7
8


Create a new paste based on this one


Comments: