Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-11-05 05:54:37


Sebastian Faust wrote:
> > When you're using a broken compiler you need to resort to slightly
> > uglier code. Try this definition of make_vehicle:
>
> I am using MS VC++ Net.2002. Maybe this helps you. Will this error occur
in
> the 2003 version too?

Nope, VC 7.1 will work just fine - both on Dave's version and on my original
snippet.

>
> >
> > struct make_vehicle
> > {
> > template< typename Base, typename T >
> > struct apply
> > {
> > static vehicle* make( vehicle* ptr )
> > {
> > return new T( Base::make( ptr ) );
> > }
> > };
> > };
> >
> > Now use make_vehicle instead of make_vehicle<_2,_1>
>
> I tried that, but again I get a compile-error:
> error: C2039: 'type': is not a member of boost::mpl::apply2<F, T1, T2>.
>
> What have I done wrong?

Nothing, you were just given untested code - sorry! This one works:

    struct make_vehicle
    {
        template< typename Base, typename T > struct apply
        {
            typedef apply type; // #1
            static vehicle* make( vehicle* ptr )
            {
                return new T( Base::make( ptr ) );
            }
        };
    };

> Sorry for these silly questions.

They are not silly at all :).

> Btw. can you maybe explain me why this error occurs?

The 'fold' algorithm (http://tinyurl.com/t8f5) requires that its third
parameter is either a _lambda expression_ (that thing with _1, _2, etc.
placeholders) or a _metafunction class_ (http://tinyurl.com/tphy). Without
the marked line (#1), 'make_vehicle' is neither, hence the error.

HTH,
Aleksey


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