Skip to content
This repository
Browse code

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
David A. Mellis authored March 13, 2011

Showing 1 changed file with 35 additions and 0 deletions. Show diff stats Hide diff stats

  1. 35  hardware/arduino/cores/arduino/WString.h
35  hardware/arduino/cores/arduino/WString.h
@@ -175,5 +175,40 @@ class StringSumHelper : public String
175 175
 	StringSumHelper(unsigned long num) : String(num, 10) {}
176 176
 };
177 177
 
  178
+inline StringSumHelper operator + (const String &lhs, const String &rhs)
  179
+	{ return StringSumHelper(lhs) + rhs; }
  180
+	
  181
+inline StringSumHelper operator + (const String &lhs, const char *cstr)
  182
+	{ return StringSumHelper(lhs) + cstr; }
  183
+inline StringSumHelper operator + (const String &lhs, char c)
  184
+	{ return StringSumHelper(lhs) + c; }
  185
+inline StringSumHelper operator + (const String &lhs, unsigned char c)
  186
+	{ return StringSumHelper(lhs) + c; }
  187
+inline StringSumHelper operator + (const String &lhs, int num)
  188
+	{ return StringSumHelper(lhs) + num; }
  189
+inline StringSumHelper operator + (const String &lhs, unsigned int num)
  190
+	{ return StringSumHelper(lhs) + num; }
  191
+inline StringSumHelper operator + (const String &lhs, long num)
  192
+	{ return StringSumHelper(lhs) + num; }
  193
+inline StringSumHelper operator + (const String &lhs, unsigned long num)
  194
+	{ return StringSumHelper(lhs) + num; }
  195
+	
  196
+inline StringSumHelper operator + (const char *cstr, const String &rhs)
  197
+	{ return StringSumHelper(cstr) + rhs; }
  198
+inline StringSumHelper operator + (char c, const String &rhs)
  199
+	{ return StringSumHelper(c) + rhs; }
  200
+inline StringSumHelper operator + (unsigned char c, const String &rhs)
  201
+	{ return StringSumHelper(c) + rhs; }
  202
+inline StringSumHelper operator + (int num, const String &rhs)
  203
+	{ return StringSumHelper(num) + rhs; }
  204
+inline StringSumHelper operator + (unsigned int num, const String &rhs)
  205
+	{ return StringSumHelper(num) + rhs; }
  206
+inline StringSumHelper operator + (long num, const String &rhs)
  207
+	{ return StringSumHelper(num) + rhs; }
  208
+inline StringSumHelper operator + (unsigned long num, const String &rhs)
  209
+	{ return StringSumHelper(num) + rhs; }
  210
+	
  211
+
  212
+
178 213
 #endif  // __cplusplus
179 214
 #endif  // String_class_h

0 notes on commit 488e672

Please sign in to comment.
Something went wrong with that request. Please try again.