Subject: Re: [boost] Iterator Range and operator==
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-04-21 05:33:30
on Sat Apr 21 2012, Olaf van der Spek <ml-AT-vdspek.org> wrote:
> On Fri, Apr 20, 2012 at 3:19 PM, Mathias Gaunard
> <mathias.gaunard_at_[hidden]> wrote:
>> On 20/04/12 14:15, Olaf van der Spek wrote:
>>> What do you expect this code to do? Is b true or false? And why?
>>> Is this expected behaviour?
>>> int main()
>>> Â Â Â Â std::string s = "Olaf";
>>> Â Â Â Â boost::iterator_range<std::string::iterator> Â r(s);
>>> Â Â Â Â bool a = r == s;
>> a is true.
>>> Â Â Â Â bool b = r == "Olaf";
>> b is false, "Olaf" is one character longer than r.
> It is current behaviour. But is it expected behaviour?
Yes. Until the language gives us a way to distinguish string literals
from other arbitrary arrays of char, it's the best we can do. The
alternative is to have generic code suddenly stop working when T==char.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk