Iterating over MPL container
Given an MPL container: struct A{}; struct B{}; typedef boost::mpl::vector<A,B> 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 <johan.torp@touchtable.se> writes:
Given an MPL container:
struct A{}; struct B{}; typedef boost::mpl::vector<A,B> 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<AB, id<mpl::_> >(callfoo()); [Aleksey, can I help you with getting the docs generated for this? I know you showed the sources to me, but I can't find them in the repo!] -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Johan Torp