Array literals are weird.
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Tue May 4 20:16:29 UTC 2021
On Tuesday, 4 May 2021 at 19:44:24 UTC, Imperatorn wrote:
> What would it take to allow array operations like I said
> before, without rewriting:
>
> ```d
> auto a = [1,2,3] + [3,2,1]; //[4,4,4]
> ```
>
> Can this be accomplished using templates or a library solution,
> or do I have to modify the compiler?
C++ allows operator overloading for free-standing operator
functions, D does not.
Adding this to the compiler is easy enough. You just rewrite all
"+" operators to some internal __add(x,y) template and then
default that back to "+", then overload it for anything you
want... Clunky, but it should work?
More information about the Digitalmars-d
mailing list