Inability to dup/~ for const arrays of class objects
Peter Williams
pwil3058 at bigpond.net.au
Wed May 29 18:54:50 PDT 2013
On 30/05/13 10:49, Peter Williams wrote:
> On 30/05/13 09:45, Ali Çehreli wrote:
>> Yes, simply pass-by-reference. Not expensive at all. There may be
>> surprises though; you may want to read this article:
>>
>> http://dlang.org/d-array-article.html
>
> Very informative article.
Thinking about this some more, it seems I still need the const even with
pass by value to reassure the caller that his array won't be altered.
So the problem doesn't go away it just changes slightly.
I find the mechanism described in the article a little disconcerting and
it certainly needs more publicity as it's a bug in waiting for the
unwary. Wouldn't a better rule for pass by value be that any changes to
the data part of the array (including assignment to an element) causes
reallocation of the entire data portion.
Peter
More information about the Digitalmars-d
mailing list