This commit is contained in:
Zahary Karadjov 2014-03-06 23:20:36 +02:00
commit ee1b0d8c67
4 changed files with 52 additions and 6 deletions

View file

@ -0,0 +1,43 @@
discard """
output: '''1
2
3
4
5
6
a
b
t
e
s
t
'''
"""
template accept(e: expr) =
static: assert compiles(e)
template reject(e: expr) =
static: assert(not compiles(e))
type
Container[T] = generic C
C.len is Ordinal
items(c) is iterator
for value in C:
value.type is T
proc takesIntContainer(c: Container[int]) =
for e in c: echo e
takesIntContainer(@[1, 2, 3])
reject takesIntContainer(@["x", "y"])
proc takesContainer(c: Container) =
for e in c: echo e
takesContainer(@[4, 5, 6])
takesContainer(@["a", "b"])
takesContainer "test"
reject takesContainer(10)

View file

@ -1,11 +1,8 @@
discard """
output: '''true
true
false
yes'''
output: '''true true false yes'''
"""
proc IsVoid[T](): string =
proc IsVoid[T](): string =
when T is void:
result = "yes"
else: