Array literals are weird.
Imperatorn
johan_forsberg_86 at hotmail.com
Wed May 5 05:10:02 UTC 2021
On Tuesday, 4 May 2021 at 20:16:29 UTC, Ola Fosheim Grøstad wrote:
> 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?
Thanks everyone for all clarifications and examples! I'll
experiment a bit and see what makes most sense.
More information about the Digitalmars-d
mailing list