1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: index accessor in array init expression (#12181)

This commit is contained in:
ChAoS_UnItY
2021-10-15 08:57:49 +08:00
committed by GitHub
parent 6d62574e7f
commit 4d1307f29b
6 changed files with 124 additions and 4 deletions

View File

@@ -692,6 +692,14 @@ arrays there is a second initialization syntax:
```v
mut a := []int{len: 10000, cap: 30000, init: 3}
```
You can initialize the array by accessing the it variable as shown here:
```v
mut square := []int{len: 6, init: it * it}
// square == [0, 1, 4, 9, 16, 25]
```
This creates an array of 10000 `int` elements that are all initialized with `3`. Memory
space is reserved for 30000 elements. The parameters `len`, `cap` and `init` are optional;
`len` defaults to `0` and `init` to the default initialization of the element type (`0`