One solution would be to cast the range to int when comparing:
doAssert (x.int,) == (1,)
Run
Anothor kinda hacky solution would be to define a generic proc that tries to
compare any tuples of same length:
import std/[macros, genasts, typetraits]
macro unroll*(forLoop: ForLoopStmt): untyped =
var forLoop = forLoop
forLoop[^2] = forLoop[^2][1]
var genAstCall = newCall(bindSym"genAst")
for forVar in forLoop[0 ..< ^2]:
if forVar.kind == nnkVarTuple:
for forVar in forVar[0 ..< ^1]:
genAstCall.add forVar
else:
genAstCall.add forVar
genAstCall.add newBlockStmt(forLoop[^1])
forLoop[^1] =
genAst(result = ident"result", genAstCall):
result.add genAstCall
result = genAst(result = ident"result", forLoop, impl = genSym(nskMacro,
"impl")):
macro impl: untyped =
result = newStmtList()
forLoop
impl()
func `==`(a, b: tuple): bool =
when tupleLen(a) == tupleLen(b):
for i in unroll(0 ..< tupleLen(a)):
if a[i] != b[i]: return false
true
else:
static: error "can't compare tuples of different length"
Run
but this makes some errors a bit less readable
(you can leave the unroll macro if you install+import my unroll lib
<https://github.com/choltreppe/unroll>)