[all-commits] [llvm/llvm-project] 660890: [ADT] Extend EnumeratedArray

Jannik Silvanus via All-commits all-commits at lists.llvm.org
Tue Oct 18 08:09:39 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 6608908b1b7fd9146f632b040c0b48c2fb661966
      https://github.com/llvm/llvm-project/commit/6608908b1b7fd9146f632b040c0b48c2fb661966
  Author: Jannik Silvanus <jannik.silvanus at amd.com>
  Date:   2022-10-18 (Tue, 18 Oct 2022)

  Changed paths:
    M llvm/include/llvm/ADT/EnumeratedArray.h
    M llvm/unittests/ADT/EnumeratedArrayTest.cpp

  Log Message:
  -----------
  [ADT] Extend EnumeratedArray

EnumeratedArray is essentially a wrapper around a fixed-size
array that uses enum values instead of integers as indices.

 * Add iterator support (begin/end/rbegin/rend), which enables
   the use of iterator/range based algorithms on EnumeratedArrays.
 * Add common container typedefs (value_type etc.), allowing
   drop-in replacements of other containers in cases relying on these.
 * Add a constructor that takes an std::initializer_list<T>.
 * Make the size() function const.
 * Add empty().

Iterator support slightly lowers the protection non-type-safe accesses,
because iterator arithmetic is not enum-based, and one can now use
*(begin() + IntIndex). However, it is and was also always possible to
just cast arbitrary indices to the enum type.

Differential Revision: https://reviews.llvm.org/D135594




More information about the All-commits mailing list