diff options
Diffstat (limited to 'lib/system.nim')
-rw-r--r-- | lib/system.nim | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/system.nim b/lib/system.nim index 1b6b3c9a8..ed1a0077e 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -24,6 +24,9 @@ include "system/basic_types" +func zeroDefault*[T](_: typedesc[T]): T {.magic: "ZeroDefault".} = + ## returns the default value of the type `T`. + include "system/compilation" {.push warning[GcMem]: off, warning[Uninit]: off.} @@ -911,6 +914,7 @@ proc default*[T](_: typedesc[T]): T {.magic: "Default", noSideEffect.} = # note: the doc comment also explains why `default` can't be implemented # via: `template default*[T](t: typedesc[T]): T = (var v: T; v)` + proc reset*[T](obj: var T) {.noSideEffect.} = ## Resets an object `obj` to its default value. obj = default(typeof(obj)) @@ -2753,3 +2757,8 @@ when notJSnotNims and not defined(nimSeqsV2): moveMem(addr y[0], addr x[0], x.len) assert y == "abcgh" discard + +proc arrayWith*[T](y: T, size: static int): array[size, T] {.noinit.} = # ? exempt from default value for result + ## Creates a new array filled with `y`. + for i in 0..size-1: + result[i] = y |