I am specializing the \'less\' (predicate) for a data type.
The code looks like this:
template<>
struct std::less
{
bool
Even though the question has been answered by others with answers on how to specialize std::less (by wrap them in a namespace block) and the right way to do it ( to overload operator <).
However, C++ now allows (in C++11) to speciliaze the way you did in your first example.
An explicit specialization shall be declared in a namespace enclosing the specialized template. An explicit specialization whose declarator-id is not qualified shall be declared in the nearest enclosing namespace of the template, or, if the namespace is inline (7.3.1), any namespace from its enclosing namespace set. Such a declaration may also be a definition. If the declaration is not a definition, the specialization may be defined later (7.3.1.2).
I tried the following code with g++ (8.3.0) on my Ubuntu machine.
#include
#include
The above code was compiled with
g++ --std=c++11 compare.cpp -Wall