
AMDG Patrick Loney wrote:
I've got some code which needs to call a template function on different objects (potentially in a for loop). I'm currently doing this using an array of function ptrs but like the idea of an array of types. <snip>
I believe this should be possible using the pre-processor or meta programming parts of boost but have no experience of either and was hoping for some pointers. Is it possible and is it, IYO, better than the function pointer method I'm currently using?
boost::mpl::for_each does what you want
http://www.boost.org/doc/libs/1_36_0/libs/mpl/doc/refmanual/for-each.html
(untested):
template<class T>
struct wrap {};
struct func_f {
typedef void result_type;
template<class T>
void operator()(const wrap<T>&, const std:;string& s) const {
func<T>(s);
}
};
int main() {
boost::mpl::for_each