在 golang 中不可能将任何大小的数组作为函数的参数,您必须使用切片,许多堆栈溢出答案都强调了这一点。
随着最近泛型的引入,是否可以将任意大小的数组作为参数?我尽力了,但似乎不起作用:(
func foo[A [N]V, V comparable, N int](array A) {
fmt.Println(array)
}
Run Code Online (Sandbox Code Playgroud)
./prog.go:9:13: invalid array length N
./prog.go:15:5: cannot infer V (prog.go:9:18)
Run Code Online (Sandbox Code Playgroud)