|
Boost : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-11-02 03:12:22
David Abrahams wrote:
> Aleksey Gurtovoy <agurtovoy_at_[hidden]> writes:
>
> > <digression>
> > Of course ideally Fusion and MPL should interpolate
>
> Do you mean interoperate?
Yep.
> > so that the above could be written as
> >
> > struct make_vehicle
> > {
> > template< typename T > struct result
> > {
> > typedef vehicle* type;
> > };
> >
> > template< typename T >
> > vehicle* operator()(identity<T>, vehicle* ptr) const
> > {
> > return new T(ptr);
> > }
> > };
> >
> > int main()
> > {
> > vehicle* result = fusion::fold(
> > fusion::identity_view<
mpl::vector<vehicle,car,bicycle,train>
> >>()
> > , static_cast<vehicle*>(0)
> > , make_vehicle
> > );
> >
> > return 0;
> > }
> > </digression>
>
> I'm not sure why that's an improvement.
IMO the way the OP problem is formulated, it literally screams for
'fold'/'accumulate':
> vehicle* make(vehicle* v0)
> {
> vehicle* v1 = new car( v0 );
> vehicle* v2 = new bicycle( v1 );
> vehicle* v3 = new train( v2 );
> return v3;
> }
And then the 'fold' version requires less code on the user side.
> Is identity_view supposed to
> default-construct a vehicle,car, bicycle, and train?
Nope, it constructs 'identity<vehicle>', 'identity<car>', etc.
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk