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?)
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.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
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.
Hi Laserlight,
Why do you say that he should provide operator== as well? Because he may use STL algorithms?
Why do you say that he should provide operator== as well? Because he may use STL algorithms?
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.)
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
Bookmarks