Boost logo

Boost :

Subject: Re: [boost] Dereferencing End Iterators (Was: Performance Tuning?)
From: Edward Grace (ej.grace_at_[hidden])
Date: 2009-07-22 13:14:29


>> I assert that the problem is that the bounds checking in MSVC is
>> wrong - it should only be checking for the de-referencing of invalid
>> iterators not their creation.
>
> It is not valid according to the standard. The operational
> equivalent for v.begin() + n, in Table 76 (random access iterator
> requirements) is:
>
> vector::iterator tmp(v.begin());
> tmp += n;
>
> The operational semantics for tmp += n, same table, is:
>
> iterator_traits<vector::iterator>::difference_type m(n);
> if (m >= 0) while (m--) ++tmp;
> else while (m++) --tmp;
>
> Finally, the precondition for ++tmp, from Table 74 (forward
> iterator requirements), and for --tmp, from Table 75 (bidirectional
> iterator requirements), requires that tmp be dereferenceable.

Presumably the above requirement for the random access iterator is a
result of it being an extension of a forward iterator?

> Once n >= v.size(), the resulting iterator is no longer
> dereferenceable and the MSVC checking is valid.

Fair enough. It is what it is. As long as I know what to believe
I'm happy.

-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