This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: STL and Mozilla XPCOM
- From: Tobias Oberstein <tobias dot oberstein at gmx dot de>
- To: Joe Buck <jbuck at synopsys dot COM>
- Cc: libstdc++ mailing list <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 21 Feb 2002 00:05:13 +0100
- Subject: Re: STL and Mozilla XPCOM
- References: <200202192137.NAA06568@atrus.synopsys.com>
>
>
>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()
>
Ah. That makes perfect sense, although it maybe looks unusual in the
first place, as the following "type equation" will hold for every
basic type, but as the example shows will not hold for user-defined types
in general
T == &*T for _all_ basic types
T == or != &*T for user-defined types
Looking back, its quite clear .. why should the general symmetry we're
accustomed to with op& and op* hold when overloading these? OK, I will
not get academic now;) Anyway, thanks for this nice hint ..
Tobias.
ps: in practice, I'm going to tackle this whole issue with
a little STL<->nsCOMPtr adapter class
http://www.brainthat.com/cvspublic/cvsweb/bt/btcomponents/btbase/nsSTLCOMPtr.h