Monday, September 22, 2008

I Love Functors. Part II

See Part I.
There's a better way using std::for_each()! With this, just use for_each() directly.

class Base
{
public:
virtual ~Base(){};
typedef std::list List;
struct Functor
{
virtual ~Functor(){}
virtual void operator()(Base& o) const=0;
};
static void Functorator(List& l, const Functor& f)
{
std::for_each(l.begin(), l.end(), f);
}
};

BTW -code formatted by http://formatmysourcecode.blogspot.com/
Thank you Greg Houston!

No comments: