Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[superseded] fix #14421 mitems uses lent T D20200525T033019 #260

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ type

include "system/basic_types"

const
NimMajor* {.intdefine.}: int = 1
## is the major number of Nim's version. Example:
##
## .. code-block:: Nim
## when (NimMajor, NimMinor, NimPatch) >= (1, 3, 1): discard
# see also std/private/since

NimMinor* {.intdefine.}: int = 3
## is the minor number of Nim's version.
## Odd for devel, even for releases.

NimPatch* {.intdefine.}: int = 5
## is the patch number of Nim's version.
## Odd for devel, even for releases.

proc compileOption*(option: string): bool {.
magic: "CompileOption", noSideEffect.}
Expand Down Expand Up @@ -2061,22 +2076,6 @@ template unlikely*(val: bool): bool =
else:
unlikelyProc(val)

const
NimMajor* {.intdefine.}: int = 1
## is the major number of Nim's version. Example:
##
## .. code-block:: Nim
## when (NimMajor, NimMinor, NimPatch) >= (1, 3, 1): discard
# see also std/private/since

NimMinor* {.intdefine.}: int = 3
## is the minor number of Nim's version.
## Odd for devel, even for releases.

NimPatch* {.intdefine.}: int = 5
## is the patch number of Nim's version.
## Odd for devel, even for releases.

import system/dollars
export dollars

Expand Down
53 changes: 39 additions & 14 deletions lib/system/iterators.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
iterator items*[T](a: openArray[T]): T {.inline.} =
## Iterates over each item of `a`.
var i = 0
while i < len(a):
yield a[i]
inc(i)
# import std/private/since

# since (1, 3, 5):
# when (NimMajor, NimMinor, NimPatch) >= (1, 3, 5):
when defined(nimDoesntTrackDefects): # PRTEMP
# iterator items*[T](a: openArray[T]): lent T {.inline.} =
iterator items*[T](a: openArray[T]): T {.inline.} =
## Iterates over each item of `a`.
var i = 0
let n = len(a)
while i < n:
yield a[i]
inc(i)
else:
iterator items*[T](a: openArray[T]): T {.inline.} =
## Iterates over each item of `a`.
var i = 0
let n = len(a)
while i < n:
yield a[i]
inc(i)

iterator mitems*[T](a: var openArray[T]): var T {.inline.} =
## Iterates over each item of `a` so that you can modify the yielded value.
Expand Down Expand Up @@ -179,14 +194,24 @@ iterator mpairs*(a: var cstring): tuple[key: int, val: var char] {.inline.} =
yield (i, a[i])
inc(i)

iterator items*[T](a: seq[T]): T {.inline.} =
## Iterates over each item of `a`.
var i = 0
let L = len(a)
while i < L:
yield a[i]
inc(i)
assert(len(a) == L, "the length of the seq changed while iterating over it")
when defined(nimDoesntTrackDefects): # PRTEMP
iterator items*[T](a: seq[T]): lent T {.inline.} =
## Iterates over each item of `a`.
var i = 0
let L = len(a)
while i < L:
yield a[i]
inc(i)
assert(len(a) == L, "the length of the seq changed while iterating over it")
else:
iterator items*[T](a: seq[T]): T {.inline.} =
## Iterates over each item of `a`.
var i = 0
let L = len(a)
while i < L:
yield a[i]
inc(i)
assert(len(a) == L, "the length of the seq changed while iterating over it")

iterator mitems*[T](a: var seq[T]): var T {.inline.} =
## Iterates over each item of `a` so that you can modify the yielded value.
Expand Down