Adds usage example to typetraits.name().
Credit goes to fowl (http://forum.nimrod-lang.org/t/430).
This commit is contained in:
parent
915d3291ab
commit
00f56b20d7
1 changed files with 21 additions and 2 deletions
|
|
@ -11,7 +11,26 @@
|
||||||
## working with types
|
## working with types
|
||||||
|
|
||||||
proc name*(t: typedesc): string {.magic: "TypeTrait".}
|
proc name*(t: typedesc): string {.magic: "TypeTrait".}
|
||||||
## Returns the name of the given type
|
## Returns the name of the given type.
|
||||||
|
##
|
||||||
|
## Example:
|
||||||
|
##
|
||||||
|
## .. code-block::
|
||||||
|
##
|
||||||
|
## 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]
|
||||||
|
|
||||||
|
|
||||||
proc arity*(t: typedesc): int {.magic: "TypeTrait".}
|
proc arity*(t: typedesc): int {.magic: "TypeTrait".}
|
||||||
## Returns the arity of the given type
|
## Returns the arity of the given type
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue