use typeof instead type (#16962)
This commit is contained in:
parent
4fac8af0c9
commit
d447c0fe3f
31 changed files with 253 additions and 253 deletions
|
|
@ -86,7 +86,7 @@ proc exclImpl[A](s: var HashSet[A], key: A): bool {.inline.} =
|
|||
var j = i # The correctness of this depends on (h+1) in nextTry,
|
||||
var r = j # though may be adaptable to other simple sequences.
|
||||
s.data[i].hcode = 0 # mark current EMPTY
|
||||
s.data[i].key = default(type(s.data[i].key))
|
||||
s.data[i].key = default(typeof(s.data[i].key))
|
||||
doWhile((i >= r and r > j) or (r > j and j > i) or (j > i and i >= r)):
|
||||
i = (i + 1) and msk # increment mod table size
|
||||
if isEmpty(s.data[i].hcode): # end of collision cluster; So all done
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ proc clear*[A](s: var HashSet[A]) =
|
|||
s.counter = 0
|
||||
for i in 0 ..< s.data.len:
|
||||
s.data[i].hcode = 0
|
||||
s.data[i].key = default(type(s.data[i].key))
|
||||
s.data[i].key = default(typeof(s.data[i].key))
|
||||
|
||||
proc len*[A](s: HashSet[A]): int =
|
||||
## Returns the number of elements in `s`.
|
||||
|
|
@ -812,7 +812,7 @@ proc clear*[A](s: var OrderedSet[A]) =
|
|||
for i in 0 ..< s.data.len:
|
||||
s.data[i].hcode = 0
|
||||
s.data[i].next = 0
|
||||
s.data[i].key = default(type(s.data[i].key))
|
||||
s.data[i].key = default(typeof(s.data[i].key))
|
||||
|
||||
proc len*[A](s: OrderedSet[A]): int {.inline.} =
|
||||
## Returns the number of elements in `s`.
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ template delImplIdx(t, i, makeEmpty, cellEmpty, cellHash) =
|
|||
var j = i # The correctness of this depends on (h+1) in nextTry
|
||||
var r = j # though may be adaptable to other simple sequences.
|
||||
makeEmpty(i) # mark current EMPTY
|
||||
t.data[i].key = default(type(t.data[i].key))
|
||||
t.data[i].val = default(type(t.data[i].val))
|
||||
t.data[i].key = default(typeof(t.data[i].key))
|
||||
t.data[i].val = default(typeof(t.data[i].val))
|
||||
while true:
|
||||
i = (i + 1) and msk # increment mod table size
|
||||
if cellEmpty(i): # end of collision cluster; So all done
|
||||
|
|
@ -149,8 +149,8 @@ template clearImpl() {.dirty.} =
|
|||
for i in 0 ..< t.dataLen:
|
||||
when compiles(t.data[i].hcode): # CountTable records don't contain a hcode
|
||||
t.data[i].hcode = 0
|
||||
t.data[i].key = default(type(t.data[i].key))
|
||||
t.data[i].val = default(type(t.data[i].val))
|
||||
t.data[i].key = default(typeof(t.data[i].key))
|
||||
t.data[i].val = default(typeof(t.data[i].val))
|
||||
t.counter = 0
|
||||
|
||||
template ctAnd(a, b): bool =
|
||||
|
|
@ -161,7 +161,7 @@ template ctAnd(a, b): bool =
|
|||
|
||||
template initImpl(result: typed, size: int) =
|
||||
let correctSize = slotsNeeded(size)
|
||||
when ctAnd(declared(SharedTable), type(result) is SharedTable):
|
||||
when ctAnd(declared(SharedTable), typeof(result) is SharedTable):
|
||||
init(result, correctSize)
|
||||
else:
|
||||
result.counter = 0
|
||||
|
|
|
|||
|
|
@ -338,7 +338,7 @@ else:
|
|||
{.pop.}
|
||||
|
||||
proc load*[T: Trivial](location: var Atomic[T]; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =
|
||||
cast[T](atomic_load_explicit[nonAtomicType(T), type(location.value)](addr(location.value), order))
|
||||
cast[T](atomic_load_explicit[nonAtomicType(T), typeof(location.value)](addr(location.value), order))
|
||||
proc store*[T: Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent) {.inline.} =
|
||||
atomic_store_explicit(addr(location.value), cast[nonAtomicType(T)](desired), order)
|
||||
proc exchange*[T: Trivial](location: var Atomic[T]; desired: T; order: MemoryOrder = moSequentiallyConsistent): T {.inline.} =
|
||||
|
|
|
|||
|
|
@ -446,14 +446,14 @@ proc toSockAddr*(address: IpAddress, port: Port, sa: var Sockaddr_storage,
|
|||
of IpAddressFamily.IPv4:
|
||||
sl = sizeof(Sockaddr_in).SockLen
|
||||
let s = cast[ptr Sockaddr_in](addr sa)
|
||||
s.sin_family = type(s.sin_family)(toInt(AF_INET))
|
||||
s.sin_family = typeof(s.sin_family)(toInt(AF_INET))
|
||||
s.sin_port = port
|
||||
copyMem(addr s.sin_addr, unsafeAddr address.address_v4[0],
|
||||
sizeof(s.sin_addr))
|
||||
of IpAddressFamily.IPv6:
|
||||
sl = sizeof(Sockaddr_in6).SockLen
|
||||
let s = cast[ptr Sockaddr_in6](addr sa)
|
||||
s.sin6_family = type(s.sin6_family)(toInt(AF_INET6))
|
||||
s.sin6_family = typeof(s.sin6_family)(toInt(AF_INET6))
|
||||
s.sin6_port = port
|
||||
copyMem(addr s.sin6_addr, unsafeAddr address.address_v6[0],
|
||||
sizeof(s.sin6_addr))
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ proc some*[T](val: T): Option[T] {.inline.} =
|
|||
var
|
||||
a = some("abc")
|
||||
b = some(42)
|
||||
assert $type(a) == "Option[system.string]"
|
||||
assert $typeof(a) == "Option[system.string]"
|
||||
assert b.isSome
|
||||
assert a.get == "abc"
|
||||
assert $b == "Some(42)"
|
||||
|
|
@ -122,7 +122,7 @@ proc none*(T: typedesc): Option[T] {.inline.} =
|
|||
runnableExamples:
|
||||
var a = none(int)
|
||||
assert a.isNone
|
||||
assert $type(a) == "Option[system.int]"
|
||||
assert $typeof(a) == "Option[system.int]"
|
||||
|
||||
# the default is the none type
|
||||
discard
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ when defined(windows):
|
|||
|
||||
template check(expr) =
|
||||
let r = expr
|
||||
if r == cast[type(r)](0):
|
||||
if r == cast[typeof(r)](0):
|
||||
raiseOSError(osLastError())
|
||||
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -379,9 +379,9 @@ proc formatInt(n: SomeNumber; radix: int;
|
|||
result = "0"
|
||||
else:
|
||||
result = ""
|
||||
while v > type(v)(0):
|
||||
let d = v mod type(v)(radix)
|
||||
v = v div type(v)(radix)
|
||||
while v > typeof(v)(0):
|
||||
let d = v mod typeof(v)(radix)
|
||||
v = v div typeof(v)(radix)
|
||||
result.add(mkDigit(d.int, spec.typ))
|
||||
for idx in 0..<(result.len div 2):
|
||||
swap result[idx], result[result.len - idx - 1]
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ since (1, 1):
|
|||
doAssert 12.MyInt.distinctBase == 12
|
||||
doAssert 12.distinctBase == 12
|
||||
when T is distinct:
|
||||
distinctBase(type(a))(a)
|
||||
distinctBase(typeof(a))(a)
|
||||
else: # avoids hint ConvFromXtoItselfNotNeeded
|
||||
a
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ since (1, 1):
|
|||
runnableExamples:
|
||||
doAssert tupleLen((1, 2)) == 2
|
||||
|
||||
tupleLen(type(t))
|
||||
tupleLen(typeof(t))
|
||||
|
||||
template get*(T: typedesc[tuple], i: static int): untyped =
|
||||
## Returns the `i`-th element of `T`.
|
||||
|
|
@ -132,7 +132,7 @@ since (1, 1):
|
|||
runnableExamples:
|
||||
doAssert get((int, int, float, string), 2) is float
|
||||
|
||||
type(default(T)[i])
|
||||
typeof(default(T)[i])
|
||||
|
||||
type StaticParam*[value: static type] = object
|
||||
## Used to wrap a static value in `genericParams <#genericParams.t,typedesc>`_.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ template volatileLoad*[T](src: ptr T): T =
|
|||
src[]
|
||||
else:
|
||||
var res: T
|
||||
{.emit: [res, " = (*(", type(src[]), " volatile*)", src, ");"].}
|
||||
{.emit: [res, " = (*(", typeof(src[]), " volatile*)", src, ");"].}
|
||||
res
|
||||
|
||||
template volatileStore*[T](dest: ptr T, val: T) =
|
||||
|
|
@ -33,4 +33,4 @@ template volatileStore*[T](dest: ptr T, val: T) =
|
|||
when defined(js):
|
||||
dest[] = val
|
||||
else:
|
||||
{.emit: ["*((", type(dest[]), " volatile*)(", dest, ")) = ", val, ";"].}
|
||||
{.emit: ["*((", typeof(dest[]), " volatile*)(", dest, ")) = ", val, ";"].}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue