aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorPiJoules <6019989+PiJoules@users.noreply.github.com>2024-06-25 16:33:36 -0700
committerGitHub <noreply@github.com>2024-06-25 16:33:36 -0700
commit54ca5a800d12bf76dabc957163df02c3ea005627 (patch)
tree56bbb01a38ed402c4234036dc712bcb9c7f3f839 /libc
parent0d533665054c3a04681c46f3ed88960f28777be1 (diff)
downloadllvm-54ca5a800d12bf76dabc957163df02c3ea005627.zip
llvm-54ca5a800d12bf76dabc957163df02c3ea005627.tar.gz
llvm-54ca5a800d12bf76dabc957163df02c3ea005627.tar.bz2
[libc][fixedvector] Add const_iterator begin/end (#96714)
Diffstat (limited to 'libc')
-rw-r--r--libc/src/__support/fixedvector.h5
-rw-r--r--libc/test/src/__support/fixedvector_test.cpp10
2 files changed, 15 insertions, 0 deletions
diff --git a/libc/src/__support/fixedvector.h b/libc/src/__support/fixedvector.h
index 403b162..5161c0d 100644
--- a/libc/src/__support/fixedvector.h
+++ b/libc/src/__support/fixedvector.h
@@ -90,6 +90,11 @@ public:
LIBC_INLINE constexpr iterator begin() { return store.begin(); }
LIBC_INLINE constexpr iterator end() { return iterator{&store[item_count]}; }
+
+ LIBC_INLINE constexpr const_iterator begin() const { return store.begin(); }
+ LIBC_INLINE constexpr const_iterator end() const {
+ return const_iterator{&store[item_count]};
+ }
};
} // namespace LIBC_NAMESPACE
diff --git a/libc/test/src/__support/fixedvector_test.cpp b/libc/test/src/__support/fixedvector_test.cpp
index 212e1ae..b73df04 100644
--- a/libc/test/src/__support/fixedvector_test.cpp
+++ b/libc/test/src/__support/fixedvector_test.cpp
@@ -96,3 +96,13 @@ TEST(LlvmLibcFixedVectorTest, ForwardIteration) {
ASSERT_EQ(*it, arr[idx]);
}
}
+
+TEST(LlvmLibcFixedVectorTest, ConstForwardIteration) {
+ const LIBC_NAMESPACE::cpp::array<int, 4> arr{1, 2, 3, 4};
+ const LIBC_NAMESPACE::FixedVector<int, 5> vec(arr.begin(), arr.end());
+ ASSERT_EQ(vec.size(), arr.size());
+ for (auto it = vec.begin(); it != vec.end(); ++it) {
+ auto idx = it - vec.begin();
+ ASSERT_EQ(*it, arr[idx]);
+ }
+}