Strings in DWT
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Mon Feb 25 05:05:29 PST 2008
> True, I still don't get why it is believed using + as a concatenation
> operator is so confusing for a string?
It's a completely different operation that has different semantics.
Addition is commutative while concatenation isn't; i.e. a + b == b + a
for any numeric type, but a ~ b is not generally interchangeable with b ~ a.
This comes into play in D's operator overloading as well: if the
compiler can't compile a+b as a.opAdd(b) or b.opAdd_r(a) it then tries
a.opAdd_r(b) and b.opAdd(a) (i.e. it tries to compile as b+a instead).
This transformation wouldn't be correct for concatenations, so that has
a different operator that isn't commutative and will therefore skip the
(see the section "Binary Operator Overloading" on
> coming from a C/C++ and Java
> background I personally find ~ confusing it somehow reminds me of the
> two's compliment operator.
Does template instantiation also remind you of negation?
Does multiplication remind you of pointer dereferencing?
Does bitwise-and remind you of taking an address?
I don't see the problem with unary and binary use of an operator doing
different things as long as the unary meaning doesn't make any sense for
binary use and the binary meaning doesn't make any for unary use.
Though I must admit that the unary use of 'is' had me a bit confused for
a while when I first tried to use it, but I don't think that was because
of the binary use...
More information about the Digitalmars-d-dwt