Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding additional String + operators for disambiguation.

The operator bool() means that you could implicitly convert a String to a bool and then add it to it an int, for example.  Which means our operator+ has to match exactly or it will be ambiguous.
  • Loading branch information...
commit 488e672ea0b52b65005451d27c8abcfb2e331245 1 parent cc24d41
@damellis damellis authored
Showing with 35 additions and 0 deletions.
  1. +35 −0 hardware/arduino/cores/arduino/WString.h
View
35 hardware/arduino/cores/arduino/WString.h
@@ -175,5 +175,40 @@ class StringSumHelper : public String
StringSumHelper(unsigned long num) : String(num, 10) {}
};
+inline StringSumHelper operator + (const String &lhs, const String &rhs)
+ { return StringSumHelper(lhs) + rhs; }
+
+inline StringSumHelper operator + (const String &lhs, const char *cstr)
+ { return StringSumHelper(lhs) + cstr; }
+inline StringSumHelper operator + (const String &lhs, char c)
+ { return StringSumHelper(lhs) + c; }
+inline StringSumHelper operator + (const String &lhs, unsigned char c)
+ { return StringSumHelper(lhs) + c; }
+inline StringSumHelper operator + (const String &lhs, int num)
+ { return StringSumHelper(lhs) + num; }
+inline StringSumHelper operator + (const String &lhs, unsigned int num)
+ { return StringSumHelper(lhs) + num; }
+inline StringSumHelper operator + (const String &lhs, long num)
+ { return StringSumHelper(lhs) + num; }
+inline StringSumHelper operator + (const String &lhs, unsigned long num)
+ { return StringSumHelper(lhs) + num; }
+
+inline StringSumHelper operator + (const char *cstr, const String &rhs)
+ { return StringSumHelper(cstr) + rhs; }
+inline StringSumHelper operator + (char c, const String &rhs)
+ { return StringSumHelper(c) + rhs; }
+inline StringSumHelper operator + (unsigned char c, const String &rhs)
+ { return StringSumHelper(c) + rhs; }
+inline StringSumHelper operator + (int num, const String &rhs)
+ { return StringSumHelper(num) + rhs; }
+inline StringSumHelper operator + (unsigned int num, const String &rhs)
+ { return StringSumHelper(num) + rhs; }
+inline StringSumHelper operator + (long num, const String &rhs)
+ { return StringSumHelper(num) + rhs; }
+inline StringSumHelper operator + (unsigned long num, const String &rhs)
+ { return StringSumHelper(num) + rhs; }
+
+
+
#endif // __cplusplus
#endif // String_class_h
Please sign in to comment.
Something went wrong with that request. Please try again.