www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Alias template parameters and runtime functions

reply bearophile <bearophileHUGS lycos.com> writes:
Peter Alexander:

 That said, I have managed to create a slightly more complex example that
*does* break.

I have simplified your test case a little: import std.algorithm: map; struct Bar { float[1] m; this(float a) { m[0] = a; } } class Foo { Bar[1] m; this(Bar a) { m[0] = a; } Bar foo(int i) { return m[i]; } void allFoo1() { auto fun = (int i) { return foo(i); }; auto r = map!(fun)([0]); } } void main() { Foo f = new Foo(Bar(1.5)); assert(f.m[0].m[0] == 1.5); f.allFoo1(); } If you replace the float with int, or if you use a dynamic array inside Bar (using an append inside Bar constructor) the error goes away. This is a situation where a stack trace is very useful. Bye, bearophile
Oct 03 2010
parent Peter Alexander <peter.alexander.au gmail.com> writes:
Ok, so with the test case sorted, how am I supposed to return the map over
member function calls?
Oct 03 2010