Implementing normal algorithms using predicate versions
Matt Austern
austern@apple.com
Mon Nov 29 18:05:00 GMT 2004
On Nov 28, 2004, at 3:54 PM, Gabriel Dos Reis wrote:
>
> This is done by using
>
> namespace __gnu {
> struct less {
> template<class T>
> bool operator()(const T& lhs, const T& rhs) const
> { return lhs < rhs; }
> };
> }
I don't think this is quite right, though. I think what we actually
need is more like this:
namespace __gnu {
struct lt {
template<class T1, class T2>
static bool operator()(const T1& lhs, const T2& rhs) const
{ return lhs < rhs; }
};
}
There are some algorithms that are defined to use operator< where
nothing in the standard requires the two operands to have the same
type. A perverse user could construct a test case where a type
supports both heterogeneous and homogeneous comparisons and where they
do something different in a detectable way.
--Matt
More information about the Libstdc++
mailing list