Cases to consider: Arrays and AAs with const(T) Elements, where T is a value or a reference type respectively.

    class C { }
    struct S { }

    const(S)[]  varr;
    const(C)[]  carr;
    const(S)[S] vaav;
    const(C)[S] caav;
    const(S)[C] vaac;
    const(C)[C] caac;

    pragma(msg, typeof(varr.dup));
    pragma(msg, typeof(carr.dup!(const C))); // (1)
    pragma(msg, typeof(vaav.dup));
    pragma(msg, typeof(caav.dup));
    pragma(msg, typeof(vaac.dup));
    pragma(msg, typeof(caac.dup));

yields

S[]         // ok
const(C)[]  // ok
const(S)[S] // (2)
const(C)[S] // ok
const(S)[C] // ok
const(C)[C] // ok

Questions:
(1) Why do I have to specify the type here? Why does inference fail?
(2) Why not just S[S]?
The copy of a const S is a S so why is the copy of a (const S, const S)-pair not just (S, S)?

Reply via email to