|
|
|
|
|
by Animats
1990 days ago
|
|
Two more levels of blogs down, the actual proposal.[1] Definition: // Print has a type parameter T and has a single (non-type)
// parameter s which is a slice of that type parameter.
func Print[T any](s []T) { ... }
Call: Print[int]([]int{1, 2, 3})
Above, "any" is really just a synonym for "interface{}". You can have more restrictive type constraints on parameterized types by specifying other Go interfaces. This is vaguely similar to how Rust does it, and quite different from the C++ approach."This design does not support template metaprogramming or any other form of compile time programming." [1] https://go.googlesource.com/proposal/+/refs/heads/master/des... |
|