Skip to content

Commit

Permalink
added typetraits.; merged PR #5839 manually
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Oct 30, 2017
1 parent 6cb8bf8 commit 9565da1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -35,3 +35,4 @@
- ``rationals.toRational`` now uses an algorithm based on continued fractions.
This means its results are more precise and it can't run into an infinite loop
anymore.
- Added ``typetraits.$`` as an alias for ``typetraits.name``.
13 changes: 13 additions & 0 deletions lib/pure/typetraits.nim
Expand Up @@ -31,6 +31,10 @@ proc name*(t: typedesc): string {.magic: "TypeTrait".}
## test(@['A','B'])
## # --> type: seq[char], value: @[A, B]

proc `$`*(t: typedesc): string =
## An alias for `name`.
name(t)

proc arity*(t: typedesc): int {.magic: "TypeTrait".}
## Returns the arity of the given type

Expand All @@ -52,3 +56,12 @@ proc stripGenericParams*(t: typedesc): typedesc {.magic: "TypeTrait".}
proc supportsCopyMem*(t: typedesc): bool {.magic: "TypeTrait".}
## This trait returns true iff the type ``t`` is safe to use for
## `copyMem`:idx:. Other languages name a type like these `blob`:idx:.


when isMainModule:
# echo type(42)
import streams
var ss = newStringStream()
ss.write($type(42)) # needs `$`
ss.setPosition(0)
doAssert ss.readAll() == "int"

0 comments on commit 9565da1

Please sign in to comment.