[Issue 18699] New: D's builtin arrays could allow a more generic opBinaryAssign with range support
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Mar 31 15:06:35 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18699
Issue ID: 18699
Summary: D's builtin arrays could allow a more generic
opBinaryAssign with range support
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: greensunny12 at gmail.com
(from https://issues.dlang.org/show_bug.cgi?id=13797 where it was proposed to
add a new Phobos function for this)
tl;dr: appending an array to an array works fine today:
---
int[] arr;
arr ~= [0, 1, 2];
---
So I don't see any reason why the compiler couldn't be improved to accept this
too:
---
int[] arr;
arr ~= 3.iota;
---
Custom data types can already do this with operator overloading, but this is
not possible for built-in arrays.
The lowering should be trivial as D already allows ranges for `foreach`:
---
int[] arr;
foreach (e; 3.iota)
arr ~= e;
---
--
More information about the Digitalmars-d-bugs
mailing list