Boost logo

Boost :

From: Christoph Ludwig (ludwig_at_[hidden])
Date: 2006-07-12 06:27:42

On Tue, Jul 11, 2006 at 10:44:50AM -0700, Sean Parent wrote:
> What are the semantics of operator <?
> I'd state the following:
> 4. In the absence of established convention (such as from the domain
> of mathematics), lexicographical ordering by comparing the parts
> should be used.
> Examples from the standard: std::string (which does not sort by
> established linguistic rules), std::pair, std::vector, std::set,
> tr1::tuple.
> Counter examples (which should be fixed): std::complex (real,
> imaginary).
Do I understand correctly that you ask for

  namespace std {
    template<class T>
    bool operator<(const complex<T>& lhs, const complex<T>& rhs);

in the standard? That makes me certainly cringe!

complex<T> models the _arithmetic_ type of complex numbers.
If you order an arithmetic type A, then the ordering better respects the
arithmetic. That is (among other conditions), if a,b,c in A, a < b, and 0 < c,
then a * c < b * c. That implies, though, there cannot be an ordering
that respects the complex arithmetic. [Let a = 0, b = 1i, c = 1i and assume
you have an ordering with 0 < 1i. Then a < b, 0 = a * c > b * c = -1, i.e.,
your ordering does not respect the arithmetic. (If 0 > 1i, then
consider b = c = -1i.)]

Sure, you can "forget" the arithmetic structure of the complex numbers and
restrict them to their structure as a two dimensional real vector space; I
agree this is often useful and you can order finite dimensional vector
spaces. Bu then either implement the ordering in a named function or define
an appropriate type that models (2D) real vector spaces.

Defining operator< for complex<T> for convenience's sake seems to me an abuse
of operator overloading.

> Mathematicians do not have memory or complexity to deal with
> (mathematicians don't sort) - so arguing that the lack of a rule in
> mathematics implies that one shouldn't exist in computer science is
> vacuous.

You forgot the theory of Groebner bases. Mathematicians most certainly sort,
sometimes even with non-standard orders. :-)



FH Worms - University of Applied Sciences
Fachbereich Informatik / Telekommunikation
Erenburgerstr. 19, 67549 Worms, Germany

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