From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-06-03 15:28:49


christopher diggins wrote:
> From: "Peter Dimov" <pdimov_at_[hidden]>
>
>> Neal Becker wrote:
>>
>>> Here's my version:
>>
>> [...]
>>
>> One interesting problem with strided iterators is coming up with end
>> values. Suppose you have
>>
>> int x[ 4 ];
>>
>> and you want to iterate over x[1] and x[3] with stride 2. Your begin
>> iterator will be x+1, and your end iterator will be x+5 - an invalid
>> address.
>
> I am very confused, isn't x+4 also an invalid address? What is the
> difference between x+4 and x+5 or any other address not within the
> range x to x+3 ?

x+4 is valid but not dereferenceable. x+5 is invalid, it can't be copied or
used in comparisons. None of today's platforms enforce this for pointers,
but other random access iterators might.