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


>
>
>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






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