Standard library / reflect
reflect.Copy()
Copies up to the smaller length of source and destination; overlapping slices are supported. Expected stdout: '3 [1 1 2 3]\n'.
Formal Syntax & Structure
go syntaxgo
func Copy(dst, src Value) intParameters & Attributes
| Name | Type | Description |
|---|---|---|
| dst | Value | Destination array or slice. |
| src | Value | Source array, slice or compatible string. |
Return Value
int
Copies up to the smaller length of source and destination; overlapping slices are supported.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { a := []int{1, 2, 3, 4} n := reflect.Copy(reflect.ValueOf(a[1:]), reflect.ValueOf(a[:3])) fmt.Println(n, a)}