mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 13:30:33 +00:00
typetraits module and tests
This commit is contained in:
15
lib/pure/typetraits.nim
Normal file
15
lib/pure/typetraits.nim
Normal file
@@ -0,0 +1,15 @@
|
||||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2012 Nimrod Contributors
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
#
|
||||
|
||||
## This module defines compile-time reflection procs for
|
||||
## working with types
|
||||
|
||||
proc name*(t: typedesc): string {.magic: "TypeTrait".}
|
||||
## Returns the name of the given type
|
||||
|
||||
24
tests/run/ttypetraits.nim
Normal file
24
tests/run/ttypetraits.nim
Normal file
@@ -0,0 +1,24 @@
|
||||
discard """
|
||||
msg: "int\nstring\nTBar[int]"
|
||||
output: "int\nstring\nTBar[int]"
|
||||
"""
|
||||
|
||||
import typetraits
|
||||
|
||||
proc foo(x) =
|
||||
static:
|
||||
var t = type(x)
|
||||
echo t.name
|
||||
|
||||
echo x.type.name
|
||||
|
||||
type
|
||||
TBar[U] = object
|
||||
x: U
|
||||
|
||||
var bar: TBar[int]
|
||||
|
||||
foo 10
|
||||
foo "test"
|
||||
foo bar
|
||||
|
||||
Reference in New Issue
Block a user