Boost logo

Boost :

Subject: Re: [boost] Iterator Range and operator==
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2012-04-20 08:40:18


On Friday 20 April 2012 14:15:50 Olaf van der Spek wrote:
> Hi,
>
> What do you expect this code to do? Is b true or false? And why?
> Is this expected behaviour?
>
> #include <boost/range/iterator_range.hpp>
> #include <string>
>
> int main()
> {
> std::string s = "Olaf";
> boost::iterator_range<std::string::iterator> r(s);
> bool a = r == s;
> bool b = r == "Olaf";
> assert(a);
> assert(b);
> return 0;
> }

I would prefer it to not compile. It is not clear what b should be initialized
with because the "Olaf" argument can be interpreted as either an array of 5
characters or a string of 4 characters.

If you wrap "Olaf" with as_literal, b should be initialized with true (because
ranges are compired element-wise).


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