ndslice: convert a sliced object to T[]
data pulverizer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jun 15 01:25:35 PDT 2016
On Wednesday, 15 June 2016 at 07:45:12 UTC, Andrea Fontana wrote:
> On Wednesday, 15 June 2016 at 07:24:23 UTC, data pulverizer
> wrote:
>> On Wednesday, 15 June 2016 at 03:17:39 UTC, Seb wrote:
>>> On Wednesday, 15 June 2016 at 03:11:23 UTC, data pulverizer
>>> wrote:
>>>> in that case:
>>>>
>>>> import std.array : array;
>>>> int[] x = slice.byElement.array;
>>>
>>> Are you sure you want to create a _copy_ of your data? In
>>> most cases you don't need that ;-)
>>>
>>>> thanks, now I can go to bed!
>>>
>>> You are welcome. Sleep tight!
>>
>> Thanks, I did.
>>
>> I definitely don't want to create a copy! I thought .byElement
>> would provide a range which I assume is a reference am I
>> forcing it to copy by using .array?
>
> Yes. You're forcing it to read all elements and copy them in a
> new array.
I guess foreach would not copy the elements? for example:
foreach(el; slice.byElement)
x ~= el;
But it feels wrong to be doing work pulling elements that already
exists by using foreach. I feel as if I am missing something
obvious but can't get it.
More information about the Digitalmars-d-learn
mailing list