[Insight-developers] add operator< and operator> support initk::Index

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Fri Jun 3 09:46:28 EDT 2005


I don't think there is a consistent way to define an order in list.
The code I'm proposing do the same as in functional languages or as in
string ordering.
We are able to sort a set of string because someone have define an
(arbitrary) order relation. Even if this order have no real meaning, it
allow lost of interesting things... I just propose to do the same with
indexes.

Regards,

Gaetan


On Fri, 03 Jun 2005 15:24:05 +0200, Miller, James V (Research)
<millerjv at crd.ge.com> wrote:

> What does it mean for an index to be "less than" another?
>
> In your code snippet, you are defining to "less than" to be: if any  
> component
> of the index1 is less than that component of index2, then index1 is less  
> than
> index2.  Also, if any component of index1 is greater than that component  
> in
> index2, then index1 is greater than index2.
>
> So [5, 100] is less than [10, 10] and [100, 5] is greater than [10, 10].  
> This
> seems inconsistent.
>
> I would propose that Index1 is less than Index2 if ALL the components of
> Index1 are less than the components of Index2.
>
> Index1 is greater than Index2 only if ALL the components of Index1 are
> greater than Index2.
>
> But then we wind up with a cases where an Index1 is NEITHER less than
> or greater than Index2 whenever some of the components of Index1 are less
> than and some of the components are greater than the components of  
> Index2.
>
> Jim
>
>
> -----Original Message-----
> From: insight-developers-bounces+millerjv=crd.ge.com at itk.org
> [mailto:insight-developers-bounces+millerjv=crd.ge.com at itk.org]On Behalf
> Of Gaetan Lehmann
> Sent: Friday, June 03, 2005 9:05 AM
> To: insight-developers at itk.org
> Subject: [Insight-developers] add operator< and operator> support
> initk::Index
>
>
>
> Hi,
>
> Is it possible to add support for < operator in Index class ? (and for >,
> to be consistent)
> The goal is to be able to put Index objects in stl set without having to
> write extra code.
>
> code to add can be :
>    /** Compare two indices. */
>    bool
>    operator<(const Self &vec) const
>      {
>      for (unsigned int i=0; i < VIndexDimension; i++)
>        {
>           if (m_Index[i] < vec.m_Index[i])
>             { return true; }
>           else if (m_Index[i] > vec.m_Index[i])
>             { return false; }
>        }
>      return false;
>      }
>
> Regards,
>
> Gaetan
>



-- 
Gaetan Lehmann <gaetan.lehmann at jouy.inra.fr>
Tel: +33 1 34 65 29 66
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
Web: http://voxel.jouy.inra.fr


More information about the Insight-developers mailing list