This module defines compile-time reflection procs for working with types
proc name(t: typedesc): string {...}{.magic: "TypeTrait".}
Returns the name of the given type.
Example:
import typetraits proc `$`*(T: typedesc): string = name(T) template test(x): typed = echo "type: ", type(x), ", value: ", x test 42 # --> type: int, value: 42 test "Foo" # --> type: string, value: Foo test(@['A','B']) # --> type: seq[char], value: @[A, B]
proc `$`(t: typedesc): string
proc arity(t: typedesc): int {...}{.magic: "TypeTrait".}
t
has. Examples:
assert arity(seq[string]) == 1 assert arity(array[3, int]) == 2 assert arity((int, int, float, string)) == 4
proc genericHead(t: typedesc): typedesc {...}{.magic: "TypeTrait".}
A compile-time error will be produced if the supplied type is not generic.
proc stripGenericParams(t: typedesc): typedesc {...}{.magic: "TypeTrait".}
proc supportsCopyMem(t: typedesc): bool {...}{.magic: "TypeTrait".}
t
is safe to use for copyMem. Other languages name a type like these blob.
© 2006–2018 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/typetraits.html