Article View: comp.std.c++
Article #1974Re: Implementing auto_ptr + type of operator->*
From: Ulf Schuenemann
Date: Fri, 15 Sep 1995 15:22
Date: Fri, 15 Sep 1995 15:22
75 lines
3493 bytes
3493 bytes
In article <9509080952.AA15973@jodium.cs.few.eur.nl>, Rogier Goossens <goossens@cs.few.eur.nl> writes:
|>
|> I have another, related question:
|>
|> For a 'pointer' type to be complete, it seems to me it needs an 'operator ->*'
|> as well.
|>
|> How would such an operator be declared for a pointer<C> class ?
|>
|> One possibility is:
|>
|> template<class C>
|> class pointer {
|> public:
|> template<class TMC> // TMC : type of member of class C
|> TMC &pointer<C>::operator ->*(TMC *cmp); // cmp: C member pointer
|> }
[..]
|> The semantics would then have to be something like:
|>
|> pointer<myclass> p;
|> ...
|> p->*memberptr; <--> p->(p.operator->*(memberptr));
|> p->*methodptr(...); <--> p->(p.operator->*(methodptr))(...);
[..]
|> To resume:
|> - Is such a declaration for operator->* possible at all, and if so, is
|> the declaration above correct.
AFAIK it is possible. ->* is overloadable (13.5[over.oper],3).
5.5[expr.mprt.oper],3:
... second operand, which shall be of type "ptr to mem of T" to it's
^^^^^^^^^^^^^^^
first operand, which shall be of type ptr to T ...
The result is ... of the type specified by the second argument.
Instead of template parameter 'TMC: type of member of class C',
I'd suggest 'TPMC: type of ptr to member of class C'.
Then you can forget about TMC& and TMC*.
|> - If it is possible, are 'my' semantics of operator->* correct.
Using operator-> and operator->* to describe semantics of userdefined
operator->* confuses me. I prefere an implementation that is based
on the non-overloadable operator.*:
template<class C, class TPMC> // TPMC: type of ptr to member of C
TPMC auto_ptr<C>::operator->*(TPMC pmc) // pmc: a ptr to member of C
{
return (*get()).*pmc;
}
[ Is this the correct syntax for template members of a template class? ]
For orthogonality with (the not so old feature of) memberpointers
(that can be used on objects by .* and on built-in pointers by ->*)
I would appreciate if operator->* would be a standard part of auto_ptr.
Ulf Schuenemann
--------------------------------------------------------------------
,_. Ulf Schünemann
#, \ Fakultät für Informatik, Technische Universität München, Germany.
| > email: schuenem@informatik.tu-muenchen.de
v==-< WWW: http://hphalle2.informatik.tu-muenchen.de/~schuenem/
...there is only one way to "skin a C+@"...:) -- Jim Fleming
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<43c5oc$an2@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: schuenem@informatik.tu-muenchen.de (Ulf Schuenemann) Newsgroups: comp.std.c++ Subject: Re: Implementing auto_ptr + type of operator->* Date: 15 Sep 1995 15:22:52 GMT Organization: ? Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <43c5oc$an2@engnews2.Eng.Sun.COM> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset="us-ascii"; conversions="QUOTED-PRINTABLE, " Content-Transfer-Encoding: QUOTED-PRINTABLE X-Nntp-Posting-Host: hpbroy14.informatik.tu-muenchen.de Originator: schuenem@hpbroy14.informatik.tu-muenchen.de X-Lines: 81 Content-Length: 2509 Originator: clamage@taumet