mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Since this is a C++ stdlib type we need make sure that any overloads that use it are preferred over custom types that also conform to `ExpressibleByStringLiteral` when argument is a string literal. This is important for operators like `==` which could be heterogenous and have a custom C++ type that conforms to `ExpressibleByStringLiteral` on either side together with `std.string` i.e. `==(std.string, const CustomString &)`, such overloads should only be selected if argument passed to `CustomString` is non-literal because literals are convered by a stdlib `==(std.string, std.string)` overload.
21 lines
478 B
C++
21 lines
478 B
C++
#include <string>
|
|
|
|
struct HasMethodThatReturnsString {
|
|
int value = 111;
|
|
std::string getString() const { return std::to_string(value); }
|
|
};
|
|
|
|
inline std::string takesStringWithDefaultArg(std::string s = "abc") { return s; }
|
|
|
|
struct StringBox {
|
|
std::string value;
|
|
|
|
friend bool operator==(const StringBox &lhs, const std::string &rhs) {
|
|
return lhs.value == rhs;
|
|
}
|
|
|
|
friend bool operator==(const std::string &lhs, const StringBox &rhs) {
|
|
return rhs == lhs;
|
|
}
|
|
};
|