CKTIS / C++
std::equal_to — equality function object
std::equal_to from <functional> wraps operator ==. The typed T form returns bool, while std::equal_to<> deduces both argument types.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <functional>
std::equal_to<T>{}(x, y)
std::equal_to<>{}(x, y) // std::equal_to<void>std::equal_to from <functional> creates an object callable like a function. std::equal_to<T> accepts arguments through const T& and returns bool from x == y. Argument passing can involve conversions to T.
std::equal_to<>, meaning std::equal_to<void>, independently deduces both types and perfectly forwards arguments to ==. It preserves the expression's result type and exposes the type marker is_transparent. Comparing different types still requires a valid == expression.
Both forms have a constexpr operator(). They do not define new equality semantics: they use the available ==, including overloads.
Examples
#include <functional>
#include <iostream>
int main() {
constexpr std::equal_to<int> typed{};
constexpr std::equal_to<> transparent{};
static_assert(typed(7, 7));
static_assert(transparent(7, 7L));
std::cout << std::boolalpha
<< typed(7, 8) << '\n'
<< transparent(7, 7L) << '\n';
}
Result
false true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.