Topic: Using pointers to members with smart pointers
Author: A.Stokes@globalcomm.co.uk
Date: 1998/08/26 Raw View
In article <80AA1DF10211D211812100805FE217E806D054@HASASSURNET01>,
BourezC <BourezC@Assurnet.be> wrote:
>
> operator->* is an unsecable operator.
> It does not mean operator-> followed by operator* !!!
[No breach of netiquette intended, but to avoid any ambiguity I'm assuming
that by "unsecable", which isn't actually an English word, you mean "atomic"
or "indivisible".]
In a sense of course you're right - if only because one can't apply operator *
to a member function pointer.
But logically A->*B() is a multi-stage operation: find the object pointed to
by A, then apply the member function pointed to by B to it.
My point is that there seems no logical or practical reason why the first step
shouldn't make use of an operator -> if A is an object not a pointer.
I believe the standard says that this does not happen (but would welcome
confirmation), and I'm curious as to why. It would make the language more
regular and uniform if it did, IMHO, and would make some code slightly neater.
--
- Alan
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Greg Colvin" <spam@me.not>
Date: 1998/08/26 Raw View
A.Stokes@globalcomm.co.uk wrote in article
<6s15qo$8dj$1@nnrp1.dejanews.com>...
> In article <80AA1DF10211D211812100805FE217E806D054@HASASSURNET01>,
> BourezC <BourezC@Assurnet.be> wrote:
[ moderator's note: excessive quoting deleted. -sdc ]
> But logically A->*B() is a multi-stage operation: find the object pointed to
> by A, then apply the member function pointed to by B to it.
> My point is that there seems no logical or practical reason why the first step
> shouldn't make use of an operator -> if A is an object not a pointer.
> I believe the standard says that this does not happen (but would welcome
> confirmation), and I'm curious as to why. It would make the language more
> regular and uniform if it did, IMHO, and would make some code slightly neater.
There was a proposal to change operator->* along the lines you describe.
There was little doubt that it was technically feasible, and would have been
useful, e.g. in auto_ptr, but it was just too late.
Greg Colvin
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: BourezC <BourezC@Assurnet.be>
Date: 1998/08/25 Raw View
operator->* is an unsecable operator.
It does not mean operator-> followed by operator* !!!
Christophe Bourez
Assurnet
Belgium
alanstokes@my-dejanews.com wrote:
Suppose I have a smart pointer template class with operator *() and operator
-> () defined, in the usual sort of way. Then I can use this in all sorts of
contexts where I would normally use a pointer. But there is an exception if I
want to make use of a pointer to member (I think).
This is because ->* requires its left hand side to be a real pointer, rather
than something whose operator ->() will eventually result in a pointer. Is
this correct, and is there any good reason for it?
[ moderator's note: excessive quoting deleted. Please trim the
quoted material to include only what is relevent. -sdc ]
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: alanstokes@my-dejanews.com
Date: 1998/08/19 Raw View
Suppose I have a smart pointer template class with operator *() and operator
-> () defined, in the usual sort of way. Then I can use this in all sorts of
contexts where I would normally use a pointer. But there is an exception if I
want to make use of a pointer to member (I think).
This is because ->* requires its left hand side to be a real pointer, rather
than something whose operator ->() will eventually result in a pointer. Is
this correct, and is there any good reason for it?
I came across it in the context of std::mem_fun, which can only be used with a
real pointer, when I wanted to use if with std::for_each on a container of
smart pointers.
An example of what I mean:
template <typename T> struct SmartPtr
{
T * operator ->();
};
struct X { int m };
void f()
{
SmartPtr<X> Smart = ...;
X * Dumb = ...;
int X::* pMem = ...;
Smart->m; // OK
Dumb->m; // OK
Smart->*pMem; // Not allowed
Dumb->*pMem; // OK
}
--
- Alan
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]