[libc-commits] [libc] [libc] Implement forward iterators (PR #93916)
via libc-commits
libc-commits at lists.llvm.org
Thu May 30 20:23:21 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: None (jameshu15869)
<details>
<summary>Changes</summary>
- Implements forward iterators to use in https://github.com/llvm/llvm-project/pull/92009
---
Full diff: https://github.com/llvm/llvm-project/pull/93916.diff
2 Files Affected:
- (modified) libc/src/__support/fixedvector.h (+4)
- (modified) libc/test/src/__support/CPP/array_test.cpp (+5)
``````````diff
diff --git a/libc/src/__support/fixedvector.h b/libc/src/__support/fixedvector.h
index 81747ee10067c..6aeb4d56363e9 100644
--- a/libc/src/__support/fixedvector.h
+++ b/libc/src/__support/fixedvector.h
@@ -63,6 +63,10 @@ template <typename T, size_t CAPACITY> class FixedVector {
return reverse_iterator{&store[item_count]};
}
LIBC_INLINE constexpr reverse_iterator rend() { return store.rend(); }
+
+ using iterator = typename cpp::array<T, CAPACITY>::iterator;
+ LIBC_INLINE constexpr iterator begin() { return store.begin(); }
+ LIBC_INLINE constexpr iterator end() { return iterator{&store[item_count]}; }
};
} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/__support/CPP/array_test.cpp b/libc/test/src/__support/CPP/array_test.cpp
index f2d7bff636e42..06991871f6172 100644
--- a/libc/test/src/__support/CPP/array_test.cpp
+++ b/libc/test/src/__support/CPP/array_test.cpp
@@ -28,6 +28,11 @@ TEST(LlvmLibcArrayTest, Basic) {
ASSERT_EQ(*(++it), 1);
ASSERT_EQ(*(++it), 0);
+ auto forward_it = a.begin();
+ ASSERT_EQ(*forward_it, 0);
+ ASSERT_EQ(*(++forward_it), 1);
+ ASSERT_EQ(*(++forward_it), 2);
+
for (int &x : a)
ASSERT_GE(x, 0);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/93916
More information about the libc-commits
mailing list