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

Miller, James V (Research) millerjv at crd.ge.com
Fri Jun 3 09:24:05 EDT 2005


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
_______________________________________________
Insight-developers mailing list
Insight-developers at itk.org
http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list