Boost logo

Boost :

From: Alex Chovanec (achovane_at_[hidden])
Date: 2003-10-11 20:39:33

"Thorsten Ottosen" <nesotto_at_[hidden]> wrote in message
> "Brian McNamara" <lorgon_at_[hidden]> wrote in message
> Brian, thanks for your cat and dog example; the thing is that it could be
> necessary to sort polymorphic types or that Base is not polymophic.
> the hard thing is to make the copy copy pointers and not objects. The easy
> solution
> (which I'm leaning a little towards ) is simply to provide normal
> struct ptr_less_than
> {
> template< typename T >
> bool operator()( const T*l, const T* r)
> {
> *l < *r;
> }
> };
> sort( v.ptr_begin(), v.ptr_end(), ptr_less_than() );

One disadvantage of this approach is that it requires you to define
specialized function objects which act on pointers. If your operator*()
returns some sort of proxy, as you originally suggested, you can provide it
with an implicit cast to const T &. This will allow you to sort the
ptr_vector without defining ptr_less_than. You can simply use std::less<T>.

sort(v.ptr_begin(), v.ptr_end(), std::less<T>());


Boost list run by bdawes at, gregod at, cpdaniel at, john at