Array literals are weird.

Q. Schroll qs.il.paperinik at gmail.com
Tue May 4 00:34:49 UTC 2021


On Sunday, 2 May 2021 at 08:05:49 UTC, Imperatorn wrote:
> Is there any way to enable this in the language?
>
> ```d
> auto a = [1,2,3] + [4,5,6]; //[5,7,9]
> ```
>
> I want to allow the operation.
>
> If I made a dmd fork, could I change this behavior "easily" or 
> would it require a blood sacrifice

You could enable this easily using a wrapping struct template. 
Have a look at this: https://run.dlang.io/is/6CNgpy

In short, the solution is very elegant, very general, and only 
requires you to make two keystrokes `.v` before the operation. 
Alternatively, you can use `v(1, 2, 3)` instead of a slice 
literal.


More information about the Digitalmars-d mailing list