It would be simpler to make the functor a template parameter:
template <class T1, class F>
static void FOREACH (T1 cont, F callback) {
typename T1::iterator it = cont.begin();
for ( ; it != cont. end(); it++ ) {
callback (*it);
}
}
This would work, provided you pass it a compatible callable entity that actually exists. Of course, it would be even easier to use std::for_each
:
#include <algoritm>
...
std::for_each(vec.begin(), vec.end(), Print);