|
From: | James Crotinger |
Subject: | question... |
Date: | Wed, 11 Apr 2001 15:34:04 -0700 |
Is it safe to convert a vector<int>::const_iterator to a const int
* via something like void foo(const
vector<int> &a) { const
int *pBegin = &(a.begin()[0]); } In particular, is it allowable for operator[] for a const_iterator to
return by value instead of reference, in which case this would be taking the
address of a temporary. I’m trying to figure out a way to get the DynamicArray::destroy(begin,
end, …) stuff to work reliably for both vector<int> iterators and for int
pointers. Currently it is explicitly written for int pointers (there is a
virtual function call in the execution path, so I can’t rely on templates
here). Since vector iterators are usually typedefs to pointers, the current
code will usually work for vector iterators. But on some systems, or with some
compile options, it might not compile (if the iterators are implemented as
classes). However, I do know that vector guarantees contiguous storage, so if
there is a way to convert the iterator to an address of the corresponding
element in the container, this will work regardless of the way iterators are
implemented. Jim --------------------------------------------------- James A.
Crotinger Software
Research Scientist Proximation,
LLC |
[Prev in Thread] | Current Thread | [Next in Thread] |