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]

Re: rel_ops issues


Joe Buck <jbuck@racerx.synopsys.com> writes:

| > Right.  But they don't perform identically on X<int>.  Which is the whole
| > purpose of the exercise.  
| 
| But if operator!= returns the same value as operator!(operator==), then
| the only difference is any side effects, like printing messages.  

The key word is "if" -- an assumption the library is not funded to
make since the standard algorithm description requires only operator==.

[...]

| My proposed fix is to add definitions like
| 
| template<typename _Iterator, typename _Container>
| inline bool
| operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
| 	   const __normal_iterator<_Iterator, _Container>& __rhs)
| { return !(__lhs == __rhs); }
| 
| and similarly for >, >=, <= to stl_iterator.h.  This is needed so
| that vector<T> works in a compilation unit that has said
| 
| using std::rel_ops::operator=;
| 
| or
| 
| using namespace std::rel_ops;
| 
| Without it there is a conflict between the two operator!= definitions.
| This third definition will be preferred to either of the other two
| for != on two vector iterators.
| 
| Objections?

Since __normal_iterator is a class the library put in for its own
purposes, it should ensure it works properly without introducing
unwanted semantics in user programs.  That pretty much exclude the
using-declaration and using-directive.  In fact, the solution is to
overload operator!=, operator<, operator>, operator<= and operator>=
for __normal_iterator. 

-- Gaby


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