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 690121 - Provide operator BoolExpr for VariantBase
Provide operator BoolExpr for VariantBase
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2012-12-12 19:43 UTC by Andrew Potter
Modified: 2012-12-18 15:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
VariantBase: Add operators for BoolExpr and relations. (3.48 KB, patch)
2012-12-12 19:43 UTC, Andrew Potter
none Details | Review
VariantBase: Add operator for BoolExpr (const void*). (2.92 KB, patch)
2012-12-17 17:40 UTC, Andrew Potter
none Details | Review

Description Andrew Potter 2012-12-12 19:43:53 UTC
Created attachment 231413 [details] [review]
VariantBase: Add operators for BoolExpr and relations.

Sometimes, an application is handed a Variant that may have an underlying null instance. For example, a stateful GSimpleAction may callback with a null variant.

Attached is a patch to provide an operator const void*(), matching the style of recent gtkmm objects by typedefing const void* to BoolExpr.

Since this casting operator now allows Variants to be used in std::set, I also provided operators <, <=, >, >=, and == to allow for expected usage in a set. I considered using g_variant_compare, but it doesn't seem generic enough since it is only defined for basic types. It follows that operator== should have the same semantics as the other relational operators rather than using g_variant_equal.
Comment 1 Kjell Ahlstedt 2012-12-17 12:44:26 UTC
BoolExpr and operator const void* are ok, but are those relational operators
necessary? They do very unintuitive comparisons. Implicit conversions from
VariantBase to const void* in comparisons are even worse, but they are avoided
if the relational operators are declared private without implementations.
Is it really important to be able to store Variants in a std::set?

You have not declared operator!=(). Is that because you think it's generated
automatically from operator==()? That's true in Ada, but not in C++ as far as
I know.
Comment 2 Andrew Potter 2012-12-17 17:40:36 UTC
Created attachment 231750 [details] [review]
VariantBase: Add operator for BoolExpr (const void*).

I don't care about putting variants in a set :) I didn't think about deleting the operators. Attached is a patch that does so (and deletes != as well)
Comment 3 Kjell Ahlstedt 2012-12-18 15:18:20 UTC
I have pushed the patch to the master branch.