Thread overview | |||||
---|---|---|---|---|---|
|
September 18, 2010 [phobos] is save supposed to do a shallow or deep copy? | ||||
---|---|---|---|---|
| ||||
Forward ranges are supposed to define a save property which makes a copy of the range so that its place can be saved by an algorithm. This is so that reference types can be used as ranges as well. The question is then, should save make a shallow or deep copy. I pretty much always think deep copy when I think of a copy, but that's not necessarily what we want here. Does it depend on how the range works? The best that I can think of is that if the range needs to copy its reference- based elements in order to save its place, then it needs to at least deep copy those, but that if it really only needs its value elements to maintain its place, then it could do a shallow copy. But I don't know. Arrays are reference types, and they do a shallow copy via slicing. Is there a definitive rule as to whether save should return a shallow or deep copy? Or is it dependent entirely on the range type? - Jonathan M Davis |
September 18, 2010 [phobos] is save supposed to do a shallow or deep copy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | The whole point of save() is to copy just the iteration state, not the
contents. Therefore, it should copy as deeply as necessary for that
purpose.
On 9/18/2010 5:36 PM, Jonathan M Davis wrote:
> Forward ranges are supposed to define a save property which makes a copy of the range so that its place can be saved by an algorithm. This is so that reference types can be used as ranges as well. The question is then, should save make a shallow or deep copy. I pretty much always think deep copy when I think of a copy, but that's not necessarily what we want here. Does it depend on how the range works?
>
> The best that I can think of is that if the range needs to copy its reference- based elements in order to save its place, then it needs to at least deep copy those, but that if it really only needs its value elements to maintain its place, then it could do a shallow copy. But I don't know. Arrays are reference types, and they do a shallow copy via slicing.
>
> Is there a definitive rule as to whether save should return a shallow or deep copy? Or is it dependent entirely on the range type?
>
> - Jonathan M Davis
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
>
|
September 18, 2010 [phobos] is save supposed to do a shallow or deep copy? | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Simcha | On Saturday 18 September 2010 14:39:45 David Simcha wrote:
> The whole point of save() is to copy just the iteration state, not the
> contents. Therefore, it should copy as deeply as necessary for that
> purpose.
That definitely makes sense, but the docs should probably be more specific on the matter.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation