Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-02-28 08:55:50


"Andy Little" <andy_at_[hidden]> writes:

> "Andy Little" wrote
>
>> The expectation ( based on OP's light reading of examples I guess ) is this
>>
>> assert( boost::is_same <
>> mpl::transform<
>> vector_c<int,1,2,3> ,vector_c<int,1,1,1> ,some_plus_func
>> > ::type ,
>> vector_c<int,2,3,4>
>> >::value == true);
>>
>> Personally I think ( even ) that is with (some mods) a realistic expectation.
>
> FWIW Enclosed is a small sample which seems to work ok in VC7.1 and gcc4.01,
> bearing in mind its based on expectations not status quo
> Formatting of output works best in vc7.1 BTW.
>
> IOW Its not impossible to make it work.

<sigh> Nobody ever said it was impossible.

What you're doing here fails one of the primary design goals of the
MPL: in the same way that the STL iterator abstraction avoids an MxN
explosion of algorithm implementations (where M is the number of
algorithms and N is the number of data structures), the MPL is
designed to avoid the same kind of explosion. If you follow this
path, you will end up reimplementing every algorithm once for every
data structure.

Finally, even if you do meet the expectation, it will be incredibly
fragile: it becomes impossible to extend the library (or user code)
and continue to meet expectations. You add a new algorithm, and then
suddenly the expectation is broken for any user-defined sequence types
that you didn't know about. You add a new sequence, and the
expectation is broken for any user-defined algorithms you didn't know
about.

> Might be useful as a relatively simple demo anyway. Could also be
> used to explain the reasons for rejecting this approach too of
> course ;-)

I hope you find my explanation above satisfactory.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net