Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2001-07-26 10:58:43


----- Original Message -----
From: Jeremy Siek <jsiek_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, July 26, 2001 12:44 PM
Subject: RE: [boost] Re: Boost algorithm library

> On Thu, 26 Jul 2001, Fernando Cacciola wrote:
> > (*) Now consider how would this look like if the range is encapsulated
in a
> > single class.
> >
> > template <class Range>
> > void sort_heap (Range range)
> > {
> > Range::iterator first = range.begin() ;
> > Range::iterator last = range.end();
> > while (last - first > 1)
> > pop_heap( Range(first, last--) );
> > }
>
> I thought we were talking about providing a wrapper to the iterator-pair
> algorithms, not reimplementing the algorithms in terms of ranges.
>
Obviously, I'm not making myself any clear.
I showed sort_heap() as a mere example of an algorithm that uses a subrange.
Just pretend it is something you wrote yourself.
My big point is that the expressions that would create the subranges will
create whole new containers with duplicate elements if the object passed to
the algorithm is a true container and not a range class object.
That's why I suggested either to stick with a pair or use a range class that
cannot be replaced by a container, such as a class having first/last instead
of begin/end.

If I were to reinvent the STL, I would separate containers from ranges right
from the start. That is, a container would have a member function range()
returning a range object, and all the algorithms would use range objects.
Unfortunately, we can just wrap STL, but that should be done carefully.

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


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