|
Boost : |
Subject: Re: [boost] Dereferencing End Iterators (Was: Performance Tuning?)
From: Edward Grace (ej.grace_at_[hidden])
Date: 2009-07-22 13:52:58
On 22 Jul 2009, at 18:02, Christopher Jefferson wrote:
> On 22 Jul 2009, at 16:23, Stewart, Robert wrote:
>>
>>
>>> Ultimately are random access iterators *supposed* to be homeomorphic
>>> to the integers in the same (apparent) way C indices are?
>
> I'm sure that:
>
> int a[3]
> int* b = a + 4;
>
> Is illegal C code, as you have gone outside the bounds of your array,
> even if you never dereference the pointer.
Following your minimalistic example, I'm thinking about:
typdef int index;
int a[3];
index i = 0; // Index idx is homeomorphic to the integers 'cause it
is one.
i -= 1000;
i += 2002;
int b=a[i];
That's clearly ok as idx is 2 and the last line is b=*(a + 2).
Whereas.
int *p = a;
p = p - 1000; // Undefined?
p = p + 1002; // Also undefined?
int b=*p;
Is presumably undefined.
That implies to me that pointer arithmetic is *not* like integer
arithmetic since the first example is not identical to the second.
Baring in mind the old adage of Mark Twain,
http://www.quotationspage.com/quote/369.html
it seems to me absurd that they are not the same. I guess that's
just the way it is.
-ed
------------------------------------------------
"No more boom and bust." -- Dr. J. G. Brown, 1997
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk