Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost variant comparator

I need to compare two variables of type boost::variant and I want to compare the values inside the variant for equality.

What would be the best way to implement this?

My variant looks like this:

typedef boost::variant<int, float, double, long, bool, std::string, boost::posix_time::ptime> variant;
like image 429
Tony The Lion Avatar asked Jan 03 '11 14:01

Tony The Lion


1 Answers

From variant docs:

EqualityComparable: variant is itself EqualityComparable if and only if every one of its bounded types meets the requirements of the concept.

So variant already implements equality if all the types are comparable. So in your case you should be able to just use the operator ==.

In general, you can implement a binary visitor by creating a unary visitor that encloses a reference to one of the arguments and applying the visitor to the second argument.

like image 155
Giuseppe Ottaviano Avatar answered Sep 19 '22 02:09

Giuseppe Ottaviano