...
1
2
3
4
5 package p
6
7 func f1[P int | string]() {}
8 func f2[P ~int | string | float64]() {}
9 func f3[P int](x P) {}
10
11 type myInt int
12 type myFloat float64
13
14 func _() {
15 _ = f1[int]
16 _ = f1[myInt ]
17 _ = f2[myInt]
18 _ = f2[myFloat ]
19 var x myInt
20 f3 (x)
21 }
22
23
24
25 type SliceConstraint[T any] interface {
26 []T
27 }
28
29 func Map[S SliceConstraint[E], E any](s S, f func(E) E) S {
30 return s
31 }
32
33 type MySlice []int
34
35 func f(s MySlice) {
36 Map[MySlice , int](s, nil)
37 }
38
View as plain text