Boost logo

Boost Users :

From: Joel de Guzman (joel_at_[hidden])
Date: 2007-03-16 19:21:50


Christian Henning wrote:
> Hi there, since there is no example in the docs and no test for it. I
> was wondering how to use fusion's transform metafunction.
>
> Here is what I want to do.
>
> template <typename T>
> struct add_vector
> {
> typedef std::vector<T> type;
> };
>
> struct A;
> struct B;
> struct C;
>
> int main()
> {
> typedef fusion::list< A, B, C > types;
> typedef fusion::transform< types, add_vector<> >::type vector_of_types;
>
> return 0;
> }
>
> The compiler is complaining that there are too few parameters for
> add_vector. In MPL you would just add _1 as the template parameter.
> But this doesn't work for fusion. So, how do I use it?

There is an example (at least a test). You can get that here:
libs/fusion/test/algorithm/transform/transform.cpp. The doc
also contains an example (see the transform docs)

This is one of the cases where Fusion differs from MPL. Fusion
requires a polymorphic function object for the transform. See
the docs on "Polymorphic Function Object". Having said that,
and looking at your code, it seems you do not need value
transformation (which is what Polymorphic Function Objects
do). All you are doing is type manipulation. I'd suggest you
to first work on an mpl sequence. Then, when you get your
desired MPL sequence, convert it to a fusion sequence through
fusion::as_xxx (see conversions in the docs). fusion::as_xxx
can take in any valid MPL sequence. Here's an example:

     typedef
         fusion::result_of::as_list<any_mpl_seq>::type
     list_of_vectors;

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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