src: Add inequality operator for StringRef

This commit is contained in:
Tatsuhiro Tsujikawa 2016-01-17 16:42:19 +09:00
parent 919e9eee63
commit d5efab4993
2 changed files with 24 additions and 0 deletions

View File

@ -342,6 +342,22 @@ inline bool operator==(const char *lhs, const StringRef &rhs) {
return rhs == lhs;
}
inline bool operator!=(const StringRef &lhs, const std::string &rhs) {
return !(lhs == rhs);
}
inline bool operator!=(const std::string &lhs, const StringRef &rhs) {
return !(rhs == lhs);
}
inline bool operator!=(const StringRef &lhs, const char *rhs) {
return !(lhs == rhs);
}
inline bool operator!=(const char *lhs, const StringRef &rhs) {
return !(rhs == lhs);
}
inline int run_app(std::function<int(int, char **)> app, int argc,
char **argv) {
try {

View File

@ -87,6 +87,14 @@ void test_template_immutable_string(void) {
CU_ASSERT("bravo" == from_lit);
CU_ASSERT(5 == from_lit.size());
// equality
ImmutableString eq("delta");
CU_ASSERT("delta1" != eq);
CU_ASSERT("delt" != eq);
CU_ASSERT(eq != "delta1");
CU_ASSERT(eq != "delt");
}
void test_template_string_ref(void) {