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


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


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