Until C++14, std::greater<T>
was a class template based on one explicit type parameter T
. It only allowed to compare two equal types. Otherwise, when comparing different types, one had to rely on conversion which can fail in the process of template argument deduction.
This has been fixed with C++14 in the sense that now there also exists a general comparison of two distinct types. Instead of using a new class template std::greater<T,U>
(which possibly would not be backwards compatible and certainly also more complicate), a specialization std::greater<void>
is used which did not exist before C++14. The type void
is chosen for exactly this reason: as it was never used before C++14 -- comparison of void
s makes no sense -- one automatically gets backwards compatibility and even avoids introducing a new class template.
As it's described in the reference, std::greater<void>
now is a functor containing an operator()
function template similar to
template< class T, class U>
constexpr auto operator()( T&& lhs, U&& rhs ) const
{
return std::forward<T>(lhs) > std::forward<U>(rhs);
}
This implements the general comparison between two types (and is quite the same as one would come up with nowadays).