/* -*- 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/. */
/* Iterator over contiguous enum values */
/* * Implements generator functions that create a range to iterate over the values * of a scoped or unscoped enum. Unlike IntegerRange, which can only function on * the underlying integral type, the elements of the generated sequence will * have the type of the enum in question. * * Note that the enum values should be contiguous in the iterated range; * unfortunately there exists no way for EnumeratedRange to enforce this * either dynamically or at compile time.
*/
#ifdef __GNUC__ // Enums can have an unsigned underlying type, which makes some of the // comparisons below always true or always false. Temporarily disable // -Wtype-limits to avoid breaking -Werror builds. # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wtype-limits" #endif
// Create a range to iterate from aBegin to aEnd, exclusive. template <typename EnumType>
constexpr detail::EnumeratedRange<EnumType> MakeEnumeratedRange(EnumType aBegin,
EnumType aEnd) {
MOZ_ASSERT(aBegin <= aEnd, "Cannot generate invalid, unbounded range!"); return detail::EnumeratedRange<EnumType>(aBegin, aEnd);
}
// Create a range to iterate from EnumType(0) to aEnd, exclusive. EnumType(0) // should exist, but note that there is no way for us to ensure that it does! template <typename EnumType>
constexpr detail::EnumeratedRange<EnumType> MakeEnumeratedRange(EnumType aEnd) { return MakeEnumeratedRange(EnumType(0), aEnd);
}
// Create a range to iterate from aBegin to aEnd, inclusive. // // NOTE: This internally constructs a value that is one past `aEnd`, so the // enumeration needs to either have a fixed underlying type, or `aEnd + 1` must // be inside the range of the enumeration, in order to not be undefined // behavior. // // See bug 1614512. template <typename EnumType>
constexpr detail::EnumeratedRange<EnumType> MakeInclusiveEnumeratedRange(
EnumType aBegin, EnumType aEnd) { using EnumUnderlyingType = typename std::underlying_type_t<EnumType>; constauto end = static_cast<EnumUnderlyingType>(aEnd);
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.