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 452135 - Consider adding operator bool() to Gdk::Rectangle
Consider adding operator bool() to Gdk::Rectangle
Status: RESOLVED WONTFIX
Product: gtkmm
Classification: Bindings
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2007-06-29 03:44 UTC by Jonathon Jongsma
Modified: 2009-06-26 18:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to add Gdk::Rectangle::operator bool() (1.15 KB, patch)
2007-06-29 03:45 UTC, Jonathon Jongsma
none Details | Review

Description Jonathon Jongsma 2007-06-29 03:44:59 UTC
In C Gtk+, you can do the following:
if (gdk_rectangle_intersect (a, b, c))
{
  // the rectangles intersect
}

in gtkmm you can do this, but it is rather cumbersome:
bool rectangles_intersect;
c = a.intersect(b, rectangles_intersect);
if (rectangles_intersect)
{
  // the rectangles intersect
}

if Gdk::Rectangle had an operator bool() which returned true if the rectangle was non-empty, it would make this less clumsy, e.g.:
if (c = a.intersect(b))
{
  // the rectangles intersect
}
Comment 1 Jonathon Jongsma 2007-06-29 03:45:55 UTC
Created attachment 90845 [details] [review]
patch to add Gdk::Rectangle::operator bool()

good idea or no?
Comment 2 Murray Cumming 2007-11-09 16:44:43 UTC
Sorry, I don't like this much. empty-rectangle-instance == no-intersect doesn't feel natural to me.

And sorry for not seeing this until now.
Comment 3 Jonathon Jongsma 2007-11-09 17:38:54 UTC
It feels natural to me -- empty intersection area == no intersection.  But I agree that the semantics are slightly different than the GTK+ version.  And like I said, it's already possible, it's just slightly less convenient than the GTK+ version.  So I don't mind if it doesn't get added, I just thought it might make the API more of a direct translation from GTK+ to gtkmm.
Comment 4 Daniel Elstner 2009-06-12 17:32:04 UTC
I remember wanting to call it empty() first, but Murray insisted on has_zero_area(). :-)

About the operator: I think we should start to cut back on our heavy use of operator bool() in the current API. It's an implicit conversion to an integer type that can lead to subtly broken code compiling cleanly, and also messes with overload resolution. Please don't add even more of those. :-)
Comment 5 Jonathon Jongsma 2009-06-12 20:08:45 UTC
yeah, I'm convinced that it's probably not a good idea.
Comment 6 José Alburquerque 2009-06-26 18:51:29 UTC
(In reply to comment #4)
> About the operator: I think we should start to cut back on our heavy use of
> operator bool() in the current API. It's an implicit conversion to an integer
> type that can lead to subtly broken code compiling cleanly, and also messes
> with overload resolution. Please don't add even more of those. :-)

A while ago I remember trying to implement a boolean operator for the ValueBase class, avoiding the implicit conversion to an integer (I commented about it in the report in the middle of comment #4[1]).  The relevant links in the patch are:

http://bugzilla.gnome.org/attachment.cgi?id=104530&action=diff#glib/glibmm/value.h_sec1
http://bugzilla.gnome.org/attachment.cgi?id=104530&action=diff#glib/glibmm/value.h_sec2
http://bugzilla.gnome.org/attachment.cgi?id=104530&action=diff#glib/glibmm/value.cc_sec1

Maybe code like this can be used for boolean operators that are necessary but where the implicit conversions and overload resolution problems should be avoided.  This is just a thought for consideration.  If it makes sense it can be used when convenient.
Comment 7 José Alburquerque 2009-06-26 18:59:47 UTC
Sorry, forgot the footnote:

[1] http://bugzilla.gnome.org/show_bug.cgi?id=512717#c4