I would like to generate one call to a templated function for each type
in an MPL sequence. Which is the best way to do this?
E.g.:
typedef vector SomeVector;
template <typename T> write_size() { std::cout << sizeof(T) << " "; }
Should somehow expand to:
write_size<float>();
write_size<double>();
write_size<long double>();
I have managed to do this "manually" in a fairly general way, what I'm
looking for is some part of boost which replaces my ForEach struct below
or some nicer way of writing the same code:
==============================================
struct WriteSize
{
template<typename T> void Call() {write_size<T>();}
};
template struct ForEach
{
template <class Func> static void Call(Func& func)
{
func.Call<typename It::type>();
ForEach::Call(func);
}
};
template <class End> struct ForEach
{
template <class Func> static void Call(Func&) {}
};
// Then I can generate the calls by
WriteSize ws;
ForEach::type, end::type>::Call(ws);
==============================================
--
System Developer
TouchTable AB
Tel: +46 (0)31 773 68 12
johan.torp@touchtable.se