Str class overloads some operators but not others. I will be the first to
agree that the reasons for why something should or should not be
overloadable are controversial. In any case, I present my reasons
char*instead of defining
copy(). This is to keep syntax consistent between the copy constructor used by C++ (which Str implements) and copying to an object that already exists. Another reason is that C++'s default "bit-copy" implementation for
=is not a good idea with
Strbecause it would create two copies of
size_and_flagsthat point to the same
operatorover because the compiler can get confused about the
syntax when types other than
intare used as the index type.
equals()in place of
operator==for string content equality because of C/C++'s strong roots in using
==for pointer operations. Using
==for something that does not execute in constant time just does not sit well with me. Another reason is that
==is usually grouped as a set with
<=and I did not want to provide all of these operators for the same core reason.
append()in place of
operator+=because I prefer to keep
+=in the numerical domain. Also
+=is often grouped as a set with
-=and I didn't not want to try and guess what these operators should do to a string.
operator<<. To counteract this, I provided a simple
#definethat can remove the code from the compiled output in cases where C++ streams are not used.