[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
Fri Jan 9 14:00:47 PST 2026
https://github.com/bassiounix updated https://github.com/llvm/llvm-project/pull/174820
>From 8de54d6d5490c47217791ad22ad39d3fefb16ccc 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/3] [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 da0b76a345a30..e7bd43e72e380 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 3b8a8430d36bdc50d5b6a2baa51147b4c3362265 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/3] 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
>From 7d82867d1efa9ee5a261d01923bb6314ab1af26b Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Wed, 7 Jan 2026 20:34:39 +0200
Subject: [PATCH 3/3] fix extension
---
.../wctype/conversion/utils/{enumerate.hpp => enumerate.h} | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
rename libc/src/__support/wctype/conversion/utils/{enumerate.hpp => enumerate.h} (98%)
diff --git a/libc/src/__support/wctype/conversion/utils/enumerate.hpp b/libc/src/__support/wctype/conversion/utils/enumerate.h
similarity index 98%
rename from libc/src/__support/wctype/conversion/utils/enumerate.hpp
rename to libc/src/__support/wctype/conversion/utils/enumerate.h
index 9d65d064e8784..dd4d56e483268 100644
--- a/libc/src/__support/wctype/conversion/utils/enumerate.hpp
+++ b/libc/src/__support/wctype/conversion/utils/enumerate.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ENUMERATE_HPP
-#define LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ENUMERATE_HPP
+#ifndef LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ENUMERATE_H
+#define LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ENUMERATE_H
#include "hdr/types/size_t.h"
#include "src/__support/CPP/tuple.h"
@@ -67,4 +67,4 @@ enumerate(Iterable &&iterable) {
} // namespace LIBC_NAMESPACE_DECL
-#endif // LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ENUMERATE_HPP
+#endif // LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ENUMERATE_H
More information about the llvm-branch-commits
mailing list