[Issue 8864] Simpler syntax for array literal of structs from one argument

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 27 21:08:47 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=8864

Andrei Alexandrescu <andrei at erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrei at erdani.com
         Resolution|---                         |WONTFIX

--- Comment #5 from Andrei Alexandrescu <andrei at erdani.com> ---
This is a core language change with many risks associated. A DIP would need to
discuss them all.

Workarounds are possible with library code:

void main() {
    BigInt[] data1 = makeArray!BigInt(5, 6, 9);
    Ranged!(int,5,10)[] data2 = makeArray!(Ranged!(int,5,10))(5, 6, 9);
    Nibble[] data3 = makeArray!Nibble[1, 2, 15]; // Nibble.sizeof == 1
    alias Typedef!int Mint;
    Mint[] data4 = makeArray!Mint(5, 6, 9);
}

Within the current language this is possible although not super handy:

    BigInt[] data1 = only(5, 6, 9).map!(x => BigInt(x)).array;

--


More information about the Digitalmars-d-bugs mailing list