[libc-commits] [libc] [libc] Add front() and erase() to FixedVector (PR #213866)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Wed Aug 5 01:12:33 PDT 2026
================
@@ -106,3 +106,40 @@ TEST(LlvmLibcFixedVectorTest, ConstForwardIteration) {
ASSERT_EQ(*it, arr[idx]);
}
}
+
+TEST(LlvmLibcFixedVectorTest, Front) {
+ LIBC_NAMESPACE::FixedVector<int, 20> fixed_vector;
+ for (int i = 0; i < 5; i++)
+ ASSERT_TRUE(fixed_vector.push_back(i));
+ ASSERT_EQ(fixed_vector.front(), 0);
+ fixed_vector.front() = 10;
+ ASSERT_EQ(fixed_vector.front(), 10);
+ fixed_vector.front() = 0;
+
+ const auto &const_vector = fixed_vector;
+ ASSERT_EQ(const_vector.front(), 0);
+}
+
+TEST(LlvmLibcFixedVectorTest, Erase) {
+ LIBC_NAMESPACE::FixedVector<int, 20> fixed_vector;
+ for (int i = 0; i < 5; i++)
+ ASSERT_TRUE(fixed_vector.push_back(i));
+
+ auto it = fixed_vector.erase(fixed_vector.begin());
+ ASSERT_EQ(it, fixed_vector.begin());
+ ASSERT_EQ(fixed_vector.size(), size_t(4));
----------------
kaladron wrote:
This should be static_cast<size_t>(4) (here and elsewhere).
Although I hate this. We should define integer literal suffixes for these:
```c++
constexpr std::size_t operator"" zu(unsigned long long int val) {
return static_cast<std::size_t>(val);
}
```
And then our code would be much nicer. =/
https://github.com/llvm/llvm-project/pull/213866
More information about the libc-commits
mailing list