Boost logo

Boost Users :

Subject: Re: [Boost-users] [MPL][FUSION] generate fusion::map from mpl::vector
From: Adam Merz (adammerz_at_[hidden])
Date: 2008-09-28 17:23:13


Manuel Jung <gzahl <at> arcor.de> writes:
> Hi,
>
> I get as template parameter a mpl::vector with various types. Now want to
> generate one object of each type. To do so, i like to generate a
> fusion::map, which has as key the type itself (from the mpl::vector) and as
> object e.g. boost::promise_stream< type >.
>
> Well this is what i've got so far:
>
<snip>
>
> This compiles fine. But i'm not able to generate some fusion::map from the
> Out_type.
> I get compiling errors than. Well I'm new to the whole MPL and fusion stuff.
> Am i doing the right things? Or maybe my goal could be achived easier?

I don't have a compiler handy, so I couldn't attempt to compile your code to see
if there was a simple fix, but the following should work (untested):

namespace fusion = boost::fusion;
namespace mpl = boost::mpl;

template<typename T>
struct make_out_signature_pair
{
    typedef typename fusion::result_of::make_pair
    <
        T, boost::promise_stream<T>
>::type type;
};

template<typename OutSignatures>
struct filter_impl
{
    typedef typename fusion::result_of::as_map
    <
        typename mpl::transform
        <
            OutSignatures,
            make_out_signature_pair<mpl::_1>
>::type
>::type OutMap;
};

filter_impl<Sequence>::OutMap is now an instantiable fusion::map. Two noteworthy
things: First, the value type of the map (e.g. boost::promise_stream) must be
default constructable. Second, by default the maximum size of an mpl::vector is
20 and of a fusion::map is 10. So if you have 10+ elements in your OutSignatures
sequence, you'll need to define the BOOST_MPL_LIMIT_VECTOR_SIZE and/or
FUSION_MAX_MAP_SIZE macros before including any boost headers. See
http://ln-s.net/2GhE and http://ln-s.net/2GhF for more details.


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