octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add an operator<(Complex, Complex) to oct-sort.cc for non-g++ co


From: John W. Eaton
Subject: [PATCH] Add an operator<(Complex, Complex) to oct-sort.cc for non-g++ compilers.
Date: Fri, 30 Nov 2007 12:54:59 -0500

On 29-Nov-2007, Jason Riedy wrote:

| The standard rightly does not define ordering operators, but g++'s
| libstdc++ provides them.  Other compilers (e.g. icc) do not, and
| oct-sort.cc refuses to compile.  The included operator is never
| actually *used* in Octave; src/DLD-FUNCTIONS/sort.cc defines
| comparison functions for Complex sorts.

I don't see why this would be needed since the Complex versions of
these templates should not be instantiated except in
src/DLD-FUNCTIONS/sort.cc, which does provide a definition of
operator< for Complex values.  However, looking at that file, I
noticed that some of the functions there should probably pass
arguments by const reference instead of value, so I checked the
following changes.  Does that help?  If not, precisely what is the
error message you see from icc?

jwe


src/ChangeLog:

2007-11-30  John W. Eaton  <address@hidden>

        * DLD-FUNCTIONS/sort.cc (ascending_compare, descending_compare,
        operator < (const Complex&, const Complex&)):
        Pass args by const reference, not value.


Index: src/DLD-FUNCTIONS/sort.cc
===================================================================
RCS file: /cvs/octave/src/DLD-FUNCTIONS/sort.cc,v
retrieving revision 1.39
diff -u -u -w -r1.39 sort.cc
--- src/DLD-FUNCTIONS/sort.cc   25 Oct 2007 05:50:56 -0000      1.39
+++ src/DLD-FUNCTIONS/sort.cc   30 Nov 2007 17:54:37 -0000
@@ -67,14 +67,14 @@
 
 template <class T>
 bool 
-ascending_compare (vec_index<T> *a, vec_index<T> *b)
+ascending_compare (const vec_index<T> *a, const vec_index<T> *b)
 {
   return (a->vec < b->vec);
 }
 
 template <class T>
 bool 
-descending_compare (vec_index<T> *a, vec_index<T> *b)
+descending_compare (const vec_index<T> *a, const vec_index<T> *b)
 {
   return (a->vec > b->vec);
 }
@@ -442,32 +442,28 @@
 
 template <>
 bool
-ascending_compare (uint64_t a, 
-                  uint64_t b)
+ascending_compare (uint64_t a, uint64_t b)
 {
   return (a < b);
 }
 
 template <>
 bool
-ascending_compare (vec_index<uint64_t> *a, 
-                  vec_index<uint64_t> *b)
+ascending_compare (const vec_index<uint64_t> *a, const vec_index<uint64_t> *b)
 {
   return (a->vec < b->vec);
 }
 
 template <>
 bool
-descending_compare (uint64_t a, 
-                   uint64_t b)
+descending_compare (uint64_t a, uint64_t b)
 {
   return (a > b);
 }
 
 template <>
 bool
-descending_compare (vec_index<uint64_t> *a, 
-                   vec_index<uint64_t> *b)
+descending_compare (const vec_index<uint64_t> *a, const vec_index<uint64_t> *b)
 {
   return (a->vec > b->vec);
 }
@@ -800,37 +796,37 @@
 
 template <>
 bool
-ascending_compare (Complex a, Complex b)
+ascending_compare (const Complex& a, const Complex& b)
 {
-  return (xisnan (b) || (xabs (a) < xabs (b)) || ((xabs (a) == xabs (b))
-             && (arg (a) < arg (b))));
+  return (xisnan (b) || (xabs (a) < xabs (b))
+         || ((xabs (a) == xabs (b)) && (arg (a) < arg (b))));
 }
 
-bool
-operator < (const Complex a, const Complex b)
+static inline bool
+operator < (const Complex& a, const Complex& b)
 {
-  return (xisnan (b) || (xabs (a) < xabs (b)) || ((xabs (a) == xabs (b))
-             && (arg (a) < arg (b))));
+  return (xisnan (b) || (xabs (a) < xabs (b))
+         || ((xabs (a) == xabs (b)) && (arg (a) < arg (b))));
 }
 
 template <>
 bool
-descending_compare (Complex a, Complex b)
+descending_compare (const Complex& a, const Complex& b)
 {
-  return (xisnan (a) || (xabs (a) > xabs (b)) || ((xabs (a) == xabs (b))
-             && (arg (a) > arg (b))));
+  return (xisnan (a) || (xabs (a) > xabs (b))
+         || ((xabs (a) == xabs (b)) && (arg (a) > arg (b))));
 }
 
 bool
-operator > (const Complex a, const Complex b)
+operator > (const Complex& a, const Complex& b)
 {
-  return (xisnan (a) || (xabs (a) > xabs (b)) || ((xabs (a) == xabs (b))
-             && (arg (a) > arg (b))));
+  return (xisnan (a) || (xabs (a) > xabs (b))
+         || ((xabs (a) == xabs (b)) && (arg (a) > arg (b))));
 }
 
 template <>
 bool
-ascending_compare (vec_index<Complex> *a, vec_index<Complex> *b)
+ascending_compare (const vec_index<Complex> *a, const vec_index<Complex> *b)
 {
   return (xisnan (b->vec)
          || (xabs (a->vec) < xabs (b->vec))
@@ -840,7 +836,7 @@
 
 template <>
 bool
-descending_compare (vec_index<Complex> *a, vec_index<Complex> *b)
+descending_compare (const vec_index<Complex> *a, const vec_index<Complex> *b)
 {
   return (xisnan (a->vec)
          || (xabs (a->vec) > xabs (b->vec))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]