Array literals are weird.

Imperatorn johan_forsberg_86 at hotmail.com
Tue May 4 05:24:11 UTC 2021


On Tuesday, 4 May 2021 at 00:34:49 UTC, Q. Schroll wrote:
> 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.

Interesting! Even more cool if not the .v was required tho 😁


More information about the Digitalmars-d mailing list