Update doc/docs.md
parent
5fc4360e4d
commit
eceba3029f
|
|
@ -1145,13 +1145,13 @@ println(a) // `[2, 2, 2, 13, 2, 3, 4]`
|
|||
println(b) // `[2, 3, 13]`
|
||||
```
|
||||
|
||||
for immidaite reallocation and become independent you can call `.clone()` after slice brackets:
|
||||
You can call .clone() on the slice, if you do want to have an independent copy:
|
||||
```v
|
||||
mut a := [0, 1, 2, 3, 4, 5]
|
||||
mut b := a[2..4].clone()
|
||||
b[0] = 7 // `b[0]` is not referring to `a[2]`
|
||||
println(a) // `[0, 1, 2, 3, 4, 5]
|
||||
```
|
||||
b[0] = 7 // NB: `b[0]` is NOT referring to `a[2]`, as it would be, without the .clone()
|
||||
println(a) // [0, 1, 2, 3, 4, 5]
|
||||
println(b) // [7, 3]
|
||||
|
||||
### Slices with negative indexes
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue