This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/8780: std::vector iterators not recognized as pointersby templates in certain cases
- From: Joe Buck <jbuck at synopsys dot com>
- To: gcc-gnats at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, johnb at stl dot sarov dot ru, gcc-bugs at gcc dot gnu dot org, paolo at gcc dot gnu dot org
- Date: Wed, 04 Dec 2002 10:21:03 -0800
- Subject: Re: libstdc++/8780: std::vector iterators not recognized as pointersby templates in certain cases
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=8780
Thanks for the report, but this is not a bug.
Any code that assumes that a vector<T>::iterator is a pointer is
non-portable
and will break on many C++ implementations (including debug implementations,
which use extra fields in the iterator to detect dereferencing of out of
range
iterators).
If you have code that makes such assumptions, then for cases where you know
that the iterator is not pointing to vec.end(), the construct &*iter
will give
a valid pointer to the data (and you may portably assume that the data are
stored contiguously in the vector). A portable one-past-the-end pointer is
1+&vec.back() .