Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-05-02 13:40:12


Peter Dimov wrote:
> Peter Dimov wrote:
>
>> Eric Niebler wrote:
>>
>>> Yes, but I was refering to native (C-style) strings, as in:
>>> BOOST_FOREACH(char ch, "hello world")
>>
>>
>> This is a good opportunity to ask: what does this do?
>>
>> char const a[] = { 0, 1, 2 };
>
>
> Or for extra fun, drop the 0.
>
>> BOOST_FOREACH( int x, a )
>> {
>> std::cout << x << std::end;
>> }
>

The short answer is: it is consistent with how Boost.Range handles it.
The longer answer is that it is treated as a null-terminated string. In
the first case, the loop immediately terminates and in the second,
behavior is undefined -- you read off the end of the array because it is
not null-terminated.

I think this is OK. If you think this is a problem, you should discuss
it with Thorsten. Whatever we decide, FOREACH and Range should be
consistent.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

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