Boost logo

Boost :

From: Jaap Suter (J.Suter_at_[hidden])
Date: 2003-01-12 01:18:58


Hi,

I need some help with providing lambda support for my own meta functions. I
think this has to do with the following thread:

    http://aspn.activestate.com/ASPN/Mail/Message/1387917

but I can't really figure out what to do.

Basically, I have the following meta function (more complicated in real
life, but the number of parameters is the same)

    template< class A, class B, class C >
    struct meta_fun : mpl::plus< A, B, C > {};

And I use it as follows:

    template< class List, class Bar >
    struct foo
    {
        typedef typename mpl::fold<
            List,
            mpl::integral_c< size_t, 0 >,
            meta_fun< mpl::_1, mpl::_2, Bar >
>::type type;
    }

Perhaps it is interesting to note that only the first and second parameter
of the meta function are lambda'd. The last parameter is 'fixed' to Bar. Is
this at all possible with lambda, or do I need to 'bind' the third parameter
to create a meta-function that takes two parameters? It compiles on Intel
and GCC, so I guess it is supported.

In my actual code I'm not using mpl::plus but another meta-function that
tries to acces A::value_type and B::value_type. This works fine on Intel and
GCC, but MSVC gets the wrong types for A and B because it tells me that:

    error C2039: 'value_type' : is not a member of 'boost::mpl::arg<N>'
    with
    [
        N=2
    ]

This is wrong because at the point where the error occurs I'm asking for the
value_type member of something should be integral_c<> and not arg<>. I guess
the fix lies in the BOOST_MPL_AUX_LAMBDA_SUPPORT and VOID_SPEC macros. But I
don't really understand what these macros do (looking at their definitions
didn't really help either). I've tried something like:

    template< class A, class B, class C >
    struct meta_fun : mpl::plus< A, B, C >
    {
            BOOST_MPL_AUX_LAMBDA_SUPPORT( 3, meta_fun, (A, B, C) );
    };

but that didn't fix it.

I guess my question is: how would you define meta_fun so it supports lambda
on MSVC 7? Or if it's possible, do you have some time to give a short
explanation on the LAMBDA macros, what compiler-problems they try to fix,
and how they do it?

Any information will of course be updated in the Effective MPL wiki.

Thanks,

Jaap Suter


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk