GNOME Bugzilla – Bug 452135
Consider adding operator bool() to Gdk::Rectangle
Last modified: 2009-06-26 18:59:47 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 }
Created attachment 90845 [details] [review] patch to add Gdk::Rectangle::operator bool() good idea or no?
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.
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.
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. :-)
yeah, I'm convinced that it's probably not a good idea.
(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.
Sorry, forgot the footnote: [1] http://bugzilla.gnome.org/show_bug.cgi?id=512717#c4