Does foreach on array literal allocate?

Bill Baxter wbaxter at gmail.com
Thu Dec 4 10:58:39 PST 2008


Does anyone know off the top of their head if code like this allocates
or not with current DMD 1.x compilers?

foreach(x; [1, 2, 3, 4])
{
     // do something non-allocating with x
}

And is the answer different if the values are only known at runtime?  Like here:

void a func(int a1, int a2, int a3)
{
   foreach(x; [a1,a2,a3]) {
         // do something non-allocating with x
   }

}

--bb



More information about the Digitalmars-d mailing list