After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 101878 - Glib::RefPtr<> should have operator*()
Glib::RefPtr<> should have operator*()
Status: RESOLVED NOTABUG
Product: glibmm
Classification: Bindings
Component: object
2.4.x
Other All
: Normal enhancement
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2002-12-23 22:42 UTC by Daniel Elstner
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Daniel Elstner 2002-12-23 22:42:19 UTC
I think we should reconsider the decision to omit operator*() at the next
API/ABI break.  Not being able to use Glib::RefPtr<> with
Gtk::Object-derived classes is an awkward inconsistency.
Comment 1 Murray Cumming 2002-12-24 20:30:10 UTC
1. I thought this was not the only thing stopping us from using
Glib::RefPtr with Gtk::Object derived classes.

2. You still need to give an example of when it would be necessary or
useful. I wouldn't want to add the confusion without gaining anything.
Comment 2 Murray Cumming 2003-01-22 23:29:11 UTC
I still have no answers to these questions.
Comment 3 Murray Cumming 2003-01-28 13:05:38 UTC
I don't see any use for this until we can use RefPtr with
Gtk::Object-derived classes. Apparently the problem with that is that
the Gtk::Object can be destroyed even when there are outstanding
references.
Comment 4 Michael Johnson 2003-01-29 00:00:11 UTC
Providing operator*() for RefPtr<> allows appropriate access to
operators of the referenced object, e.g.:

(*ptr) += some_value;
++(*ptr);
value = (*ptr)[index];

Even though there are currently no operators for any classes derived
from SigC::Object, this would make it much more practical to create
some in the future. I'm sure there are practical uses for operators
for a variety of glibmm classes.

While I can understand the original motivation for not supporting the
operator (presumably it was to avoid having programmers take and keep
"dumb" references to the referenced object; I did the same thing the
first time I wrote a smart pointer class) it really doesn't have that
effect, because anyone with a little savvy can just do something like
"pointer = ptr.operator->()" which is dirty and ugly. You're better
off removing their motivation to do that by providing the
dereferencing operator so that RefPtr<> behaves as much like a
built-in pointer type as possible.
Comment 5 Murray Cumming 2003-01-29 20:09:54 UTC
Yes, I know that it would be useful if RefPtr<> could be used with
non-Glib::Object classes. But until it can, I see no need for it. I
see no reason to add something that should never be used.
Comment 6 Michael Johnson 2003-01-31 14:31:38 UTC
I guess I didn't make my point effectively enough. There are basically
two reasons, having nothing to do with using RefPtr with
non-Glib::Object classes, why the dereferencing operator is useful:

1) It would make it feasible to add operators to Glib::Object-based
classes.
2) It would discourage people from using the much uglier
ptr.operator->() mechanism to get at the referenced object directly.
Comment 7 Murray Cumming 2003-01-31 23:32:25 UTC
> 1) It would make it feasible to add operators to Glib::Object-based
> classes.

I don't understand. What would be added to what?

> 2) It would discourage people from using the much uglier
> ptr.operator->() mechanism to get at the referenced object directly.

You have not yet shown that it is necessary for anyone to use either
operator* or the uglier operator-> mechanism.
Comment 8 Michael Johnson 2003-02-01 22:14:18 UTC
>> 1) It would make it feasible to add operators to Glib::Object-based
>> classes.
>
>I don't understand. What would be added to what?

I'm not suggesting any specific changes. I'm just saying that it would
make it feasible to exploit operators in the Glib::Object hierarchy.
Facilitating a highly useful programming technique seems to me to be a
good reason to have the dereferencing operator, even if it isn't going
to be used immediately.

>> 2) It would discourage people from using the much uglier
>> ptr.operator->() mechanism to get at the referenced object >directly.
>
>You have not yet shown that it is necessary for anyone to use either
>operator* or the uglier operator-> mechanism.

Nope, that's true. But you can't stop people from doing it if they are
determined to do so. If you make it possible to use the operator*
technique rather than the operator-> technique, then I suspect the
tendency to abuse them would be reduced. I expect that people using
the operator-> hack would be more likely to keep long-lived copies of
the dumb pointer, whereas if they can use the operator* to quickly and
succinctly get very short-lived references to the object, then they're
less likely to abuse them.
Comment 9 Murray Cumming 2003-02-16 10:53:07 UTC
>> 1) It would make it feasible to add operators to Glib::Object-based
>> classes.
>
>I don't understand. What would be added to what?

I'm not suggesting any specific changes. I'm just saying that it would
make it feasible to exploit operators in the Glib::Object hierarchy.

Do you mean "make it feasible to add operator overrides to
Glib::Object-derived classes"? I can't think of any time when that
would be useful. Again, until we actually need it, I see no need to 
confuse the RefPtr API.

> But you can't stop people from doing it if they are
> determined to do so.
Yes, and those people know that they are doing something wrong and can
deal with the consequences.
Comment 10 Murray Cumming 2004-10-14 15:31:05 UTC
I'm closing this bug because, still, nobody has suggested a real-world situation
in which anyone needs access to the underlying instance. Daniel might know of
such a case, in which case he should reopen this bug.