All Comparison Function Objects
All Comparison Function Objects
A compact scan page for comparison functors, transparent comparators, and ordering helpers used across algorithms and containers.
All Comparison Function Objects
A compact scan page for comparison functors, transparent comparators, and ordering helpers used across algorithms and containers.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
std::lessstd::greaterstd::equal_tostd::not_equal_tostd::less_equalstd::greater_equalstd::less<>std::ranges::lessstd::ranges::greaterstd::compare_three_waycompare_three_way and <=> when the domain benefits from explicit ordering-category modeling.#include <map>
#include <string>
#include <string_view>
int main() {
std::map<std::string, int, std::less<>> counts{{"Ada", 1}, {"Grace", 2}};
return counts.contains(std::string_view{"Grace"}) ? 0 : 1;
}
The benefit of std::less<> here is heterogeneous lookup: the code can search a std::map<std::string, ...> using std::string_view without building a temporary std::string.
#include <map>
#include <string>
#include <string_view>
int main() {
std::map<std::string, int, std::less<>> counts{std::pair{"Ada", 1}};
return counts.contains(std::string_view{"Ada"}) ? 0 : 1;
}