Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-11-18 05:56:56


Rozental, Gennadiy wrote:
> > I hope you mean "what it does/how to use it" as opposite to
> > "how it does what it does" ;).
>
> In fact it is second ;-)

See http://aspn.activestate.com/ASPN/Mail/Message/boost/1156353 for the
sketch. The full implementation is just way too complicated to describe in
words. The code is always there, of course :).

>
> > // numbered placeholders semantics
> > plus<_1, int_c<5> > == bind<meta_fun2<plus>,_1,int_c<5> >
> > plus< int_c<5>,_1 > == bind<meta_fun2<plus>,int_c<5>,_1 >
> > plus< int_c<5>,_2 > == bind<meta_fun2<plus>,int_c<5>,_2 >
> > plus<_1,_2> == bind<meta_fun2<plus>,_1,_2>
> > plus<_2,_1> == bind<meta_fun2<plus>,_2,_1>
> >
> > logical_or< is_same<_1,int>, is_same<_1,long> >
> > = bind< meta_fun2<logical_or>
> > , bind< meta_fun2<is_same>,_1,int >
> > , bind< meta_fun2<is_same>,_1,long >
> > >
> >
> > is_same< _1, add_pointer<_2> >
> > == bind< meta_fun2<is_same>
> > , _1
> > , bind< meta_fun1<add_pointer>, _2 >
> > >
>
> It would help if you start with what meta_fun[n] are, cause
> they are not covered in docs.

'meta_fun[n]' (to be renamed to 'quote[n]') converts a metafunction
(http://www.mywikinet.com/mpl/paper/mpl_paper.html#metafunctions.simple) of
arity 'n' into the corresponding metafunction class
(http://www.mywikinet.com/mpl/paper/mpl_paper.html#metafunctions.classes).

> Also if I understand correctly it require
> template template parameters.

Yes.

> How then it works for MSVC6.5?

It ('meta_fun') doesn't. Lambda facility does, because on deficient
compilers it employs intrusive introspection:

    template< typename T > struct identity
    {
        typedef T type;
        BOOST_MPL_AUX_LAMBDA_SUPPORT(1,identity,(T)) // here
    };

The marked line is required if you want to use 'identity' in lambda
expressions on compilers that don't support partial specialization or
template template parameters.

[...]

> So the _ placeholder is substituted with appropriated numbered
> one based on position in expression. How did you managed to achieve
> this?

Well, I just do that - when resolving each bind's argument I analyze if it
is the unnamed placeholder, and if it is, then I substitute it for the
current numbered equivalent and "increment" the count. See
"boost/mpl/aux_/preprocessed/plain/bind.hpp" for the details. For comparison
purposes, "boost/mpl/aux_/preprocessed/plain/basic_bind.hpp" contains the
preprocessed version _without_ the unnamed placeholder support.

HTH,
Aleksey


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