Boost logo

Boost :

Subject: Re: [boost] Iterator Range and operator==
From: Daryle Walker (darylew_at_[hidden])
Date: 2012-04-23 10:02:59


> From: mostafa_working_away_at_[hidden]
> Date: Sat, 21 Apr 2012 17:42:26 -0700
>
> On Fri, 20 Apr 2012 05:15:50 -0700, Olaf van der Spek <ml_at_[hidden]>
> wrote:
>
> > What do you expect this code to do? Is b true or false? And why?
> > Is this expected behaviour?
> >
> > [1] #include <boost/range/iterator_range.hpp>
> > [2] #include <string>
> > [3][4] int main()
> > [5] {
> > [6] std::string s = "Olaf";
> > [7] boost::iterator_range<std::string::iterator> r(s);
> > [8] bool a = r == s;
> > [9] bool b = r == "Olaf";
> > [10] assert(a);
> > [11] assert(b);
> > [12] return 0;
> > [14] }
> >
>
> I would expect both lines 8 and 9 to cause compilation failure. To
> someone unfamiliar with the library, it's not /immediately/ clear what the
> intent of either line is. If one wants to treat "s" as a range for the
> purpose of comparison, then one should explicitly adapt it to such. Ditto
> for line 9. It just makes the maintaining code that much easier. In the
> case of line 9, this has the additional benefit of forcing newcomers to
> ask what does make_iterator_range("Olaf") mean?, leading to a
> documentation look up that will preempt any potential surprises associated
> with char arrays and the library.
[TRUNCATE]
I'm guessing that Boost.Range handles the range traversal method that's acounter to the iterator traversal method.  If so, I was thinking the samething Mostafa did when reading this thread: the comparisons should causecompiler errors because the types shouldn't be conceptually directlycompatible.
Daryle W.
                                               


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk