Fixed size array initialization

rumbu rumbu at rumbu.ro
Sat Feb 10 15:54:03 UTC 2018


On Saturday, 10 February 2018 at 14:55:49 UTC, b2.temp wrote:
> On Saturday, 10 February 2018 at 14:35:52 UTC, rumbu wrote:
>>
>> In this case, it there any way to be sure that I declared all 
>> the elements I intended? Obviously, without counting them by 
>> hand.
>
> At the level of the library use a template.

Sorry, but I don't get it. Can you elaborate, please?

This is the array in question: 
https://github.com/rumbu13/decimal/blob/master/src/decimal/integrals.d#L2072

First time, I tried to use mixins to generate the array, in order 
to avoid writing the same thing again and again. The mixin 
solution was nice until the compiler served me a nice Out of 
Memory error, that's why I finally used a hand-written array.

>
> At the level of the compiler: no. Not only not all elements are 
> required but they also don't need to be declared in order 
> (static array initialization, like in the example beyond).
>
> It would be possible to put a compiler warning but warnings are 
> not in the D philosophy (one consequence is that many people, 
> like me use -de all the time, making a possible warning not 
> compatible with the legit uses of the "partial array 
> initialization").
>
> By the way i said i did change the compiler. Actually i even 
> captured the session to promote my IDE: 
> http://sendvid.com/c00x7nps.




More information about the Digitalmars-d-learn mailing list