On Jan 28, 6:46 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
ManicQin wrote:
struct greaterScale : public std::greater<PCOperation>
Btw, you don't have to inherit from std::greater (or any
comparator in the STL) in order to write a comparator.
This is template metaprogramming, not object-oriented
programming.
True, but providing additional information in the form of
typedefs is sometimes useful. I'd generally inherit from
std::binary_operator< Operation*, Operation*, bool > for
example. Since std::greater< Operation* > inherits from
this, he's effectively done so, with less characters to
type, but with the result of misleading the reader (since
his object manifestly has nothing to do with std::greater).
If you're doing much of this sort of thing, it might be
worth defining a ComparisonOperator class template:
template< typename ArgumentType >
struct ComparisonOperator
: std::binary_operator< ArgumentType, ArgumentType, bool >
{
} ;
and inheriting from it.
(I generally define a compare() member function, then derive
from a ComparisonOperators class template which defines all
of the comparison operators in terms of compare(), and
provides the typedefs.)
I'll take it to my consideration. But I still have the