reflect: add MakeSlice()

This commit is contained in:
Damian Gryski
2023-02-25 17:35:19 -08:00
committed by Ayke
parent 836689fdd2
commit 5cc5f11b58
2 changed files with 40 additions and 1 deletions
+7
View File
@@ -132,6 +132,13 @@ func TestSlice(t *testing.T) {
t.Errorf("s[%d]=%d, want %d", i, s[i], i*10)
}
}
refs = MakeSlice(TypeOf(s), 5, 10)
s = refs.Interface().([]int)
if len(s) != refs.Len() || cap(s) != refs.Cap() {
t.Errorf("len(s)=%v refs.Len()=%v cap(s)=%v refs.Cap()=%v", len(s), refs.Len(), cap(s), refs.Cap())
}
}
func equal[T comparable](a, b []T) bool {