Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-09-13 10:23:05


Johan Torp <johan.torp_at_[hidden]> 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

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