Tuesday, February 9, 2010

Delete all pointers in a STL container

#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_object.hpp>

#include <algorithm>
#include <vector>
#include <iostream>

using namespace boost::phoenix;
using namespace boost::phoenix::arg_names;

class A
{
   public:
   ~A() { std::cout << "A deleted\n"; }
};

int main()
{
     std::vector vec;
     vec.push_back(new A);
     vec.push_back(new A);

     std::for_each (vec.begin(), vec.end(), delete_ (arg1));
}

No comments:

Post a Comment