static if check for array and AA

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Fri Jun 23 17:15:44 PDT 2006


Sean Kelly wrote:
> Oskar Linde wrote:
>> In article <e7djp7$42g$1 at digitaldaemon.com>, Kirk McDonald says...
>>
>>> It turns out the above template fails because "is(typeof(T.init[0]))" 
>>> fails, as it doesn't describe a valid type. (You can't subscript an 
>>> int!)
>>
>> Yes. I've been reporting this a couple of time, but never gotten any 
>> (official)
>> response on whether this is the intended behavior. Static arrays are 
>> the only type for which typeof(T.init)
>> != T.
> 
> This is also somewhat close to implementation-specific behavior.  I'd 
> prefer to have a more formal means of detecting static arrays.
> 
> 
> Sean

I'm not sure that is implementation-specific behavior. I suspect that 
that is related to the fact that static arrays are the only type that 
cannot be assigned to a value of the same type.
So in order for something like this:
   T a = T.init ;
to work for all types, then T.init had to an element of the array.
I think that all of this (arrays not being proper value types) is pretty 
inconsistent, although most of us are so used to C and C++ that we don't 
even notice or are bothered by it.


-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list