[boost.range] comparison operators for iterator_range and sub_range

Dear all, Another small issue have surfaced regarding operator==(), operator!=() and operator<() (the latter currently not there). The current behavior is compare the two underlying iterators. I would suggest to change this to compare the objects in the underlying range. The motivation would be the follwoing: 1. comparing the iterators is seldom useful and can be done explicitlty or by a new member function equal() 2. comparing the objects is the range is highly useful and allows for code like sub_range<string> sub = ...; if( sub == "foo" ) 3. operator<() cannot be defined for iterators in general and hence we couldn't put iterator_range into a set/map; Any comments? An additional question would be if operator> operator>= etc really needs to be defined? I would support just to have ==, !=, < to start with. br Thorsten

"Thorsten Ottosen" <nesotto@cs.auc.dk> wrote in message news:chqcic$joc$1@sea.gmane.org...
Dear all,
Another small issue have surfaced regarding operator==(), operator!=() and operator<() (the latter currently not there).
The current behavior is compare the two underlying iterators. I would suggest to change this to compare the objects in the underlying range. The motivation would be the follwoing:
1. comparing the iterators is seldom useful and can be done explicitlty or by a new member function equal() 2. comparing the objects is the range is highly useful and allows for code like
sub_range<string> sub = ...; if( sub == "foo" )
Wouldn't it be natural to define a collection-oriented version of std::equal from <algorithm> to perform this test?
3. operator<() cannot be defined for iterators in general and hence we couldn't put iterator_range into a set/map;
Would this be a lexicograpkical comparison? Jonathan

"Jonathan Turkanis" <technews@kangaroologic.com> wrote in message news:chqfj7$sh4$1@sea.gmane.org... | | "Thorsten Ottosen" <nesotto@cs.auc.dk> wrote in message | > sub_range<string> sub = ...; | > if( sub == "foo" ) | | Wouldn't it be natural to define a collection-oriented version of std::equal | from <algorithm> to perform this test? sure, but that might be frased in term of one range argument and one iterator argument...and it wouldn't be easy to use. | > 3. operator<() cannot be defined for iterators in general and hence we | > couldn't put iterator_range into a set/map; | | Would this be a lexicograpkical comparison? yes, simply forward to std::lexicographical_compare br Thorsten

Hi, On Thu, Sep 09, 2004 at 02:57:39PM -0600, Jonathan Turkanis wrote:
"Thorsten Ottosen" <nesotto@cs.auc.dk> wrote in message news:chqcic$joc$1@sea.gmane.org...
Dear all,
Another small issue have surfaced regarding operator==(), operator!=() and operator<() (the latter currently not there).
The current behavior is compare the two underlying iterators. I would suggest to change this to compare the objects in the underlying range. The motivation would be the follwoing:
1. comparing the iterators is seldom useful and can be done explicitlty or by a new member function equal() 2. comparing the objects is the range is highly useful and allows for code like
sub_range<string> sub = ...; if( sub == "foo" )
Wouldn't it be natural to define a collection-oriented version of std::equal from <algorithm> to perform this test?
Such an algorithm is already in string_algo lib (maybe it will be move elsewhere when better place will be found). However, the point is somewhere else. There are operators for vector, list and etc. It is natural to have it also for the iterator_range. Plus it can simplyfy the usage as stated in the example above.
3. operator<() cannot be defined for iterators in general and hence we couldn't put iterator_range into a set/map;
Would this be a lexicograpkical comparison?
This seem most natural. Regards, Pavol

"Pavol Droba" <droba@topmail.sk> wrote in message:
Hi,
On Thu, Sep 09, 2004 at 02:57:39PM -0600, Jonathan Turkanis wrote:
"Thorsten Ottosen" <nesotto@cs.auc.dk> wrote in message
1. comparing the iterators is seldom useful and can be done explicitlty or by a new member function equal() 2. comparing the objects is the range is highly useful and allows for code like
sub_range<string> sub = ...; if( sub == "foo" )
Wouldn't it be natural to define a collection-oriented version of std::equal from <algorithm> to perform this test?
Such an algorithm is already in string_algo lib (maybe it will be move elsewhere when better place will be found).
However, the point is somewhere else. There are operators for vector, list and etc. It is natural to have it also for the iterator_range.
Okay. I agree. Jonathan
participants (3)
-
Jonathan Turkanis
-
Pavol Droba
-
Thorsten Ottosen