Standard library / slices
slices.Grow()
Ensures capacity for at least n additional elements without changing length. May allocate; negative n panics. Expected stdout: '1 true\n'.
Formal Syntax & Structure
go syntaxgo
func Grow[S ~[]E, E any](s S, n int) SParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | S | Input slice; may share its backing array. |
| n | int | Count or bound for this operation. |
Return Value
S
Ensures capacity for at least n additional elements without changing length. May allocate; negative n panics.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { a := slices.Grow([]int{1}, 5) fmt.Println(len(a), cap(a)-len(a) >= 5)}