added typetraits.; merged PR #5839 manually
This commit is contained in:
parent
6cb8bf8045
commit
9565da11e5
2 changed files with 14 additions and 0 deletions
|
|
@ -35,3 +35,4 @@
|
||||||
- ``rationals.toRational`` now uses an algorithm based on continued fractions.
|
- ``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
|
This means its results are more precise and it can't run into an infinite loop
|
||||||
anymore.
|
anymore.
|
||||||
|
- Added ``typetraits.$`` as an alias for ``typetraits.name``.
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@ proc name*(t: typedesc): string {.magic: "TypeTrait".}
|
||||||
## test(@['A','B'])
|
## test(@['A','B'])
|
||||||
## # --> type: seq[char], value: @[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".}
|
proc arity*(t: typedesc): int {.magic: "TypeTrait".}
|
||||||
## Returns the arity of the given type
|
## Returns the arity of the given type
|
||||||
|
|
||||||
|
|
@ -52,3 +56,12 @@ proc stripGenericParams*(t: typedesc): typedesc {.magic: "TypeTrait".}
|
||||||
proc supportsCopyMem*(t: typedesc): bool {.magic: "TypeTrait".}
|
proc supportsCopyMem*(t: typedesc): bool {.magic: "TypeTrait".}
|
||||||
## This trait returns true iff the type ``t`` is safe to use for
|
## This trait returns true iff the type ``t`` is safe to use for
|
||||||
## `copyMem`:idx:. Other languages name a type like these `blob`:idx:.
|
## `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"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue