Inability to dup/~ for const arrays of class objects

Diggory diggsey at googlemail.com
Wed May 29 22:44:38 PDT 2013


On Thursday, 30 May 2013 at 05:41:06 UTC, Maxim Fomin wrote:
> On Wednesday, 29 May 2013 at 23:45:04 UTC, Ali Çehreli wrote:
>> On 05/29/2013 03:59 PM, Peter Williams wrote:
>>
>> > I've been trying to find out how non ref array arguments are
>> passed to
>> > functions in D but can't find any documentation on it.
>>
>> The following concepts are relevant:
>>
>> - Dynamic array: Maintained by the D runtime
>
> Generally yes, but not always http://dpaste.dzfl.pl/ffbcb449

That's not a dynamic array, it's a slice of a static array.

>
>> - Fixed-length array (aka static array): Can be on the stack
>>
>> - Slice: An efficient tool to access a range of elements (of 
>> any type of array)
>>
>> Usually, it is the slice that gets passed:
>>
>>  void foo(int[] slice);
>
> Isn't it a dynamic array? I don't understand listing slice as 
> separate type of arrays or mixing meaning of slice and dynamic 
> array. As far as D spec is concerned, slice is a 
> SliceExpression which produces dynamic array for array types.

You can't directly access dynamic arrays in D, you can only 
manipulate views of them using slices. "new int[5]" creates a new 
dynamic array internally but only returns a slice of that array.


More information about the Digitalmars-d mailing list