the best language I have ever met(?)

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 25 08:03:32 PST 2016


On 11/25/16 15:51, Jonathan M Davis via Digitalmars-d-learn wrote:
> On Friday, November 25, 2016 14:27:39 Igor Shirkalin via Digitalmars-d-learn 
> wrote:
>> I think you may write it (I mean actual D) with using some
>> template like this:
>>
>> auto array = static_array!uint(1, 2, 3, 4)
>>
>> Could you please help to write down this template in the best and
>> clear manner?
> 
> That's easy. The problem is if you want it to have the same semantics as
> 
> uint[4] arr = [1, 2, 3, 4];
> 
> In particular, VRP (Value Range Propagation) is a problem. This compiles
> 
> ubyte[4] arr = [1, 2, 3, 4];
> 
> because each of the arguments is known to fit in a ubyte. However, making
> 
> auto arr = staticArray!ubyte(1, 2, 3, 4);
> 
> do the same without forcing a cast is difficult. [...]

   enum T[N] staticArray(T, alias ELS, size_t N=ELS.length) = ELS;
   auto arr = staticArray!(ubyte, [1, 2, 3, 4]);

artur


More information about the Digitalmars-d-learn mailing list