What would be the idiomatic way to do something like a compile time assert.
Say that you had proc foo(bar:int) where you want to restrict bar to values 1,3,5 and 8. I don't think you can use a range here because they are not contiguous. But you could use a when to check at compile time, but what is the best way to cause a compile error when it doesn't match?
Also is there a nice way you could also cause an error at runtime with debug builds?
Here you go
const allowedInts = {1, 3, 5, 8}
proc foo(bar:static[int]) =
static: assert bar in allowedInts, "Value " & $bar & " not allowed"
echo "Success"
foo(6)
const allowedInts = {1, 3, 5, 8}
proc foo(bar:static[int]) =
static: assert bar in allowedInts, "Value " & $bar & " not allowed"
echo "Success"
foo(5)