I'm messing around with templates and can't get passed this template/generic instantiation of 'test' from here. What is wrong with this code?
let val = 10
template test(val: typed) =
case val:
of low(int)..<5:
echo "under 5"
else:
echo "5 or above"
test(val)
I'm trying to get to something like this:
template test(stuff: untyped): untyped =
stuff
let val = 10
test:
case val:
of low(int)..<5:
echo "under 5"
else:
echo "5 or above"
I'm not sure what this error means and why this code won't work. Any help is appreciated
Very likely the of-branch cannot evaluate iterator and/or template. The ..< not defined as proc, the workaround is
template test(v: typed) =
case v
of low(int) .. pred(5):
echo "under 5"
else:
echo "5 or above"