开发者

boost variant comparator

开发者 https://www.devze.com 2023-02-02 00:04 出处:网络
I need to compare two variables of type boost::variant and I want to compare the values inside the variant for equality.

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> vari开发者_JS百科ant;


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号