[llvm-branch-commits] [libc] [libc][wctype] Upstream enumerate header from PtrHash-cc prototype to LLVM libc (PR #174820)

Muhammad Bassiouni via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 7 10:24:43 PST 2026


https://github.com/bassiounix updated https://github.com/llvm/llvm-project/pull/174820

>From d18dd8547d888c98a24649a4c0e8bba8e4985a0f Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Wed, 7 Jan 2026 20:08:51 +0200
Subject: [PATCH 1/2] [libc][wctype] Upstream enumerate header from PtrHash-cc
 prototype to LLVM libc

---
 .../wctype/conversion/utils/CMakeLists.txt    | 10 +++
 .../wctype/conversion/utils/enumerate.hpp     | 66 +++++++++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100644 libc/src/__support/wctype/conversion/utils/enumerate.hpp

diff --git a/libc/src/__support/wctype/conversion/utils/CMakeLists.txt b/libc/src/__support/wctype/conversion/utils/CMakeLists.txt
index 2dcf45e4a0105..492b782c984c8 100644
--- a/libc/src/__support/wctype/conversion/utils/CMakeLists.txt
+++ b/libc/src/__support/wctype/conversion/utils/CMakeLists.txt
@@ -1,3 +1,13 @@
+add_header_library(
+  enumerate
+  HDRS
+    enumerate.h
+  DEPENDS
+    libc.hdr.types.size_t
+    libc.src.__support.CPP.tuple
+    libc.src.__support.common
+)
+
 add_header_library(
   slice
   HDRS
diff --git a/libc/src/__support/wctype/conversion/utils/enumerate.hpp b/libc/src/__support/wctype/conversion/utils/enumerate.hpp
new file mode 100644
index 0000000000000..74f6a568c935f
--- /dev/null
+++ b/libc/src/__support/wctype/conversion/utils/enumerate.hpp
@@ -0,0 +1,66 @@
+//===-- Internal utils for wctype conversion code - enumerate ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ENUMERATE_HPP
+#define LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ENUMERATE_HPP
+
+#include "hdr/types/size_t.h"
+#include "src/__support/CPP/tuple.h"
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace internal_wctype_conversion_utils {
+
+namespace {
+
+template <typename Iterable> struct Enumerate {
+  Iterable &iterable;
+
+  struct Iterator {
+    size_t index;
+    decltype(iterable.begin()) it;
+
+    LIBC_INLINE constexpr auto operator*() const {
+      return cpp::tuple<size_t, decltype(*it)>(index, *it);
+    }
+
+    LIBC_INLINE constexpr Iterator &operator++() {
+      ++index;
+      ++it;
+      return *this;
+    }
+
+    LIBC_INLINE constexpr bool operator!=(const Iterator &other) const {
+      return it != other.it;
+    }
+  };
+
+  LIBC_INLINE constexpr Iterator begin() const { return {0, iterable.begin()}; }
+
+  LIBC_INLINE constexpr Iterator end() const { return {0, iterable.end()}; }
+};
+
+} // namespace
+
+template <typename Iterable>
+LIBC_INLINE static constexpr Enumerate<Iterable> enumerate(Iterable &iterable) {
+  return Enumerate<Iterable>{iterable};
+}
+
+template <typename Iterable>
+LIBC_INLINE static constexpr Enumerate<Iterable>
+enumerate(Iterable &&iterable) {
+  return Enumerate<Iterable>{iterable};
+}
+
+} // namespace internal_wctype_conversion_utils
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ENUMERATE_HPP

>From 640683887d1f4eb7f5145abe3f0162879558284e Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Wed, 7 Jan 2026 20:25:05 +0200
Subject: [PATCH 2/2] fix nesting

---
 libc/src/__support/wctype/conversion/utils/enumerate.hpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libc/src/__support/wctype/conversion/utils/enumerate.hpp b/libc/src/__support/wctype/conversion/utils/enumerate.hpp
index 74f6a568c935f..9d65d064e8784 100644
--- a/libc/src/__support/wctype/conversion/utils/enumerate.hpp
+++ b/libc/src/__support/wctype/conversion/utils/enumerate.hpp
@@ -15,7 +15,9 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-namespace internal_wctype_conversion_utils {
+namespace wctype_internal {
+
+namespace conversion_utils {
 
 namespace {
 
@@ -59,7 +61,9 @@ enumerate(Iterable &&iterable) {
   return Enumerate<Iterable>{iterable};
 }
 
-} // namespace internal_wctype_conversion_utils
+} // namespace conversion_utils
+
+} // namespace wctype_internal
 
 } // namespace LIBC_NAMESPACE_DECL
 



More information about the llvm-branch-commits mailing list