/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** * EnumSet<T, U> is a set of values defined by an enumeration. It is implemented * using a bit mask with the size of U for each value. It works both for enum * and enum class types. EnumSet also works with U being a BitSet.
*/ template <typename T, typename Serialized = typename std::make_unsigned< typename std::underlying_type<T>::type>::type> class EnumSet { public: using valueType = T; using serializedType = Serialized;
/** * Union
*/
constexpr EnumSet operator+(const EnumSet& aEnumSet) const {
EnumSet result(*this);
result += aEnumSet; return result;
}
/** * Remove an element
*/
constexpr void operator-=(T aEnum) {
IncVersion();
mBitField &= ~(BitFor(aEnum));
}
/** * Remove an element
*/
constexpr EnumSet operator-(T aEnum) const {
EnumSet result(*this);
result -= aEnum; return result;
}
/** * Remove a set of elements
*/
constexpr void operator-=(const EnumSet& aEnumSet) {
IncVersion();
mBitField &= ~(aEnumSet.mBitField);
}
/** * Remove a set of elements
*/
constexpr EnumSet operator-(const EnumSet& aEnumSet) const {
EnumSet result(*this);
result -= aEnumSet; return result;
}
/** * Test is an element is contained in the set.
*/
constexpr bool contains(T aEnum) const { return HasBitFor(aEnum); }
/** * Test if a set is contained in the set.
*/
constexpr bool contains(const EnumSet& aEnumSet) const { return (mBitField & aEnumSet.mBitField) == aEnumSet.mBitField;
}
/** * Return the number of elements in the set.
*/
size_t size() const { if constexpr (std::is_unsigned_v<Serialized>) { if constexpr (kMaxBits > 32) { return CountPopulation64(mBitField);
} else { return CountPopulation32(mBitField);
}
} else { return mBitField.Count();
}
}
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 ist noch experimentell.