Variadic function not recognizing static array length

Zach the Mystic reachzach at gggggmail.com
Thu Mar 14 13:59:37 PDT 2013


On Wednesday, 13 March 2013 at 22:14:26 UTC, Timon Gehr wrote:
> On 03/12/2013 10:47 PM, Zach the Mystic wrote:
>> void func(string[2] a) {}
>>
>> void func2(T...)(T args) {
>>    static assert(is(typeof(args[0]) == string[2]));
>> }
>>
>> void func3(T...)(T args) {
>>    static assert(args[0].length == 2);
>> }
>>
>> func(["",""]); // Okay
>> func2(["",""]); //  Error: (is(string[] == string[2LU])) is 
>> false
>> func3(["",""]); // Error: _param_0 cannot be read at compile 
>> time
>>
>> Is this the intended design?
>
> Yes.
>
>> Is there a workaround which allows me to
>> ensure that the parameter is exactly 2 length?
>
> http://d.puremagic.com/issues/show_bug.cgi?id=9712
> http://d.puremagic.com/issues/show_bug.cgi?id=9711

Man, Hara Kenji is so fast!!!!!! I didn't even know my problem 
wasn't just part of the design, and already it's close to being a 
fixed bug/enhancement!



More information about the Digitalmars-d-learn mailing list