[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:08:23 PST 2026


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

None

>From 46f91c8d9fc3b8e037217b5d5c44a300297e4791 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] [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



More information about the llvm-branch-commits mailing list