CTFE - filling an array
    The Anh Tran 
    trtheanh at gmail.com
       
    Tue Dec  9 00:44:21 PST 2008
    
    
  
Hi,
I would like to pre-create a double array, each element is calculated by 
a function.
//-----------------------------------------------------
import std.stdio;
import std.conv;
import std.string;
template f(int N)
{
	bool fn(double[] tb)
	{
		for (int i = 1; i < N; i++)
			tb[i] = 1.0/i;
		return true;
	}
}
void main(string[] args)
{
	const int N = 200;
	static double[N] dd = void;
	static auto tmp = f!(N).fn(dd);
	
	int n = toInt(args[1]);
	
	writefln("test array[%d] = %f", n, dd[n]);
}
//------------------------------------------------------
dmd.2021 says: cannot evaluate "static auto tmp = f!(N).fn(dd);" at 
compile-time.
How can i fix it?
Thanks.
    
    
More information about the Digitalmars-d-learn
mailing list