3 ms·
In the Go language, there is something called iota which is like a iterator that counts up from 0: type EGlassRNState int const ( EGlassRNStat
by pkaye 10y ago
In the Go language, there is something called iota which is like a iterator that counts up from 0:
type EGlassRNState int
const (
EGlassRNState_Initial EGlassRNState = 1 << iota
EGlassRNState_Weakened
EGlassRNState_Shattering
EGlassRNState_Shattered
EGlassRNState_ActiveFrags
)
- 50CNT 10y agoIn python you could probably do def makeflag(): flag = 1 while True: yield flag flag = flag << 1 flag = makeflag() E_GLASS_RN_STATE_INITIAL = next(flag) E_GLASS_RN_STATE_WEAKENED = next(flag) E_GLASS_RN_STATE_SHATTERING = next(flag) E_GLASS_RN_STATE_ACTIVE_FRAGS = next(flag) flag2 = makeflag() UNRELATED_FLAG = next(flag2) UNRELATED_FLAG = next(flag2) Also no chance of fatfingering a number.
- deleted 10y ago[deleted]
- dalke 10y agoAnother option is to assume at most 128 bits then do something like: >>> _bitflags = [1<<i for i in range(128)] >>> (E_GLASS_RN_STATE_INITIAL, ... E_GLASS_RN_STATE_WEAKENED, ... E_GLASS_RN_STATE_SHATTERING, ... E_GLASS_RN_STATE_ACTIVE_FRAGS, ... *rest) = _bitflags >>> E_GLASS_RN_STATE_ACTIVE_FRAGS 8
- lifthrasiir 10y agoFor the sake of correctness, the first const should be 0 and the second should be `1 << (iota - 1)`.