|
|
|
|
|
by p0nce
2715 days ago
|
|
> Similarly operator overloading via a string that tells you what you are overloading seems... insane? Very error-prone & complex? Frankly you should try D for just 5 minutes and see for yourself, because no it is really sane and works well. Never seen anyone complain about this... See here it is used to implement all operators for small vectors in 46 lines:
https://github.com/d-gamedev-team/gfm/blob/master/math/gfm/m... |
|
But you could still do that and not be string-based. It could (and should!) be an enum of the operator instead. opBinary takes a fixed number of ops, but the parameter type of string has an infinite number of values.
Whether or not the design of having a single operator overload method is a good idea or not is independent from what I'm specifically calling insane which is that the parameter type to that method is a string.