|
![](/i/fill.gif) |
Nicolas Alvarez wrote:
> Darren New wrote:
>> In C++ you call
>> qsort(myArray, operator< );
>> or some such syntax, but without the need to have a specifically named
>> function just to wrap up the < operator.
>
> std::sort(myArray) is all you need. Guess *how* the operator< is used by
> default?
>
> template <typename T> bool less(const T& x, const T& y) {
> return x < y;
> }
>
> std::sort uses std::less as the default sorting function.
>
Yep. And now what do you do if the "less" you want to use is actually a
member function of type T? What if the "less" you want to use is
class MyDate {
bool comesBefore(const MyDate& otherDate);
}
--
Darren New, San Diego CA, USA (PST)
"Ouch ouch ouch!"
"What's wrong? Noodles too hot?"
"No, I have Chopstick Tunnel Syndrome."
Post a reply to this message
|
![](/i/fill.gif) |