Don't enable ordinalCount()
or bitCount()
for bitset enums
Summary: Bitfield enums are not sequential, so use of these functions on these enums would be invalid. I looked at whether we could trivially move `bitCount` to template based on `ordinalCount`. `bitCount` must be constexpr, since we use it directly as a bit-field size constant. `log2` and `ceil` to be constexpr, which isn't here until C++ 26. Reviewed By: javache Differential Revision: D51518899 fbshipit-source-id: 256f15bbed517be6f90bf43baa43ce96e9259a71
This commit is contained in:
committed by
Facebook GitHub Bot
parent
c7c81e3c89
commit
0eb861b459
22
enums.py
22
enums.py
@@ -169,19 +169,19 @@ for name, values in sorted(ENUMS.items()):
|
||||
ordinal = value[0] if isinstance(value, tuple) else value
|
||||
f.write(f" {ordinal} = YG{name}{ordinal},\n")
|
||||
f.write("};\n\n")
|
||||
f.write(
|
||||
f"YG_DEFINE_ENUM_FLAG_OPERATORS({name})\n\n" if name in BITSET_ENUMS else ""
|
||||
)
|
||||
|
||||
f.write("template <>\n")
|
||||
f.write(f"constexpr inline int32_t ordinalCount<{name}>() {{\n")
|
||||
f.write(f" return {len(values)};\n")
|
||||
f.write("} \n\n")
|
||||
if name in BITSET_ENUMS:
|
||||
f.write(f"YG_DEFINE_ENUM_FLAG_OPERATORS({name})\n\n")
|
||||
else:
|
||||
f.write("template <>\n")
|
||||
f.write(f"constexpr inline int32_t ordinalCount<{name}>() {{\n")
|
||||
f.write(f" return {len(values)};\n")
|
||||
f.write("} \n\n")
|
||||
|
||||
f.write("template <>\n")
|
||||
f.write(f"constexpr inline int32_t bitCount<{name}>() {{\n")
|
||||
f.write(f" return {math.ceil(math.log(len(values), 2))};\n")
|
||||
f.write("} \n\n")
|
||||
f.write("template <>\n")
|
||||
f.write(f"constexpr inline int32_t bitCount<{name}>() {{\n")
|
||||
f.write(f" return {math.ceil(math.log(len(values), 2))};\n")
|
||||
f.write("} \n\n")
|
||||
|
||||
f.write(f"constexpr inline {name} scopedEnum(YG{name} unscoped) {{\n")
|
||||
f.write(f" return static_cast<{name}>(unscoped);\n")
|
||||
|
Reference in New Issue
Block a user