Hi, you want to use append, not copy: https://play.golang.org/p/1TXCsC4-GJ
On Sunday, October 2, 2016 at 5:18:42 PM UTC+3, 高橋誠二 wrote: > > As official doc explains, copy to zero length slice results to be empty. > > package main > > import "fmt" > > func main() { > src := []int{1, 2, 3} > dst := []int{} > fmt.Println(len(dst)) > copy(dst, src) > fmt.Println(src) > fmt.Println(dst) > // [1 2 3] > // [] > > src2 := []int{1, 2, 3} > dst2 := make([]int, len(src)) > copy(dst2, src2) > fmt.Println(src2) > fmt.Println(dst2) > // [1 2 3] > // [1 2 3] > } > > > > But it seems unusual, is it should be like following? > > package main > > import "fmt" > > func main() { > src := []int{1, 2, 3} > dst := []int{} > fmt.Println(len(dst)) > copy(dst, src) > fmt.Println(src) > fmt.Println(dst) > // [1 2 3] > // [1 2 3] > } > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.