sort error with ranges
John W. Eaton
jwe at bevo.che.wisc.edu
Fri Feb 8 14:34:06 CST 2008
On 8-Feb-2008, David Bateman wrote:
| John W. Eaton wrote:
| > Also, shouldn't the sortmode enum be inside the octave_sort class?
| >
| Yes, I remember trying that then stop due to an issue I can't remember.
| Why not try placing it the octave_sort class as this would be better for
| the namespace separation.
OK, I see the problem now. You have to write something like
octave_value
sort (octave_idx_type dim = 0,
octave_sort<T>::mode mode = octave_sort<T>::UNDEFINED) const;
but it's not always clear what T should be.
If we only have ascending and descending sorts, then what about just
using
octave_value
sort (octave_idx_type dim = 0, bool ascending = true) const;
instead? I know that the calls will then be like
foo = sort (dim, true);
and that is not quite as readable as
foo = sort (dim, ascending);
but it does avoid the namespace problem. Or, we could define a new
type just for the mode, something like
struct
octave_sortmode
{
enum
{
ascending,
descending
};
};
Then we could write
octave_value
sort (octave_idx_type dim = 0, int mode = octave_sortmode::ascending) const;
I'll eliminate the UNDEFINED mode next, but wait on deciding what to
do about the enum.
jwe
More information about the Bug-octave
mailing list