How to detect if an array if dynamic or static

asdf via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 25 05:44:05 PST 2016


On Wednesday, 24 February 2016 at 21:48:14 UTC, mahdi wrote:
> Suppose we have a function like this:
>
> void diss(int[] array) ...
>
> How can we detect is `array` is static (fixed size) or dynamic, 
> inside the function body?

I don't understand what I'm doing but got a proof of concept for 
you. This https://dlang.org/phobos/std_traits.html page helped.

import std.stdio;

void main() {
     int[]  a;
     int[1] b;
     writeln(is(typeof(a) == int[])); // true
     writeln(is(typeof(b) == int[])); // false
}



More information about the Digitalmars-d-learn mailing list