question...

James Crotinger JimC at proximation.com
Wed Apr 11 22:34:04 UTC 2001


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
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sourcerytools.com/pipermail/pooma-dev/attachments/20010411/1d6f1f37/attachment.html>


More information about the pooma-dev mailing list