stdlib/system: add sink and move (#13283)
This commit is contained in:
parent
8f73753a2d
commit
046bb0b881
1 changed files with 92 additions and 44 deletions
|
|
@ -406,7 +406,7 @@ when defined(nimArrIdx):
|
||||||
proc `[]`*[I: Ordinal;T](a: T; i: I): T {.
|
proc `[]`*[I: Ordinal;T](a: T; i: I): T {.
|
||||||
noSideEffect, magic: "ArrGet".}
|
noSideEffect, magic: "ArrGet".}
|
||||||
proc `[]=`*[I: Ordinal;T,S](a: T; i: I;
|
proc `[]=`*[I: Ordinal;T,S](a: T; i: I;
|
||||||
x: S) {.noSideEffect, magic: "ArrPut".}
|
x: sink S) {.noSideEffect, magic: "ArrPut".}
|
||||||
proc `=`*[T](dest: var T; src: T) {.noSideEffect, magic: "Asgn".}
|
proc `=`*[T](dest: var T; src: T) {.noSideEffect, magic: "Asgn".}
|
||||||
|
|
||||||
proc arrGet[I: Ordinal;T](a: T; i: I): T {.
|
proc arrGet[I: Ordinal;T](a: T; i: I): T {.
|
||||||
|
|
@ -427,7 +427,7 @@ type
|
||||||
b*: U ## The upper bound (inclusive).
|
b*: U ## The upper bound (inclusive).
|
||||||
Slice*[T] = HSlice[T, T] ## An alias for ``HSlice[T, T]``.
|
Slice*[T] = HSlice[T, T] ## An alias for ``HSlice[T, T]``.
|
||||||
|
|
||||||
proc `..`*[T, U](a: T, b: U): HSlice[T, U] {.noSideEffect, inline, magic: "DotDot".} =
|
proc `..`*[T, U](a: sink T, b: sink U): HSlice[T, U] {.noSideEffect, inline, magic: "DotDot".} =
|
||||||
## Binary `slice`:idx: operator that constructs an interval ``[a, b]``, both `a`
|
## Binary `slice`:idx: operator that constructs an interval ``[a, b]``, both `a`
|
||||||
## and `b` are inclusive.
|
## and `b` are inclusive.
|
||||||
##
|
##
|
||||||
|
|
@ -439,7 +439,7 @@ proc `..`*[T, U](a: T, b: U): HSlice[T, U] {.noSideEffect, inline, magic: "DotDo
|
||||||
## echo a[2 .. 3] # @[30, 40]
|
## echo a[2 .. 3] # @[30, 40]
|
||||||
result = HSlice[T, U](a: a, b: b)
|
result = HSlice[T, U](a: a, b: b)
|
||||||
|
|
||||||
proc `..`*[T](b: T): HSlice[int, T] {.noSideEffect, inline, magic: "DotDot".} =
|
proc `..`*[T](b: sink T): HSlice[int, T] {.noSideEffect, inline, magic: "DotDot".} =
|
||||||
## Unary `slice`:idx: operator that constructs an interval ``[default(int), b]``.
|
## Unary `slice`:idx: operator that constructs an interval ``[default(int), b]``.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
@ -1242,7 +1242,7 @@ proc delete*[T](x: var seq[T], i: Natural) {.noSideEffect.} =
|
||||||
else:
|
else:
|
||||||
defaultImpl()
|
defaultImpl()
|
||||||
|
|
||||||
proc insert*[T](x: var seq[T], item: T, i = 0.Natural) {.noSideEffect.} =
|
proc insert*[T](x: var seq[T], item: sink T, i = 0.Natural) {.noSideEffect.} =
|
||||||
## Inserts `item` into `x` at position `i`.
|
## Inserts `item` into `x` at position `i`.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
@ -1525,7 +1525,55 @@ proc `@`*[T](a: openArray[T]): seq[T] =
|
||||||
newSeq(result, a.len)
|
newSeq(result, a.len)
|
||||||
for i in 0..a.len-1: result[i] = a[i]
|
for i in 0..a.len-1: result[i] = a[i]
|
||||||
|
|
||||||
proc `&`*[T](x, y: seq[T]): seq[T] {.noSideEffect.} =
|
|
||||||
|
when defined(nimSeqsV2):
|
||||||
|
|
||||||
|
proc `&`*[T](x, y: sink seq[T]): seq[T] {.noSideEffect.} =
|
||||||
|
## Concatenates two sequences.
|
||||||
|
##
|
||||||
|
## Requires copying of the sequences.
|
||||||
|
##
|
||||||
|
## See also:
|
||||||
|
## * `add(var seq[T], openArray[T]) <#add,seq[T][T],openArray[T]>`_
|
||||||
|
##
|
||||||
|
## .. code-block:: Nim
|
||||||
|
## assert(@[1, 2, 3, 4] & @[5, 6] == @[1, 2, 3, 4, 5, 6])
|
||||||
|
newSeq(result, x.len + y.len)
|
||||||
|
for i in 0..x.len-1:
|
||||||
|
result[i] = move(x[i])
|
||||||
|
for i in 0..y.len-1:
|
||||||
|
result[i+x.len] = move(y[i])
|
||||||
|
|
||||||
|
proc `&`*[T](x: sink seq[T], y: sink T): seq[T] {.noSideEffect.} =
|
||||||
|
## Appends element y to the end of the sequence.
|
||||||
|
##
|
||||||
|
## Requires copying of the sequence.
|
||||||
|
##
|
||||||
|
## See also:
|
||||||
|
## * `add(var seq[T], T) <#add,seq[T][T],T>`_
|
||||||
|
##
|
||||||
|
## .. code-block:: Nim
|
||||||
|
## assert(@[1, 2, 3] & 4 == @[1, 2, 3, 4])
|
||||||
|
newSeq(result, x.len + 1)
|
||||||
|
for i in 0..x.len-1:
|
||||||
|
result[i] = move(x[i])
|
||||||
|
result[x.len] = move(y)
|
||||||
|
|
||||||
|
proc `&`*[T](x: sink T, y: sink seq[T]): seq[T] {.noSideEffect.} =
|
||||||
|
## Prepends the element x to the beginning of the sequence.
|
||||||
|
##
|
||||||
|
## Requires copying of the sequence.
|
||||||
|
##
|
||||||
|
## .. code-block:: Nim
|
||||||
|
## assert(1 & @[2, 3, 4] == @[1, 2, 3, 4])
|
||||||
|
newSeq(result, y.len + 1)
|
||||||
|
result[0] = move(x)
|
||||||
|
for i in 0..y.len-1:
|
||||||
|
result[i+1] = move(y[i])
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
proc `&`*[T](x, y: seq[T]): seq[T] {.noSideEffect.} =
|
||||||
## Concatenates two sequences.
|
## Concatenates two sequences.
|
||||||
##
|
##
|
||||||
## Requires copying of the sequences.
|
## Requires copying of the sequences.
|
||||||
|
|
@ -1541,7 +1589,7 @@ proc `&`*[T](x, y: seq[T]): seq[T] {.noSideEffect.} =
|
||||||
for i in 0..y.len-1:
|
for i in 0..y.len-1:
|
||||||
result[i+x.len] = y[i]
|
result[i+x.len] = y[i]
|
||||||
|
|
||||||
proc `&`*[T](x: seq[T], y: T): seq[T] {.noSideEffect.} =
|
proc `&`*[T](x: seq[T], y: T): seq[T] {.noSideEffect.} =
|
||||||
## Appends element y to the end of the sequence.
|
## Appends element y to the end of the sequence.
|
||||||
##
|
##
|
||||||
## Requires copying of the sequence.
|
## Requires copying of the sequence.
|
||||||
|
|
@ -1556,7 +1604,7 @@ proc `&`*[T](x: seq[T], y: T): seq[T] {.noSideEffect.} =
|
||||||
result[i] = x[i]
|
result[i] = x[i]
|
||||||
result[x.len] = y
|
result[x.len] = y
|
||||||
|
|
||||||
proc `&`*[T](x: T, y: seq[T]): seq[T] {.noSideEffect.} =
|
proc `&`*[T](x: T, y: seq[T]): seq[T] {.noSideEffect.} =
|
||||||
## Prepends the element x to the beginning of the sequence.
|
## Prepends the element x to the beginning of the sequence.
|
||||||
##
|
##
|
||||||
## Requires copying of the sequence.
|
## Requires copying of the sequence.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue