// make a single call deleting them all together than to delete one at a time.
// Delete zeroes the elements s[len(s)-(j-i):len(s)].
func Delete[S ~[]E, E any](s S, i, j int) S {
- _ = s[i:j] // bounds check
+ _ = s[i:j:len(s)] // bounds check
+
+ if i == j {
+ return s
+ }
oldlen := len(s)
s = append(s[:i], s[j:]...)
{"with negative second index", []int{42}, 1, -1},
{"with out-of-bounds first index", []int{42}, 2, 3},
{"with out-of-bounds second index", []int{42}, 0, 2},
+ {"with out-of-bounds both indexes", []int{42}, 2, 2},
{"with invalid i>j", []int{42}, 1, 0},
{"s[i:j] is valid and j > len(s)", s, 0, 4},
+ {"s[i:j] is valid and i == j > len(s)", s, 3, 3},
} {
if !panics(func() { Delete(test.s, test.i, test.j) }) {
t.Errorf("Delete %s: got no panic, want panic", test.name)