CT aggregate computations

Enigma via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 30 11:21:43 PDT 2017


Is it possible to compute at compile time computations on a 
manifest constant that contains values(in a somewhat complex way, 
but that shouldn't matter)?

I am using foreach and it seems to be done dynamically as I can 
step through the code for each value and see them change. This 
tells me it is not done at compile time like it should be.

I might have something like


import std.meta, std.algorithm, std.stdio;
void main()
{
	enum X = [1,2,3,4,5];
	int y = 0;	
	foreach(x; X) // or foreach(x; aliasSeqOf!X), both iterate over 
y at run time according to the debugger.
	   y = max(x, y);
	
	writeln(y);
		
}

But I want it to be effectively the same as


import std.meta, std.algorithm, std.stdio;
void main()
{
	enum X = [1,2,3,4,5];
	int y = 5;	
	writeln(y);	
}

so y is computed at compile time. I'd rather not having to create 
some complex templates to handle it, which I think could be done 
using template recursion. I know of Map and such but will these 
compute completely at compile time or will be essentially be the 
same as the foreach loop?


More information about the Digitalmars-d-learn mailing list