[phobos] is save supposed to do a shallow or deep copy?

David Simcha dsimcha at gmail.com
Sat Sep 18 14:39:45 PDT 2010


  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
>



More information about the phobos mailing list