blob: 43290a6ad673ec2f63f7621d9cc386ded90b0d58 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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] = concept c
c.len is Ordinal
items(c) is T
for value in c:
type(value) 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)
|