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: First patch to simplify <algorithm>


caj <caj@cs.york.ac.uk> writes:

| > I have a slight preference for  (1) putting the stuff in __gnu_cxx::
| >  (2) using standard names, e.g. equal, less, greater, ...
| >      They are already reserved for implementation.
| >  (3) making the operator a member template, instead of parameterizing
| >      the whole class; they should be const-members.
| >
| >E.g.
| >
| >   namespace __gnu_cxx   {
| >      struct less {
| >         template<class _Tp1, class _Tp2>             bool
| > operator()(const _Tp1& __lrhs, const _Tp2& __rhs) const
| >           { return __lhs < __rhs; }
| >   }
| >
| >
| >
| For some reason I thought I couldn't declare this as a member
| template. I'm really not sure why now, and it's clearly neater, as now
| there is no need to pass the type at all. I agree with all these
| points, other than (possibly) calling them equal, less, greater. I'm a
| little worried about possible collisions with the "normal" less,
| equal, greater, although such things should be easily avoidable (as
| you say).

I don't see why there should be collision with "normal" less.  Do you
have scenario in mind?
(I just hate uglified names :-))

| The only very minor thing I've noticed is that in theory someone could
| notice/detect this change, as now we will always be calling operator<
| on const objects whereas before we were calling it on non-const
| objects. A bunch of overloads could be introduced, but I'm sure people
| can't assume we are going to be calling non-const operator<, and if
| anyone is relying on it we can stand on them until they are quiet.

That is a possibility but, I don't think you can play with operator<
and expect any sensible or reliable answer back from standard algorithms. 
You can add a second overload -- that takes non cont refs.

-- Gaby


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