[Issue 12315] std.array.array at compile-time too

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 9 05:26:21 PDT 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12315



--- Comment #2 from bearophile_hugs at eml.cc 2014-03-09 05:26:20 PDT ---
(In reply to comment #1)
> Changing this to dmd CTFE bug. I can't think of any way to solve it in Phobos
> without more compiler support.

This seems to work:


import std.traits: ForeachType;
ForeachType!R[] myArray(R)(R r) {
    if (__ctfe) {
        typeof(return) result;
        foreach (item; r)
            result ~= r;
        return result;
    } else {
        // ...
        assert(0);
    }
}
struct Foo1 {
    int i;
}
struct Foo2 {
    immutable int i;
}
void main() {
    enum r1 = [Foo1(1)].myArray; // OK
    enum r2 = [Foo2(1)].myArray; // OK
}

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list