static if check for array and AA

Oskar Linde Oskar_member at pathlink.com
Thu Jun 22 12:12:48 PDT 2006


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. So the simplest test 
for a static array is:

template isStaticArray(T) { const bool isStaticArray = !is(typeof(T.init) == T);
}

But having this special case for static arrays complicates template code in many
cases.

/Oskar





More information about the Digitalmars-d mailing list