questionable/questionable/operators.nim
Mark Spanbroek d079162675 Use scope instead of block
To avoid influencing `break` statements.
2022-10-24 13:02:55 +02:00

22 lines
555 B
Nim

import ./private/scope
template liftUnary*(T: type, operator: untyped) =
template `operator`*(a: T): untyped =
scope:
let evaluated = a
evaluated ->? `operator`(evaluated.unsafeGet())
template liftBinary*(T: type, operator: untyped) =
template `operator`*(a: T, b: T): untyped =
scope:
let evalA = a
let evalB = b
(evalA, evalB) ->? `operator`(evalA.unsafeGet, evalB.unsafeGet)
template `operator`*(a: T, b: typed): untyped =
scope:
let evalA = a
evalA ->? `operator`(evalA.unsafeGet(), b)