Re: STL map question : directed to stl map expert(s)....
On 2007-09-22 07:52:24 -0400, Remco Vietor <remco@wanadoo.fr> said:
Maciej Sobczak wrote:
[snip]
To better understand the meaning of this in practical terms, imagine a
CPU that has dedicated registers for pointer-related operations. Such
registers can be different from general-purpose registers and can add
some verification for safety purposes. For example, they can be
coupled with the memory manager - every time you *just load* some
value to the pointer register, the automatic check is performed to
verify that the pointer is valid. If it's not, you get the trap and
then grey smoke (signal, core dump, whatever).
Most popular processors don't work this way, but the above scheme
might be valuable in safety-critical applications. With such CPU not
only you wouldn't copy an invalid pointer, you wouldn't be able to
even iterate past the end of an array.
[snip]
I may be completely wrong here, but wouldn't such behaviour invalidate a
number of standard algorithms (foreach, find, ..., where a pointer after
the last element of the sequence is used to signal the end of the
sequence)?
No, for a couple of reasons. First, if these pointers can't be
meaningfully compared, the problem is in the pointers, not in
algorithms. Second, such pointers aren't valid iterator types, since
iterators must provide a usable past-the-end value. In particular, note
that both C and C++ require that for an array arr of N elements, the
address arr+N must be a valid pointer.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]