nim-stew/stew/objects.nim

34 lines
758 B
Nim
Raw Normal View History

template init*(lvalue: var auto) =
mixin init
lvalue = init(type(lvalue))
template init*(lvalue: var auto, a1: auto)=
mixin init
lvalue = init(type(lvalue), a1)
template init*(lvalue: var auto, a1, a2: auto) =
mixin init
lvalue = init(type(lvalue), a1, a2)
template init*(lvalue: var auto, a1, a2, a3: auto) =
mixin init
lvalue = init(type(lvalue), a1, a2, a3)
2019-07-03 02:30:49 +03:00
when not declared(default):
proc default*(T: type): T = discard
proc toArray*[T](N: static int, data: openarray[T]): array[N, T] =
doAssert data.len == N
copyMem(addr result[0], unsafeAddr data[0], N)
2019-08-02 11:51:04 +03:00
template anonConst*(val: untyped): untyped =
const c = val
c
2019-10-02 16:24:59 +03:00
when not compiles(len((1, 2))):
import typetraits
func len*(x: tuple): int =
arity(type(x))