Quote:

>Given

>inline bool operator < (const SomeClass &Elem1, const SomeClass &Elem2)

>{

> // details

>}

>and later you do

>SomeClassContainerIterator = lower_bound(SomeClassContainer.begin(),

>SomeClassContainer.end(), SomeClassValue);

>is it possible that for some STL implementations (including Dinkumware's)

>for

>Elem1 to be SomeClassValue ?

>Elem2 to be SomeClassValue ?

>Also same question for equal_range() and upper_bound().

>Does the standard say anything this?

Regardless, you have to be ready to handle comparison of equivalent

objects, and an object must be equivalent to itself. I don't think it

would be worthwhile to treat this specially, like when avoiding

self-assignment. I would just go ahead and do the comparison. I can't

find anything in the standard to prohibit comparison to self.

Quote:

>The reason I ask this is for SomeClass, there are some "Sentinel Values".

>They should be less than any member of the class and greater than any

>memeber of the class. I need to make sure that my < operator is well-defined

>and I don't get a comparison that results in false when it should be true

>etc.

A value can't be simultaneously less than and greater than all other

values, but it can be one or the other. Be sure your comparison

function returns false when two equivalent sentinel values are

compared.

Quote:

>If it turns out Elem1 and Elem2 can be SomeClassValue (for lower_bound), I

>will have to think very hard about my < operator and whether SomeClassValue

>being passed to lower_bound() is correctly defined.

These functions are defined in terms of a strict weak ordering

relation, which is a partial ordering with a definition of

equivalence, so you need to verify your comparison function fulfills

the following:

1. Is the relation you define irreflexive? f(x,x) must return false.

2. Is the relation transitive? If f(x,y) && f(y,z), then f(x,z) must

also be true.

3. If !f(x,y) && !f(y,x) is true, then x and y are equivalent. (This

relation derived from f() is an equivalence relation.)

--

Doug Harrison [VC++ MVP]

Eluent Software, LLC

http://www.eluent.com

Tools for Visual C++ and Windows