devxlogo

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

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.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.