Boost logo

Boost Users :

Subject: Re: [Boost-users] mpl/fusion: metafunction to 'rangify'
From: Christopher Schmidt (mr.chr.schmidt_at_[hidden])
Date: 2009-12-22 18:23:35


Hicham Mouline schrieb:
>> Hicham Mouline schrieb:
>>> I am making small progress in my attempt to generate a new mpl
>> sequence
>>> that I will use to read from a stream.
>>>
>>>
>>>
>>> The following code fails to compile:
>> [snip]
>>
>> You should work with a copy of fusion's trunk. See
>>
>> http://thread.gmane.org/gmane.comp.lib.boost.user/53893/
>>
>> for more information.
> Exactly what I just discovered. I copied the fix in
> fusion/adapted/struct/adapt_struct.hpp
> The is_sequence works but as you say below, mpl::transform doesn't.
>
>> Unfortunately there is another problem. mpl::transform internally
>> instantiates mpl::clear. Fusion's implementation of mpl::clear only
>> works for the built-in container. I think fusion's mpl::clear should
>> rather forward to fusion::clear and fusion::clear should return a
>> simple, empty container that models the same category as the sequence to
>> be cleared. At the moment, fusion::clear returns fusion::vector0<> in
>> any case.
>>
>> -Christopher
> Stjepan Rajko had a similar problem back in Feb09 and seems to have solved
> it, but I don't understand.
> He adds a bit of code in (see pastebin)
> http://lists.boost.org/boost-users/2009/02/45051.php

This code provides a specialization of fusion's mpl::clear for adapted
arrays. This makes his particular use-case compile fine but this does
not solve the general problem.

>
> In the meantime, can I just use the fusion::transform on the adapted struct
> instead of mpl::transform?
> What I really want is a new fusion sequence the elements of which are the
> result of my metafunction applied on the elements of the adapted struct. So
> this seemed to be a mpl::transform job.

This should work fine:

struct make_fixed_or_range
{
        template<typename Sig>
        struct result;

        template<typename Self,typename Arg>
        struct result<Self(Arg)>
        {
                typedef fixed_or_range<Arg> type;
        };

        template<class Arg>
        typename result<make_fixed_or_range(Arg)>::type
        operator()(Arg);
};

typedef
boost::fusion::result_of::as_vector<boost::fusion::result_of::transform<params,make_fixed_or_range>::type>::type
params_fixed_or_range;

-Christopher


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