[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: issorted & sortrows
From: |
John W. Eaton |
Subject: |
Re: issorted & sortrows |
Date: |
Wed, 11 Feb 2009 14:52:27 -0500 |
On 11-Feb-2009, Jaroslav Hajek wrote:
| On Wed, Feb 11, 2009 at 4:02 PM, John W. Eaton <address@hidden> wrote:
|
| > +bool (*_sortrows_comparator (sortmode mode,
| > + const Array<Complex>& a , bool allow_chk))
| > +(Complex, Complex)
| > +{
| >
| > This has me scratching my head. Maybe a typedef would help here, so
| > you could write this as
| >
| > sortrows_comparator_function
| > xsortrows_comparator (const Complex&, const Complex&)
| > {
| >
|
| Here, I simply copied the template from Array.cc
|
| template<class T>
| bool (*_sortrows_comparator (...))(T, T) { ... }
|
| I don't think this syntax can be simplified without introducing a
| traits class. For the specializations, one can introduce explicit
| typedefs (like you have shown) but it seems to me that it obscures
| somewhat the fact that it's a specialization (matching signatures).
I don't see why a traits class is needed. Won't something like the
following work?
diff --git a/liboctave/Array-d.cc b/liboctave/Array-d.cc
--- a/liboctave/Array-d.cc
+++ b/liboctave/Array-d.cc
@@ -52,11 +52,10 @@
return lo_ieee_isnan (x) ? ! lo_ieee_isnan (y) : x > y;
}
-bool (*_sortrows_comparator (sortmode mode,
- const Array<double>& a , bool allow_chk))
-(double, double)
+octave_sort<double>::compare_fcn_type
+_sortrows_comparator (sortmode mode, const Array<double>& a , bool allow_chk)
{
- bool (*result) (double, double) = 0;
+ octave_sort<double>::compare_fcn_type result = 0;
if (allow_chk)
{
diff --git a/liboctave/oct-sort.h b/liboctave/oct-sort.h
--- a/liboctave/oct-sort.h
+++ b/liboctave/oct-sort.h
@@ -135,6 +135,8 @@
static bool ascending_compare (T, T);
static bool descending_compare (T, T);
+
+ typedef bool (*compare_fcn_type) (T, T);
private:
It seems much clearer to have a typedef like this and be able to write
the function as
octave_sort<double>::compare_fcn_type
_sortrows_comparator (sortmode mode, const Array<double>& a , bool allow_chk)
{
octave_sort<double>::compare_fcn_type result = 0;
...
instead of
bool (*_sortrows_comparator (sortmode mode,
const Array<double>& a , bool allow_chk))
(double, double)
{
bool (*result) (double, double) = 0;
...
I now see I had it wrong in my earlier message because I was having
trouble deciphering the declaration.
If you don't like mixing the octave_sort and Array classes for this,
then I think you can put the typedef in the Array class instead.
BTW, why isn't _sortrows_comparator a member of the Array class?
jwe
- Re: issorted & sortrows, (continued)
- Re: issorted & sortrows, John W. Eaton, 2009/02/11
- Re: issorted & sortrows, Jaroslav Hajek, 2009/02/11
- Re: issorted & sortrows, David Bateman, 2009/02/11
- Re: issorted & sortrows, John W. Eaton, 2009/02/12
- Re: issorted & sortrows, Jaroslav Hajek, 2009/02/12
- Re: issorted & sortrows, John W. Eaton, 2009/02/12
- Re: issorted & sortrows, Jaroslav Hajek, 2009/02/12
- Re: issorted & sortrows, dbateman, 2009/02/12
- Re: issorted & sortrows, John W. Eaton, 2009/02/12
- Re: issorted & sortrows, Jaroslav Hajek, 2009/02/12
- Re: issorted & sortrows,
John W. Eaton <=
Re: issorted & sortrows, Jaroslav Hajek, 2009/02/11