arduino / arduino/ArduinoCore-API
String relational operators are members.
- Dominant language
- C++
- Stars
- 306
- Forks
- 150
- PR merge metrics
- No merged PRs in 30d
Description
Member relational operators are no good because they cause the lhs and rhs to be treated differently. This causes problems such as making == appear non-commutative. Such as:
```c++
void setup() {
String("hi") == "world";
"world" == String("hi");
}
```
```
sketch_jan19a:3: error: no match for 'operator==' (operand types are 'const char [6]' and 'String')
"world" == String("hi");
^
exit status 1
```
It would be less user-surprising to bring these operators out of the class.
I propose defining them at namespace scope as symmetric pairs of operators, between a String on one side, and everything String accepts as an implicit conversion on the other side, per:
http://en.cppreference.com/w/cpp/string/basic_string/operator_cmp
Contributor guide
No contributing guide indexed for this repository
Research direction
Use the two C++ expressions in the issue as the first reproduction, then locate the String relational-operator declarations in ArduinoCore-API. Compare both operand orders and check the existing String behavior; done means equivalent comparisons compile and behave symmetrically, with coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100