
On Wed, May 27, 2009 at 11:50 AM, Eric Friedman <ebf@users.sourceforge.net> wrote:
I think operator!= (and operator<=, operator>, operator>=) were left out for simplicity, but no good reason other than that.
The main issue I considered at the time was that I felt variant should forward to the underlying operator. That is, it should call operator!=, rather than assume operator!= is equivalent to the negation of operator==.
Maybe there's no need to be this pedantic though. Do others have an opinion?
Eric
On Mon, May 25, 2009 at 6:56 PM, Brook Milligan <brook@biology.nmsu.edu>wrote:
I just ran into the case that Boost Variant does not satisfy the EqualityComparable concept. While it provides operator==() and operator<() (and therefore is LessThanComparable), it does not provide operator!=(), which is required for the EqualityComparable concept.
Is this by design or oversight? It seems reasonable to expect that a Boost Variant model this concept, but perhaps I am missing something.
In case it is by oversight, the following patch seems to provide the missing operator.
Cheers, Brook
--- boost/variant/variant.hpp.orig 2009-05-13 21:21:59.000000000 -0600 +++ boost/variant/variant.hpp 2009-05-25 19:21:40.000000000 -0600 @@ -1681,6 +1681,8 @@ return rhs.apply_visitor(visitor); }
+ bool operator!=(const variant& rhs) const { return !(*this == rhs); } + bool operator<(const variant& rhs) const { //
I use Boost.Variant quite often, and I never even thought it had operators, I just did everything using custom-made visitors, but if it did expose all those operators and delegate them down to the internal types if they are the same type, I would love that actually, would actually save me quite a bit of code in some places. Although, thinking of it, perhaps I would want something like variantA==variantB to test that the types are equal and that is it, and perhaps something like (*variantA)==(*variantB) to test both types and delegate to the internal objects, that form I would consider perfect.