GNOME Bugzilla – Bug 690121
Provide operator BoolExpr for VariantBase
Last modified: 2012-12-18 15:18:20 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.
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.
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)
I have pushed the patch to the master branch.