Alias template parameters and runtime functions
    Peter Alexander 
    peter.alexander.au at gmail.com
       
    Sun Oct  3 08:43:51 PDT 2010
    
    
  
== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> But that code works with dmd 2.049:
> ...
> Bye,
> bearophile
You're right!
That makes things even more curious then. I had noticed the problem in some more complex code
and just assumed it would be the same in the simple code that I presented.
That said, I have managed to create a slightly more complex example that *does* break.
import std.algorithm: map, equal;
import std.range: iota;
import std.stdio;
struct Bar
{
    float[1] m;
    this(float a) { m = [a]; }
}
class Foo {
    Bar[1] m;
    this(Bar a) { m = [a]; }
    const foo(int i) { return m[i]; }
    const allFoo1() {
        auto fun = (int i) { return foo(i); };
        return map!(fun)(iota(m.length));
    }
    const allFoo2() {
        return map!((int i){ return foo(i); })(iota(m.length));
    }
}
void main()
{
    Foo f = new Foo(Bar(1));
    assert(equal(f.allFoo1(), [Bar(1)]));
    assert(equal(f.allFoo2(), [Bar(1)]));
}
    
    
More information about the Digitalmars-d
mailing list