Re: recursive function call at compile time

2012-12-16 Thread Philippe Sigaud
> > > When you instantiate MyStruct!5, it tries to define ret, so it > instantiates MyStruct!4, MyStruct!3, ... and so on. You have to put a > static if or something else to stop that. > Like this: import std.stdio; struct MyStruct(uint K) if (K > 0) // Only to disable direct creation for K==0 {

Re: recursive function call at compile time

2012-12-16 Thread bearophile
Oleg: at compile time i have errors ./recursion.d(7): Error: index 4294967295 overflow for static array ./recursion.d(7): Error: index 4294967294 overflow for static array etc It prints a little too many of those... call 'recursionAlgo()' where it should not be ( K == 1 ) The firs

recursive function call at compile time

2012-12-16 Thread Oleg
Hello. I want use recursion, but in my situation compiler doesn't correct work. import std.stdio; struct MyStruct(uint K) { real[K] data; auto getSmaller() { MyStruct!(K-1) ret; foreach( no, ref d; ret.data ) d = data[no]; return ret; }