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
6
enums.py
6
enums.py
@@ -169,10 +169,10 @@ 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 ""
|
||||
)
|
||||
|
||||
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")
|
||||
|
@@ -26,16 +26,6 @@ enum class Errata : uint32_t {
|
||||
|
||||
YG_DEFINE_ENUM_FLAG_OPERATORS(Errata)
|
||||
|
||||
template <>
|
||||
constexpr inline int32_t ordinalCount<Errata>() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
template <>
|
||||
constexpr inline int32_t bitCount<Errata>() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
constexpr inline Errata scopedEnum(YGErrata unscoped) {
|
||||
return static_cast<Errata>(unscoped);
|
||||
}
|
||||
|
@@ -23,16 +23,6 @@ enum class PrintOptions : uint32_t {
|
||||
|
||||
YG_DEFINE_ENUM_FLAG_OPERATORS(PrintOptions)
|
||||
|
||||
template <>
|
||||
constexpr inline int32_t ordinalCount<PrintOptions>() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
template <>
|
||||
constexpr inline int32_t bitCount<PrintOptions>() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
constexpr inline PrintOptions scopedEnum(YGPrintOptions unscoped) {
|
||||
return static_cast<PrintOptions>(unscoped);
|
||||
}
|
||||
|
Reference in New Issue
Block a user