This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Implementing normal algorithms using predicate versions


Matt Austern <austern@apple.com> writes:

| 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.

Yes, you're right.

I notice your use of "static" to define "operator()" -- but alas C++
does not allow that.  I think I understand why you did that (at least,
I know that is what I would like to have! :-) 
I've rised the issue with Bjarne a month ago and I think he was
positive about removing that restriction.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]