import std.random : uniform; auto runtimevalue = uniform(0, 5); static assert(!__traits(compiles, { ctPrimes!runtimevalue; // Error: variable runtimevalue cannot be read at compile time })); static assert(__traits(compiles, { auto a = ctPrimes!(5, byte); auto b = ctPrimes!(5, ubyte); auto c = ctPrimes!(5, short); auto d = ctPrimes!(5, int); auto e = ctPrimes!(5, long); })); static assert(!__traits(compiles, { auto a = ctPrimes!(5, bool); auto b = ctPrimes!(5, char); auto c = ctPrimes!(5, double); })); auto primes1 = ctPrimes!(10); static assert(is(typeof(primes1) == size_t[10])); assert(primes1 == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]); auto primes2 = ctPrimes!(1); assert(primes2 == [2]); auto primes3 = ctPrimes!(10_000); assert(primes3[$ - 1] == 104_729);
Construct an array of prime number using CTFE. The length of the array is length, and the type is T[length].