Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-07-26 10:44:38


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.

template <class Range>
void sort_heap(Range& range)
{
  std::sort_heap(range.begin(), range.end());
}

BTW, there's one problem with the above. To efficiently pass in a
container we need pass-by-reference, but this will cause a problem if one
wants to call this with make_range().

sort_heap(make_range(first, last)); // error, binding temporary to a
                                    // reference

Ciao,
Jeremy

----------------------------------------------------------------------
 Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
 Ph.D. Candidate, IU B'ton email: jsiek_at_[hidden]
 Summer Manager, AT&T Research phone: (973) 360-8185
----------------------------------------------------------------------


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