Module typetraits

Search:
Group by:

This module defines compile-time reflection procs for working with types

Procs

proc name[](t: typedesc): string {.
magic: "TypeTrait"
.}

Returns the name of the given type.

Example:

import typetraits

proc `$`*[T](some:typedesc[T]): string = name(T)

template test(x): stmt =
  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]
  Source Edit
proc arity[](t: typedesc): int {.
magic: "TypeTrait"
.}
Returns the arity of the given type   Source Edit