-
February 9th, 2009, 12:45 AM
#1
std::map.find
Hey,
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?)
Thanks
-
February 9th, 2009, 12:51 AM
#2
Re: std::map.find
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, 08:47 AM
#3
Re: std::map.find
Originally Posted by laserlight
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?
-
February 10th, 2009, 09:03 AM
#4
Re: std::map.find
Originally Posted by rohshall
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.)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|