template <typename E, E MinLegal, E HighBound> class ContiguousEnumValidator {};
template <typename E, E MinLegal, E MaxLegal> class ContiguousEnumValidatorInclusive {};
template <typename E, E MinLegal, E HighBound> struct ContiguousEnumSerializer
: EnumSerializer<E, ContiguousEnumValidator<E, MinLegal, HighBound>> {};
template <typename E, E MinLegal, E MaxLegal> struct ContiguousEnumSerializerInclusive
: EnumSerializer<E,
ContiguousEnumValidatorInclusive<E, MinLegal, MaxLegal>> {};
template <typename E, E AllBits> struct BitFlagsEnumSerializer {};
template <class P> struct ParamTraits;
// --- Test: Inclusive with sentinel value ---
enumclass WithCount { A, B, C, OP_COUNT };
template <> struct ParamTraits<WithCount> // expected-warning {{ContiguousEnumSerializerInclusive includes sentinel value 'OP_COUNT' as valid; use ContiguousEnumSerializer with an exclusive upper bound instead}}
: ContiguousEnumSerializerInclusive<
WithCount, WithCount::A, WithCount::OP_COUNT> {};
enumclass WithMax { None, Partial, Full, MAX };
template <> struct ParamTraits<WithMax> // expected-warning {{ContiguousEnumSerializerInclusive includes sentinel value 'MAX' as valid; use ContiguousEnumSerializer with an exclusive upper bound instead}}
: ContiguousEnumSerializerInclusive<
WithMax, WithMax::None, WithMax::MAX> {};
template <> struct ParamTraits<WithInvalid> // expected-warning {{ContiguousEnumSerializerInclusive includes sentinel value 'Invalid' as valid; use ContiguousEnumSerializer with an exclusive upper bound instead}}
: ContiguousEnumSerializerInclusive<
WithInvalid, WithInvalid::Default, WithInvalid::Invalid> {};
// --- Test: Min value doesn't match first enumerator ---
enumclass SkippedFirst { First = 0, Second = 1, Third = 2, NUM };
template <> struct ParamTraits<SkippedFirst> // expected-warning {{ContiguousEnumSerializer min value 'Second' does not match the first enumerator 'First' (value 0); the range excludes valid enum values}}
: ContiguousEnumSerializer<
SkippedFirst, SkippedFirst::Second, SkippedFirst::NUM> {};
template <> struct ParamTraits<ComboIssue> // expected-warning {{ContiguousEnumSerializerInclusive includes sentinel value 'OP_COUNT' as valid; use ContiguousEnumSerializer with an exclusive upper bound instead}} expected-warning {{ContiguousEnumSerializerInclusive min value 'Over' does not match the first enumerator 'Clear' (value 0); the range excludes valid enum values}}
: ContiguousEnumSerializerInclusive<
ComboIssue, ComboIssue::Over, ComboIssue::OP_COUNT> {};
template <> struct ParamTraits<StorageAccess> // expected-error {{ContiguousEnumSerializerInclusive used with non-contiguous enum; range accepts 6 values but only 5 enumerators exist (1 invalid values accepted)}}
: ContiguousEnumSerializerInclusive<
StorageAccess, StorageAccess::Deny, StorageAccess::Grant> {};
// --- Test: Upper bound doesn't match last enumerator (inclusive) ---
enumclass MissedHigh { A = 0, B = 1, C = 2, D = 3 };
template <> struct ParamTraits<MissedHigh> // expected-warning {{ContiguousEnumSerializerInclusive upper bound does not match the last enumerator 'D' (value 3); the range may exclude valid enum values}}
: ContiguousEnumSerializerInclusive<
MissedHigh, MissedHigh::A, MissedHigh::B> {};
// --- Test: Upper bound doesn't match last enumerator (exclusive) ---
enumclass MissedHighExcl { A = 0, B = 1, C = 2, D = 3, Count };
template <> struct ParamTraits<MissedHighExcl> // expected-warning {{ContiguousEnumSerializer upper bound does not match the last enumerator 'Count' (value 4); the range may exclude valid enum values}}
: ContiguousEnumSerializer<
MissedHighExcl, MissedHighExcl::A, MissedHighExcl::C> {};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.