Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-11-13 07:35:25


Arkadiy Vertleyb wrote:
> Hi all,

Hi Arkadiy,

> I've been actively using MPL for about 2 weeks, and I like the library a
> lot. However, I have difficulties applying/understanding the lambda
> facility. Looks like all MPL algorithms are also lambda meta-functors, by
> the means of BOOST_MPL_AUX_LAMBDA_SUPPORT macro, that give them the
"apply"
> nested template.

They are all lambda-enabled, yes, but on a conforming compiler so is any
other class template (given that it has 5 or less type template parameters).
BOOST_MPL_AUX_LAMBDA_SUPPORT is needed only for broken compilers - see
http://tinyurl.com/uo0z.

>
> I would expect conflicts between those two roles, however in most cases
> there are not (I am curious why). Still, when I am trying to use, for
> example, the following meta-functor:
>
> select1st<_2>
>
> on a pair, my VC6 complains: error C2039: 'first' : is not a member of
> 'arg<2>'

BOOST_MPL_AUX_LAMBDA_SUPPORT is only a partial workaround; there are some
cases when it doesn't work (at least without some extra tweaking), and
'select...' templates are one of these cases (the details are usually not
worth one's time, but if you are really interested, see
http://tinyurl.com/uu8t). If you have to care about broken compilers, I
would recommend you to use 'bind' and 'select1st's metafunction-class form
instead:

    typedef apply2<
          bind1<select1st<>,_2>
        , char
        , pair<int,bool>
>::type res;

    BOOST_MPL_ASSERT_IS_SAME(res,int);

This one is guaranteed to work for all library templates.

HTH,
Aleksey


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