🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Ulf Schuenemann Fri, 15 Sep 1995 15:22
Re: Implementing auto_ptr + type of operator->*
#1974
Author: Ulf Schuenemann
Date: Fri, 15 Sep 1995 15:22
75 lines
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads