MultiFunctor implementation trouble
Hello all!
I want to implement MultiFunctor class.
Consider the following example:
// MultiFunctor object
MultiFunctor<void (int, string)> mf;
// Type of MultiFunctor's content
typedef Functor<void (int,string)> Func_t;
// Functors
Func_t f1(&some_func);
Func_t f2(some_functor);
Func_t f3(&som_obj, &SomeClass::SomeMemberFunction);
// Add functors
mf+=f1;
mf+=f2;
mf+=f3;
// Call ALL functors
mf(100,"Hello World"); // Calls all functors
// Delete one functor
mf-=f2;
// Call f1 and f3
mf(200,"Only f1 and f3");
It's fine!
But there is a big problem - how to implement operator -=?
template <class T>
MultiFunctor& MultiFunctor::operator -=(const T& functor )
{
typedef SomeContainer::iterator IT;
for(IT i = container_.begin(); i!=container_.end();++i)
{
if( *i == functor) // !!! Main problem is here !!!
{
container_.erase(i);
break; // Supposing there are not duplicates in container
}
}
return *this;
}
The main question:
Is there a way to compare two functors???
Thanks!
P.S.
I know about another approach:
ID_t id1 = mf.add(f1);
ID_t id2 = mf.add(f2);
ID_t id3 = mf.add(f3);
mf(1000,"Bad solution"); // Calls f1,f2,f3
mf.delete(id2);
mf(1000,"Bad solution"); // Calls f1,f3
But it's a ugly hack :(