Array copy warning

Mike Wey mike-wey at example.com
Sun Oct 13 08:22:49 PDT 2013


On 10/13/2013 03:15 PM, Benjamin Thaut wrote:
> Am 13.10.2013 15:10, schrieb Benjamin Thaut:
>> I'm just in the progress of upgrading to dmd 2.063 and I now get the
>> following warnings in my code:
>>
>>   Warning: explicit element-wise assignment
>> mem[cast(uint)0..this.length()] = (this.opSlice())[] is better than
>> mem[cast(uint)0..this.length()] = this.opSlice()
>>
>> I don't quite understand this warning. It doesn't make much sense to
>> overload the slice operator if I can't use it the same way as the
>> regular slice operator on a "normal" array. Whats the idea behind this
>> warning?
>
> Additionally this warning appears in generic code. Which means I don't
> even now if a regular array is passed in as a argument or just a type
> which overloads the slice operator.
>

With 2.063 and up when assigning to a slice you'll also need to use the 
slice operator on the right of the assignment.
This is also true for regular arrays.

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list