String& operator+=(const String&);
String& operator+=(const char *);
+ String& operator+=(const std::string&);
friend String operator+(const String&, const String&);
friend String operator+(const String&, const char *);
friend String operator+(const char *, const String&);
+ friend String operator+(const String&, const std::string&);
+ friend String operator+(const std::string&, const String&);
/*
* Shifting characters out
friend std::istream& operator>>(std::istream &, String &);
/*
- * String comparison tests
+ * String comparison tests, relational operators
*/
- friend int operator==(const String& x, const String& y)
+ // String == String
+
+ friend bool operator==(const String& x, const String& y)
{
return strcmp(x.p->s, y.p->s) == 0;
}
- friend int operator!=(const String& x, const String& y)
+ friend bool operator!=(const String& x, const String& y)
{
return strcmp(x.p->s, y.p->s) != 0;
}
- friend int operator<=(const String& x, const String& y)
+ friend bool operator<=(const String& x, const String& y)
{
return strcmp(x.p->s, y.p->s) <= 0;
}
- friend int operator>=(const String& x, const String& y)
+ friend bool operator>=(const String& x, const String& y)
{
return strcmp(x.p->s, y.p->s) >= 0;
}
- friend int operator<(const String& x, const String& y)
+ friend bool operator<(const String& x, const String& y)
{
return strcmp(x.p->s, y.p->s) < 0;
}
- friend int operator>(const String& x, const String& y)
+ friend bool operator>(const String& x, const String& y)
{
return strcmp(x.p->s, y.p->s) > 0;
}
- friend int operator==(const String& x, const char * y)
+ // String == char *
+
+ friend bool operator==(const String& x, const char * y)
{
return strcmp(x.p->s, y) == 0;
}
- friend int operator!=(const String& x, const char * y)
+ friend bool operator!=(const String& x, const char * y)
{
return strcmp(x.p->s, y) != 0;
}
- friend int operator<=(const String& x, const char * y)
+ friend bool operator<=(const String& x, const char * y)
{
return strcmp(x.p->s, y) <= 0;
}
- friend int operator>=(const String& x, const char * y)
+ friend bool operator>=(const String& x, const char * y)
{
return strcmp(x.p->s, y) >= 0;
}
- friend int operator<(const String& x, const char * y)
+ friend bool operator<(const String& x, const char * y)
{
return strcmp(x.p->s, y) < 0;
}
- friend int operator>(const String& x, const char * y)
+ friend bool operator>(const String& x, const char * y)
{
return strcmp(x.p->s, y) > 0;
}
+ // char * == String
+
+ friend bool operator==(const char *y, const String& x)
+ {
+ return strcmp(y, x.p->s) == 0;
+ }
+
+ friend bool operator!=(const char *y, const String& x)
+ {
+ return strcmp(y, x.p->s) != 0;
+ }
+
+ friend bool operator<=(const char *y, const String& x)
+ {
+ return strcmp(y, x.p->s) <= 0;
+ }
+
+ friend bool operator>=(const char *y, const String& x)
+ {
+ return strcmp(y, x.p->s) >= 0;
+ }
+
+ friend bool operator<(const char *y, const String& x)
+ {
+ return strcmp(y, x.p->s) < 0;
+ }
+
+ friend bool operator>(const char *y, const String& x)
+ {
+ return strcmp(y, x.p->s) > 0;
+ }
+
+ // String == std::string
+
+ friend bool operator==(const String& x, const std::string &y)
+ {
+ return strcmp(x.p->s, y.c_str()) == 0;
+ }
+
+ friend bool operator!=(const String& x, const std::string &y)
+ {
+ return strcmp(x.p->s, y.c_str()) == 0;
+ }
+
+ friend bool operator<=(const String& x, const std::string &y)
+ {
+ return strcmp(x.p->s, y.c_str()) <= 0;
+ }
+
+ friend bool operator>=(const String& x, const std::string &y)
+ {
+ return strcmp(x.p->s, y.c_str()) >= 0;
+ }
+
+ friend bool operator<(const String& x, const std::string &y)
+ {
+ return strcmp(x.p->s, y.c_str()) < 0;
+ }
+
+ friend bool operator>(const String& x, const std::string &y)
+ {
+ return strcmp(x.p->s, y.c_str()) > 0;
+ }
+
+ // std::string == String
+
+ friend bool operator==(const std::string &y, const String& x)
+ {
+ return strcmp(y.c_str(), x.p->s) == 0;
+ }
+
+ friend bool operator!=(const std::string &y, const String& x)
+ {
+ return strcmp(y.c_str(), x.p->s) != 0;
+ }
+
+ friend bool operator>=(const std::string &y, const String& x)
+ {
+ return strcmp(y.c_str(), x.p->s) >= 0;
+ }
+
+ friend bool operator<=(const std::string &y, const String& x)
+ {
+ return strcmp(y.c_str(), x.p->s) <= 0;
+ }
+
+ friend bool operator<(const std::string &y, const String& x)
+ {
+ return strcmp(y.c_str(), x.p->s) < 0;
+ }
+
+ friend bool operator>(const std::string &y, const String& x)
+ {
+ return strcmp(y.c_str(), x.p->s) > 0;
+ }
+
/*
* Modifiers
*/