using set::find() when it contains a struct or class

Quote:

> I forgot to include that function, but it went along the lines of:

> bool operator < (const Fun& fun )

> {

> return x < fun.x && d < fun.d && str < fun.str;

> }

That is not strict weak ordering so your set is broken.

If in your struct

struct Fun

{

int x;

double d;

std::string str;

Quote:

};

x is primary, d is secondary and str is tertiary (meaning the sets orders on

x, if x is equal then d and d is equal then str) then

bool operator < (const Fun& fun )

{

if (x < fun.x)

return true;

else if (x > fun.x)

return false;

else if (d < fun.d)

return true;

else if (d > fun.d)

return false;

else

return (str < fun.str);

Quote:

}

follows strict weak ordering.

Quote:

>> Any suggestions on improving this?

That depends on what you want "less than" to means for this struct. If I had

struct OneOfTheStatesInUSA

{

long population;

double gdp;

double area;

string name;

Quote:

};

and I had a set of them, what would "less than" mean?

I could have 4 sets, ordered by the least populous of the states to the

most populous, the poorest to the richest, the smallest in terms of size to

the largest, and finally the states in alphabetical order. In each case

"less than" means something different.

Nobody can "improve" on what you have until you say "less than" means for

your struct. And your "less than" has to behave the same way as a "less

than" does for integers which means that if you know that two arbitrary

elements x, y of your struct are not equal then if

(x < y) is true

then

(y < x)

must return false for arbitrary x, y

Stephen Howe