Feature request: Path append operators for strings

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Jul 3 15:08:32 PDT 2013


On Wed, Jul 03, 2013 at 11:48:21PM +0200, w0rp wrote:
> I am strongly against this kind of thing. Operator overloading is a
> very useful tool for providing obvious semantics to types. User
> defined data structures, like a matrix type, can be treated like
> first class citizens, just like built in primitive types, by having
> overloads for relevant operators.

Operator overloading was initially intended to support user-defined
arithmetic types in a transparent way. However, the ability to attach
Turing-complete semantics to an operator (for the purpose of
implementing arithmetic) led to the temptation to assign *arbitrary*
semantics to it. Which leads to (IMO) poor choices like operator<< and
operator>> in C++'s iostream.


> Using an operator to implement something non-obvious is a crime to
> me. Plus, it's usually wrong, because like C++ streams, you'd have
> to have each binary relation take a reference to something (like an
> ostream) and return the reference again so you can chain the
> operators. Why chain several binary function calls together when you
> can have a single n-ary function call like std.path.buildPath?

+1. Especially given how nicely D has solved the problem of type-safe
variadics.


> Also to shamelessly self-plug, I made a garbage collected matrix
> type with a few overloads for fun recently. Maybe somebody will find
> a use for it. https://github.com/w0rp/dmatrix/blob/master/matrix.d

I think this is a clear sign that we need *some* kind of linear algebra
/ multidimensional array support in Phobos. Denis Shelomovskij and
myself have independently implemented generic n-dimensional array
libraries, of which 2D arrays are a special case. Your matrix
implementation is the 3rd instance that I know of. There are probably
more.

Though, matrix types and 2D arrays probably will want to overload
opBinary!"*" differently (matrix multiplication vs. per-element
multiplication, for example). In theory, though, a matrix type can just
wrap around a 2D array and just override / provide its own opBinary!"*".


T

-- 
Talk is cheap. Whining is actually free. -- Lars Wirzenius


More information about the Digitalmars-d mailing list