Bartosz Milewski Wrote: > > int[] a = [0]; > > auto b = a; > > a ~= 1; > > b ~= 2; > > What is a[1]? > > > > Is this considered "stomping" and requiring a re-allocation? > > Can this question be answered without the recourse to implementation, and the > MRU cache in particular? > > I thought about an abstract definition of "stomping".Something like that: The > expanded part of the array is never implicitly shared with any other array. > But I'm not sure about this case: >
It is natural that a language like D has dynamic arrays (as core features or as library implentations). I think that's why we keep using the word "array" to describe slices. (No, I don't have proof for this theory.) In *current* D, the user code does not handle dynamic arrays. Both 'a' and 'b' below are slices. > int[] a = [1, 2, 3]; > int[] b = a[0..1]; > b ~= 4; > what is a[1]? > > By my definition, this would be considered stomping, but I couldn't find this > example in TDPL. Neither 'a' nor 'b' own the elements; in that sense, if one is a slice then the other is a slice... In D, slices have "discretionary sharing semantics." Any slice may leave the sharing contract as it sees unfit. Ali