towards support for composite type classes such as seq[Number] and SquareMatrix[T]

This commit is contained in:
Zahary Karadjov 2013-12-27 18:34:28 +02:00
commit a27eb51535
8 changed files with 87 additions and 26 deletions

View file

@ -0,0 +1,30 @@
template accept(e) =
static: assert(compiles(e))
template reject(e) =
static: assert(not compiles(e))
type
TFoo[T, U] = tuple
x: T
y: U
TBar[K] = TFoo[K, K]
TUserClass = int|string
# TBaz = TBar[TUserClass]
var
vfoo: TFoo[int, string]
vbar: TFoo[string, string]
proc foo(x: TFoo) = echo "foo"
proc bar(x: TBar) = echo "bar"
# proc baz(x: TBaz) = echo "baz"
accept(foo(vfoo))
accept(bar(vbar))
# baz vbar
reject(bar(vfoo))