diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/typetraits.nim | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim index 2c3d872df..cc7fb9f72 100644 --- a/lib/pure/typetraits.nim +++ b/lib/pure/typetraits.nim @@ -19,7 +19,7 @@ proc name*(t: typedesc): string {.magic: "TypeTrait".} ## ## import typetraits ## - ## proc `$`*[T](some:typedesc[T]): string = name(T) + ## proc `$`*(T: typedesc): string = name(T) ## ## template test(x): stmt = ## echo "type: ", type(x), ", value: ", x @@ -31,6 +31,21 @@ proc name*(t: typedesc): string {.magic: "TypeTrait".} ## test(@['A','B']) ## # --> type: seq[char], value: @[A, B] - proc arity*(t: typedesc): int {.magic: "TypeTrait".} ## Returns the arity of the given type + +proc GenericHead*(t: typedesc): typedesc {.magic: "TypeTrait".} + ## Accepts an instantiated generic type and returns its + ## uninstantiated form. + ## + ## For example: + ## seq[int].GenericHead will be just seq + ## seq[int].GenericHead[float] will be seq[float] + ## + ## A compile-time error will be produced if the supplied type + ## is not generic + +proc StripGenericParams*(t: typedesc): typedesc {.magic: "TypeTrait".} + ## This trait is similar to `GenericHead`, but instead of producing + ## error for non-generic types, it will just return them unmodified + |