[phobos] is save supposed to do a shallow or deep copy?
Jonathan M Davis
jmdavisProg at gmx.com
Sat Sep 18 14:36:48 PDT 2010
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
More information about the phobos
mailing list