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.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

All Comparison Function Objects

Core comparison functors

Transparent and ranges-oriented forms

Where they are used

Practical rules

Small worked example

#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.

Comparator sanity check

Example in practice

#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;
}