Language Idea #6892: in array ops, enable mixing slices and random access ranges
Simen Kjærås
simen.kjaras at gmail.com
Tue Feb 6 12:21:46 UTC 2018
On Tuesday, 6 February 2018 at 12:13:22 UTC, Guillaume Piolat
wrote:
> On Tuesday, 6 February 2018 at 09:02:46 UTC, Simen Kjærås wrote:
>> On Tuesday, 6 February 2018 at 02:14:35 UTC, Meta wrote:
>>>> What do you think?
>>>
>>> It's already possible, with only very slightly worse
>>> aesthetics:
>>>
>> [Good stuff]
>>
>> We can do better than that, though:
>>
>> [More good stuff]
>
> The problem in your sample is that you turn a range into a new
> slice with .array (which is "alias this" also), and this
> allocates.
Only if you assign it to an array. While it's not very well
indicated in the above example, this also works, and does not
allocate:
unittest
{
auto a = [1,2,3,4,5,6,7,8];
auto b = a.length.iota;
a.vec += b;
}
--
Simen
More information about the Digitalmars-d
mailing list