Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-08-20 22:59:13


Edd Dawson <edd_at_[hidden]> writes:

> Hello all,
>
> I have the following:
>
> template<typename T>
> void f() { /* ... */ }
>
> typedef boost::mpl::vector<int, long, double> my_vec;
>
> I'm looking for a way to call f<T>() for all types T in my_vec. I initially
> hoped that either an mpl algorithm or fusion::for_each might be able to
> accomplish this for me, but after reading through their docs this doesn't appear
> to be the case.

  struct call_f
  {
     template <class Wrapper>
     void operator()(Wrapper)
     {
         f<typename Wrapper::type>();
     }
  };

  mpl::for_each<my_vec, mpl::identity<_> >(call_f());

HTH,

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net