Created
March 20, 2018 12:56
-
-
Save mratsim/1162668aee9efb0026c135b4ee974842 to your computer and use it in GitHub Desktop.
static + macro workarounds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typetraits | |
type | |
BitsHolder[bits: static[int]] = object | |
template `div`[bits: static[int]](bh: typedesc[BitsHolder[bits]], n: static[int]): typedesc = | |
BitsHolder[bits div n] | |
type | |
MpUintImpl*[bh] = object | |
when bh is BitsHolder[128]: hi*, lo*: uint64 | |
elif bh is BitsHolder[64]: hi*, lo*: uint32 | |
elif bh is BitsHolder[32]: hi*, lo*: uint16 | |
elif bh is BitsHolder[16]: hi*, lo*: uint8 | |
# else: | |
# hi*, lo*: MpUintImpl[bh div 2] | |
MpUint*[bits: static[int]] = MpUintImpl[BitsHolder[bits]] | |
var a: BitsHolder[16] div 2 | |
echo $a.type.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment