add typetraits.pointerBase to return T in ref T|ptr T (#18293)
* add typetraits.deref to return T in ref T|ptr T * deref => refBase * refBase=>pointerBase * [skip ci] address comment
This commit is contained in:
parent
ad5063aed1
commit
128d21be1c
2 changed files with 16 additions and 9 deletions
|
|
@ -100,6 +100,16 @@ proc isNamedTuple*(T: typedesc): bool {.magic: "TypeTrait".} =
|
|||
doAssert not isNamedTuple((string, int))
|
||||
doAssert isNamedTuple(tuple[name: string, age: int])
|
||||
|
||||
template pointerBase*[T](_: typedesc[ptr T | ref T]): typedesc =
|
||||
## Returns `T` for `ref T | ptr T`.
|
||||
runnableExamples:
|
||||
assert (ref int).pointerBase is int
|
||||
type A = ptr seq[float]
|
||||
assert A.pointerBase is seq[float]
|
||||
assert (ref A).pointerBase is A # not seq[float]
|
||||
assert (var s = "abc"; s[0].addr).typeof.pointerBase is char
|
||||
T
|
||||
|
||||
proc distinctBase*(T: typedesc): typedesc {.magic: "TypeTrait".} =
|
||||
## Returns the base type for distinct types, or the type itself otherwise.
|
||||
##
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue