On Tue, Nov 07, 2000 at 10:23:47PM +0100, Lars Gullik Bj&resh;nnes wrote:
> Dekel Tsur <[EMAIL PROTECTED]> writes:
> 
> | Use
> | struct compare_formats {
> |      bool operator()(Format const & a, Format const & b) {
> |         return a.name < b.name;
> |      }
> | }
> | 
> | and then
> |     sort(formats_vec.begin(), formats_vec.end(), compare_formats());
> | 
> | PS Is there a template for simplfying this ?
> 
> 
> Yes, less<>  (e.g. less(Format>())

No. less<Format> requires having Format::operator<, which we don't have
(and if there is Format::operator<, it is suffices to write
sort(formats_vec.begin(), formats_vec.end()) ).
Is there something like less<Format, &Format::name>() ?

> Does sort take a function returning bool or one returning int? (-1
> less than 0 = equal 1  greater than)?

Bool: 

 void sort(RandomAccessIterator first, RandomAccessIterator last,
 StrictWeakOrdering comp);

 A Strict Weak Ordering is a Binary Predicate that compares two objects,
 returning true if the first precedes the second. This predicate must satisfy
 the standard mathematical definition of a strict weak ordering. The precise
 requirements are stated below, but what they roughly mean is that a Strict
 Weak Ordering has to behave the way that "less than" behaves: if a is less
 than b then b is not less than a, if a is less than b and b is less than c
 then a is less than c, and so on. 

Reply via email to