Deepcopy: Difference between revisions

Content deleted Content added
Sonia (talk | contribs)
→‎{{header|Go}}: language change. built in error type.
Line 128:
&{1 one [117 110 105 116] map[1:true]}
</pre>
If you need a generalized deep copy, one can be cobbled with an os.Pipe and the gob package, which does type safe serialization, and an os.Pipe. The deepcopy function shown below works on arbitrary data with a few limitations. It handles data types with recursive or cyclic definitions, but does not handle cycles in the data itself. For example, it handles a linked list, but not a ring data structure. Another limitiation is that struct fields must be exported. (That is, fields must start with an upper case letter. This makes the field visible outside the package.)
<lang go>package main
 
Line 138:
 
// capability requested by task
func deepcopy(dst, src interface{}) os.Errorerror {
r, w, err := os.Pipe()
if err != nil {
Line 155:
type link struct {
Value string
Next *link
}