Thread overview | |||||
---|---|---|---|---|---|
|
May 18, 2007 Q: Determining array type | ||||
---|---|---|---|---|
| ||||
Hello. How do you determine if a type is an array? I saw the hack in std.boxer but was wondering if there is a language standard / better way. Regards, Myron. |
May 18, 2007 Re: Q: Determining array type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Myron Alexander | Myron Alexander wrote:
> Hello.
>
> How do you determine if a type is an array? I saw the hack in std.boxer but was wondering if there is a language standard / better way.
>
> Regards,
>
> Myron.
Here's what I would do.
template isArray(T) { const isArray=false; }
template isArray(T: T[]) { const isArray=true; }
Beware though, this was not extensively tested. From what I can see, it _should_ work, and also does in simple test cases, but that's no guarantee.
Use it like "[static] if (isArray!(Type)) { do stuff here } "
|
May 19, 2007 Re: Q: Determining array type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Downs | Downs wrote:
> Myron Alexander wrote:
>> Hello.
>>
>> How do you determine if a type is an array? I saw the hack in std.boxer but was wondering if there is a language standard / better way.
>>
>> Regards,
>>
>> Myron.
>
> Here's what I would do.
> template isArray(T) { const isArray=false; }
> template isArray(T: T[]) { const isArray=true; }
>
> Beware though, this was not extensively tested. From what I can see, it _should_ work, and also does in simple test cases, but that's no guarantee.
>
> Use it like "[static] if (isArray!(Type)) { do stuff here } "
Thanks, rather ingenious.
|
Copyright © 1999-2021 by the D Language Foundation