CKTIS / C++
std::greater — a greater-than comparison object
std::greater from <functional> creates a callable object that compares operands using >. Learn the distinction between std::greater<T> and the transparent std::greater<>.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <functional>
std::greater<T>{}(x, y)
std::greater<>{}(x, y) // std::greater<void>std::greater is a class template from <functional>, not a function. The expression std::greater<int>{} creates a callable object; calling it compares arguments using >.
std::greater<T> accepts const T& and const T&, returning bool. Argument conversions to T can change the compared values. std::greater<>, meaning std::greater<void>, deduces types separately, forwards arguments while preserving value categories, and preserves the result type of the > expression. It exposes the marker is_transparent.
Pointers follow an implementation-defined strict total order, including when the transparent variant uses built-in pointer comparison. Do not assume a portable ordering of unrelated objects.
The example checks ordinary and mixed-type comparisons. Equal numbers produce false: > does not mean >=.
Examples
#include <functional>
#include <iostream>
int main() {
constexpr std::greater<int> typed{};
constexpr std::greater<> transparent{};
static_assert(typed(7, 3));
static_assert(transparent(7, 3.5));
std::cout << std::boolalpha
<< typed(7, 3) << '\n'
<< typed(3, 3) << '\n'
<< transparent(3, 3.5) << '\n';
}
Result
true false false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.