In STL containers, like map and set – How the unique key is determined for user-defined types?
In C#, this is done by overriding GetHashCode and Equals methods.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A map, for example, takes 4 parameters as its template arguments. Most of the time, developers use just 2 of them i.e. the
Keytype and theValuetype. But, one can also provide a functor that compares objects of theKeytype (whatever type it would be).From cplusplus.com:
http://www.cplusplus.com/reference/stl/map/
It is true for almost all cases (when using for sorting, or for any other container) and this principle holds across quite a few languages and platforms.