Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Inbuilt / pre-defined comparator in cpp

Recently I learnt about comparators in cpp from STL.

I came to know we can use greater<>() as third argument for sorting instead of writing own logic.

Just curious to know how many inbuilt comparators are there in cpp.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The standard library defines pretty much what you would expect as analogues to the built-in operators:

std::equal_to      // ==
std::not_equal_to  // !=
std::less          // <
std::less_equal    // <=
std::greater       // >
std::greater_equal // >=

Since C++20 also constrained versions of all these comparison function objects in the std::ranges namespace as well as std::compare_­three_­way, which is the analogue to the built-in three-way comparison operator <=>.

For a reference of these function objects see https://en.cppreference.com/w/cpp/utility/functional#Comparisons.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading