February 8th, 2009, 11:45 PM
Just wondering... if I'm storing my user defined type in a stl container and I use find... does find invoke the user defined types == operator in its search? (So I must define the == operator?)
February 8th, 2009, 11:51 PM
No, std::map's find() makes use of operator< instead, or the given predicate that is used to compare the keys to put them in the correct order. That said, if you are going to provide operator< it probably makes sense to provide operator== as well.
February 10th, 2009, 07:47 AM
Originally Posted by laserlight
Why do you say that he should provide operator== as well? Because he may use STL algorithms?
February 10th, 2009, 08:03 AM
That is one consideration, but what I had in mind was providing a complete interface. It just seems natural to me that if operator< is available then operator== should be available as well even though operator< is enough to determine equality. (But the converse is not true: operator== cannot be used to implement operator<, and that operator== is provided does not necessarily make it natural to provide operator< since it might not make sense, e.g., in the case of input iterators.)
Originally Posted by rohshall
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!