[wpiutil] Add reverse/bidirectional iterators to wpi::circular_buffer (#8275)

Use std::reverse_iterator<> to create reverse iterators, make other
iterators bidirectional to allow for this. Added unit tests.
This commit is contained in:
Peter Lilley
2025-10-04 02:13:55 -04:00
committed by GitHub
parent 3972b01c51
commit f1b9be551b
4 changed files with 175 additions and 8 deletions

View File

@@ -251,4 +251,18 @@ TEST(CircularBufferTest, Iterator) {
EXPECT_EQ(values[i], elem);
++i;
}
// reverse_iterator
i = 2;
for (auto it = queue.rbegin(); it != queue.rend(); ++it) {
EXPECT_EQ(values[i], *it);
--i;
}
// const_reverse_iterator
i = 2;
for (auto it = queue.crbegin(); it != queue.crend(); ++it) {
EXPECT_EQ(values[i], *it);
--i;
}
}

View File

@@ -145,4 +145,18 @@ TEST(StaticCircularBufferTest, Iterator) {
EXPECT_EQ(values[i], elem);
++i;
}
// reverse_iterator
i = 2;
for (auto it = queue.rbegin(); it != queue.rend(); ++it) {
EXPECT_EQ(values[i], *it);
--i;
}
// const_reverse_iterator
i = 2;
for (auto it = queue.crbegin(); it != queue.crend(); ++it) {
EXPECT_EQ(values[i], *it);
--i;
}
}