Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: C++
Expertise: Intermediate
Jul 28, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Equivalence Relationship in STL

Certain STL containers and algorithms require that you overload operator < for the class type they store as elements in order to sort and compare these elements. Note that STL derives the equality operator from the < operator by using the following construct

bool operator==( const T & arg1, const T & arg2)
 return (!(arg1<arg2)) && (!(arg1<arg2))

In other words, you don't need to define an overloaded version of operator == (or any other relational operator) because STL is clever enough to generate these operators from operator <. You only need to define an overloaded version of operator < for user-defined types.

Danny Kalev
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date