Added += and -= templates for literals

This commit is contained in:
Coffepots 2018-04-06 20:17:53 +01:00
parent b83d9e1c37
commit ef59a023a3

View File

@ -92,6 +92,8 @@ template defineIntConstructor(typ: typedesc, name: untyped{nkIdent}) =
template `+`*(a: int, b: typ): typ = initInt[typ](a) + b
template `-`*(a: typ, b: int): typ = a - initInt[typ](b)
template `-`*(a: int, b: typ): typ = initInt[typ](a) - b
template `+=`*(a: var typ, b: int) = a += initInt[typ](b)
template `-=`*(a: var typ, b: int) = a -= initInt[typ](b)
defineIntConstructor(Int256, i256)
defineIntConstructor(Int512, i512)
@ -105,6 +107,8 @@ template defineUIntConstructor(typ: typedesc, name: untyped{nkIdent}) =
template `+`*(a: int, b: typ): typ = initUInt[typ](a) + b
template `-`*(a: typ, b: int): typ = a - initUInt[typ](b)
template `-`*(a: int, b: typ): typ = initUInt[typ](a) - b
template `+=`*(a: var typ, b: uint) = a += initUInt[typ](b)
template `-=`*(a: var typ, b: uint) = a -= initUInt[typ](b)
defineUIntConstructor(UInt256, u256)
defineUIntConstructor(UInt512, u512)