Inability to dup/~ for const arrays of class objects

Maxim Fomin maxim at maxim-fomin.ru
Wed May 29 22:54:51 PDT 2013


On Thursday, 30 May 2013 at 05:44:43 UTC, Diggory wrote:
> 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.

And this is a problem, because article about D slices encourages 
to call some raw memory (which almost never is directly 
manipulated and doesn't appear in source code) as a dynamic 
array, and dynamic array as a slice.

>>
>>> - 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.

That's clear, issue here is misleading definitions used by D 
slices article.

typeof(slice) => int[]

 From array page spec: type[] => dynamic array. So, int[] slice is 
a parameter of type 'dynamic array'.

 From expression spec page what slice is:
SliceExpression:
    PostfixExpression [ ]
    PostfixExpression [ AssignExpression .. AssignExpression ]

and clearly 'slice' object is not an expression.


More information about the Digitalmars-d mailing list