The following code fails to compile, with error, "non-constant expression 1u ~ []"
template GetArray(uint i)
{
static if (i == 0)
const GetArray = 1u ~ GetArray!(i + 1);
else
const uint[] GetArray = [];
}
const uint[] array = GetArray!(0);
Comment #1 by samukha — 2007-07-28T05:31:33Z
There is a workaround, if it's of any use.
template GetArray(uint i)
{
static if (i == 0)
const GetArray = ([1u] ~ GetArray!(i + 1));
else
const uint[] GetArray = [];
}
const uint[] array = GetArray!(0);
----------
One more test case. Fails with error "semicolon expected following auto declaration, not '~'".
template GetArray(uint i)
{
static if (i == 0)
const GetArray = [1u] ~ GetArray!(i + 1); //fails
else
const uint[] GetArray = [];
}
const uint[] array = GetArray!(0);