This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: STL and Mozilla XPCOM



> 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() .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]