close #16569: deprecated reversed(a, start, last) overload, use toOpenArray instead (#18047)

* close #16569: deprecated reversed overload, use toOpenArray instead

* [skip ci] change wording in changelog per review

* fixup
This commit is contained in:
Timothee Cour 2021-05-30 13:37:21 -07:00 • committed by GitHub
commit 4a7f2c386c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 29 deletions

View file

@ -75,6 +75,8 @@
- `strformat` is now part of `include std/prelude`. - `strformat` is now part of `include std/prelude`.
- Deprecated `proc reversed*[T](a: openArray[T], first: Natural, last: int): seq[T]` in `std/algorithm`.
- The configuration subsystem now allows for `-d:release` and `-d:danger` to work as expected. - The configuration subsystem now allows for `-d:release` and `-d:danger` to work as expected.
The downside is that these defines now have custom logic that doesn't apply for The downside is that these defines now have custom logic that doesn't apply for
other defines. other defines.

View file

@ -131,40 +131,21 @@ proc reverse*[T](a: var openArray[T]) =
# the max is needed, since a.high is -1 if a is empty # the max is needed, since a.high is -1 if a is empty
reverse(a, 0, max(0, a.high)) reverse(a, 0, max(0, a.high))
proc reversed*[T](a: openArray[T], first: Natural, last: int): seq[T] = proc reversed*[T](a: openArray[T]): seq[T] {.inline.} =
## Returns the reverse of the slice `a[first..last]`. ## Returns the elements of `a` in reverse order.
##
## If an invalid range is passed, it raises `IndexDefect`.
## ##
## **See also:** ## **See also:**
## * `reverse proc<#reverse,openArray[T],Natural,Natural>`_ reverse a slice
## * `reverse proc<#reverse,openArray[T]>`_ ## * `reverse proc<#reverse,openArray[T]>`_
runnableExamples: runnableExamples:
let assert [10, 11, 12].reversed == @[12, 11, 10]
a = [1, 2, 3, 4, 5, 6] assert seq[string].default.reversed == @[]
b = a.reversed(1, 3) let n = a.len
assert b == @[4, 3, 2] result.setLen(n)
assert last >= first - 1 for i in 0..<n: result[i] = a[n - (i + 1)]
var i = last - first
var x = first.int
result = newSeq[T](i + 1)
while i >= 0:
result[i] = a[x]
dec(i)
inc(x)
proc reversed*[T](a: openArray[T]): seq[T] = proc reversed*[T](a: openArray[T], first: Natural, last: int): seq[T]
## Returns the reverse of the container `a`. {.inline, deprecated: "use: `reversed(toOpenArray(a, first, last))`".} =
## reversed(toOpenArray(a, first, last))
## **See also:**
## * `reverse proc<#reverse,openArray[T],Natural,Natural>`_ reverse a slice
## * `reverse proc<#reverse,openArray[T]>`_
runnableExamples:
let
a = [1, 2, 3, 4, 5, 6]
b = reversed(a)
assert b == @[6, 5, 4, 3, 2, 1]
reversed(a, 0, a.high)
proc binarySearch*[T, K](a: openArray[T], key: K, proc binarySearch*[T, K](a: openArray[T], key: K,
cmp: proc (x: T, y: K): int {.closure.}): int = cmp: proc (x: T, y: K): int {.closure.}): int =