Alias template parameters and runtime functions

bearophile bearophileHUGS at lycos.com
Sun Oct 3 13:22:09 PDT 2010


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


More information about the Digitalmars-d mailing list