Inability to dup/~ for const arrays of class objects
Diggory
diggsey at googlemail.com
Wed May 29 23:08:05 PDT 2013
On Thursday, 30 May 2013 at 05:54:57 UTC, Maxim Fomin wrote:
> 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.
The article about slices on this site -
http://dlang.org/d-array-article.html is perfectly correct.
>
>>>
>>>> - 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'.
Yep, it's misleading but the D documentation is misleading and
wrong in a lot of places and I'd say here the problems are
relatively minor. Still they should be fixed.
>
> From expression spec page what slice is:
> SliceExpression:
> PostfixExpression [ ]
> PostfixExpression [ AssignExpression .. AssignExpression ]
>
> and clearly 'slice' object is not an expression.
This is talking about the slice operator, not slices. The slice
operator can be applied to any object which defines it.
More information about the Digitalmars-d
mailing list