|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-07-26 11:13:56
From: "Ed Brey" <edbrey_at_[hidden]>
> From: "Jeremy Siek" <jsiek_at_[hidden]>
> >
> > 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
>
> When will the reference ever need to be non-const? All the underlying
> algorithms take iterators by value, and hence leave them untouched.
When you decide to add an overload:
template<class R> void sort(R & r)
{
std::sort(r.begin(), r.end());
}
template<class T> void sort(std::list<T> & l)
{
l.sort();
}
A better question would be "why would you need to use make_range() at all
when using the iterator-based version is more concise in this case?"
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk