
Dave Abrahams <dave <at> boostpro.com> writes:
<snip>
- Do the semantics for are_strict_equals at http://www.boost.org/doc/libs/1_51_0/doc/html/variant/tutorial.html differ from those of the built-in equality operator?
The built-in equality operator compares two instances of identically-typed variant. As a binary visitor, however, are_strict_equals can compare non-identically-typed variants. boost::variant<int, std::string> v1("hello"); boost::variant<int, std::string> v2("g'bye"); boost::variant<double, std::string> v3("hello"); assert(!(v1 == v2)); assert(v1 == v3);//compile error assert(boost::apply_visitor(are_strict_equals(), v1, v3)); Interestingly, it looks as if variant goes the extra mile to "prevent comparison with foreign types" (that's a comment from variant.hpp). I wonder why.
<snip>