[all-commits] [llvm/llvm-project] a428b3: [ADT] Refactor StringMap iterators (NFC) (#156137)

Kazu Hirata via All-commits all-commits at lists.llvm.org
Sun Aug 31 19:18:42 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a428b3081a1aa73e3fddb70127ba3e0fb85d6e3d
      https://github.com/llvm/llvm-project/commit/a428b3081a1aa73e3fddb70127ba3e0fb85d6e3d
  Author: Kazu Hirata <kazu at google.com>
  Date:   2025-08-31 (Sun, 31 Aug 2025)

  Changed paths:
    M clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
    M clang/lib/Driver/OffloadBundler.cpp
    M llvm/include/llvm/ADT/StringMap.h
    M llvm/unittests/ADT/StringMapTest.cpp

  Log Message:
  -----------
  [ADT] Refactor StringMap iterators (NFC) (#156137)

StringMap has four iterator classes:

- StringMapIterBase
- StringMapIterator
- StringMapConstIterator
- StringMapKeyIterator

This patch consolidates the first three into one class, namely
StringMapIterBase, adds a boolean template parameter to indicate
desired constness, and then use "using" directives to specialize the
common class:

  using const_iterator = StringMapIterBase<ValueTy, true>;
  using iterator = StringMapIterBase<ValueTy, false>;

just like how we simplified DenseMapIterator.

Remarks:

- This patch drops CRTP and iterator_facade_base for simplicity.  For
  fairly simple forward iterators, iterator_facade_base doesn't buy us
  much.  We just have to write a few "using" directives and operator!=
  manually.

- StringMapIterBase has a SFINAE-based constructor to construct a
  const iterator from a non-const one just like DenseMapIterator.

- We now rely on compiler-generated copy and assignment operators.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list