From: Daryle Walker (darylew_at_[hidden])
Date: 2006-07-18 18:26:12
On 7/11/06 6:17 AM, "Peter Dimov" <pdimov_at_[hidden]> wrote:
> Daryle Walker wrote:
>>  If you make a fake order for "std::complex<>", would you compare
>> real components then imaginary components, or would you use magnitude
>> then angle?
> Real, then imaginary. Compare with:
It wasn't a challenge. It was just an example. I got the idea of it from
_The C++ Standard Library_ book by Nicolai M. Josuttis, who asked help from
David Vandevoorde on explaining why std::complex didn't have ordering. I
looked at the "Comparison Operations" part of section 12.1.2. (In this
section, Mr. Josuttis mentions the fake operator "<" trick, but warns
against polluting the standard namespace when defining an operator for
std::complex. He also mentions using a user-defined criterion.)
> "If you make a FAKE order for std::string, would you compare left to right
> or right to left?"
You don't need to define a "fake" order since std::string already comes with
ordering operators, and it comes with all of them. (Defining operator "<"
and deciding to skip the ">", "<=", and ">=" operators is a code smell.)
The ordering is lexicographic, which is left-to-right, assuming that's the
direction you write your letters. If std::string didn't have ordering
operators, I could provide comparison types for _both_ ways and let the user
decide. If you decided to pick a direction for operator "<" by fiat, users
that needed the other direction would have to make up a custom class anyway!
-- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com