mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-11 22:08:54 +00:00
Add a document to toOpenArray proc (#23905)
This commit is contained in:
@@ -2790,6 +2790,18 @@ when not defined(js):
|
||||
|
||||
proc toOpenArray*[T](x: seq[T]; first, last: int): openArray[T] {.
|
||||
magic: "Slice".}
|
||||
## Allows passing the slice of `x` from the element at `first` to the element
|
||||
## at `last` to `openArray[T]` parameters without copying it.
|
||||
##
|
||||
## Example:
|
||||
## ```nim
|
||||
## proc test(x: openArray[int]) =
|
||||
## doAssert x == [1, 2, 3]
|
||||
##
|
||||
## let s = @[0, 1, 2, 3, 4]
|
||||
## s.toOpenArray(1, 3).test
|
||||
## ```
|
||||
|
||||
proc toOpenArray*[T](x: openArray[T]; first, last: int): openArray[T] {.
|
||||
magic: "Slice".}
|
||||
proc toOpenArray*[I, T](x: array[I, T]; first, last: I): openArray[T] {.
|
||||
|
||||
@@ -110,6 +110,9 @@ proc `[]`*[Idx, T; U, V: Ordinal](a: array[Idx, T], x: HSlice[U, V]): seq[T] {.s
|
||||
## var a = [1, 2, 3, 4]
|
||||
## assert a[0..2] == @[1, 2, 3]
|
||||
## ```
|
||||
##
|
||||
## See also:
|
||||
## * `toOpenArray(array[I, T];I,I) <#toOpenArray,array[I,T],I,I>`_
|
||||
let xa = a ^^ x.a
|
||||
let L = (a ^^ x.b) - xa + 1
|
||||
result = newSeq[T](L)
|
||||
@@ -136,6 +139,9 @@ proc `[]`*[T; U, V: Ordinal](s: openArray[T], x: HSlice[U, V]): seq[T] {.systemR
|
||||
## var s = @[1, 2, 3, 4]
|
||||
## assert s[0..2] == @[1, 2, 3]
|
||||
## ```
|
||||
##
|
||||
## See also:
|
||||
## * `toOpenArray(openArray[T];int,int) <#toOpenArray,openArray[T],int,int>`_
|
||||
let a = s ^^ x.a
|
||||
let L = (s ^^ x.b) - a + 1
|
||||
newSeq(result, L)
|
||||
|
||||
Reference in New Issue
Block a user