Using equality operators with boost::optional
问题 I'm trying to define an equality operator for a type T defined in another namespace, and then use the equality operator on optional<T> . On clang (Apple LLVM 9.1.0), this code: namespace nsp { struct Foo { }; } bool operator==(const nsp::Foo& a, const nsp::Foo& b); void foo() { optional<nsp::Foo> a = none; optional<nsp::Foo> b = none; if (a == b) ; } Results in an error: /usr/local/include/boost/optional/detail/optional_relops.hpp:29:34: error: invalid operands to binary expression ('const