This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: STL and Mozilla XPCOM
- From: Joe Buck <jbuck at synopsys dot COM>
- To: tobias dot oberstein at gmx dot de (Tobias Oberstein)
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Tue, 19 Feb 2002 13:37:04 -0800 (PST)
- Subject: 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() .