STL and Mozilla XPCOM

Joe Buck jbuck@synopsys.COM
Tue Feb 19 13:37:00 GMT 2002


> i'm having a problem with a "&*something" idiom in the GNU STL,
> which occurs here..

It's not specific to the GNU implementation.  You'll find common uses
of such code; a number of authors writing on the STL recommend its use.

> .. maybe someone could explain the rationale behind this idiom?

An iterator is not necessarily a pointer, but in certain contexts
(e.g. vectors) we are promised that the elements are in contiguous
memory.  To get to this memory with an ordinary pointer, &*iterator
is used.  For example, let's suppose I use a vector<char> named v to hold
a null-terminated string, and then I want to pass that string to a
C function, such as strcpy.  I can't use v.begin() as the argument,
as it is not necessarily a pointer.  What I can use is &*v.begin() .



More information about the Libstdc++ mailing list