B
Belebele
Suppose that I have a class that has a user-defined conversion to
std::string, and I would like to compare objects of that class to
"strings" (e.g. literals, std::strings):
class InUpperCase {
public:
operator std::string() const;
};
....
InUpperCase()=="a string"; // This does not compile.
// fine, bool operator==(InUpperCase const& , char const* );
// is not declared anywhere.
InUpperCase()==std::string("a string"); // This one does not compile
either,
// even though, there is a definition for an operator== in std
// that takes two std::strings.
I expected the second expression to compile fine due to ADL combined
with the user-defined conversion. Any idea why?
std::string, and I would like to compare objects of that class to
"strings" (e.g. literals, std::strings):
class InUpperCase {
public:
operator std::string() const;
};
....
InUpperCase()=="a string"; // This does not compile.
// fine, bool operator==(InUpperCase const& , char const* );
// is not declared anywhere.
InUpperCase()==std::string("a string"); // This one does not compile
either,
// even though, there is a definition for an operator== in std
// that takes two std::strings.
I expected the second expression to compile fine due to ADL combined
with the user-defined conversion. Any idea why?