Why .dup not work with multidimensional arrays?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 8 08:13:13 PDT 2015


On 05/08/2015 08:05 AM, Dennis Ritchie wrote:

 > why static int idx variable declared within a
 > function deepDup takes the values 1, 1, 1, 2, 2, 3, 4, as opposed to a
 > global variable static int idx, which receives the expected value of 1,
 > 2, 3, 4, 5, 6, 7 ?

That's because every template instance is a different type (or 
implementation). Just like the static variables of foo and bar are 
separate below, so are the static variables of t!int and t!float:

void foo()
{
     static int i;
}

void bar()
{
     static int i;
}

void t(T)()
{
     static int i;
}

Ali



More information about the Digitalmars-d-learn mailing list