Iterating over MPL container

Given an MPL container: struct A{}; struct B{}; typedef boost::mpl::vector AB and a templated function, specialized for all members of the MPL container: template<class T> void foo(); template<A> void foo(); template<B> void foo(); I would like to be able to generate the code: foo<A>(); foo<B>(); automatically using AB somehow. That is, I would like to iterate through the MPL container and generate a call to void Foo<T>(); for each member T in the container. How do I achieve this? Best Regards, Johan Torp -- System Developer TouchTable AB Tel: +46 (0)31 773 68 12 johan.torp@touchtable.se

Johan Torp
Given an MPL container:
struct A{}; struct B{}; typedef boost::mpl::vector AB
and a templated function, specialized for all members of the MPL container:
template<class T> void foo(); template<A> void foo(); template<B> void foo();
I would like to be able to generate the code:
foo<A>(); foo<B>();
automatically using AB somehow. That is, I would like to iterate through the MPL container and generate a call to void Foo<T>(); for each member T in the container. How do I achieve this?
template <class T> struct id {};
struct callfoo
{
template <class T> void operator()(id<T>) const
{ foo<T>(); }
};
mpl::for_each
participants (2)
-
David Abrahams
-
Johan Torp