Bug or am I getting things wrong

Q. Schroll via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 6 23:51:05 PST 2016


In the listing below the commented line should do exactly the 
same thing as the one above.

/// DimArr!(i, T) ==> T[][]...[] i times.
template DimArr(size_t i, T)
{
     static if (i == 0)  alias DimArr = T;
     else                alias DimArr = DimArr!(i - 1, T)[];
}


struct Array(T, size_t rk)
     if (rk > 1)
{
     private size_t[rk] dims;
     /+ ... +/
     auto toNestedArray() const
     {
         import std.range : iota;
         import std.format : format;
         enum dimsIndexed = `%(dims[%d]%|, 
%)`.format(dims.length.iota);
         auto result = mixin(`new DimArr!(rk, T)(` ~ dimsIndexed ~ 
`)`);
      // auto result = new DimArr!(rk, T)(mixin(dimsIndexed)));
         /+ ... +/
         return result;
     }
}

The one above does exactly what I want, but the lower one only 
uses the last dimension for some reason. I found out by using 
these pragmas

     pragma(msg, "'", dimsIndexed, "'");
     pragma(msg, ( new DimArr!(rk, T) ( mixin(dimsIndexed) ) 
).stringof);

Can someone please tell me what I'm getting wrong here, or is 
this a bug?


More information about the Digitalmars-d-learn mailing list