Commit cc61017f authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Chromium LUCI CQ

[blink] Add Post Increment Operations to WTF::Deque's Iterators

This change adds post increment operations to WTF::Deque's iterators.
Without these operations the iterators fail to fulfill the requirements
for bidirectional iterators [1] they claim to implement, making them
potentially unusable in generic algorithms.

[1] https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator

Bug: None
Change-Id: I72e3371333fe8adcc609c9b05c13693c9e512f6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2584026Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835767}
parent 43596d79
......@@ -264,12 +264,23 @@ class DequeIterator : public DequeIteratorBase<T, inlineCapacity, Allocator> {
Base::Increment();
return *this;
}
// postfix ++ intentionally omitted
Iterator operator++(int) {
Iterator tmp = *this;
++*this;
return tmp;
}
Iterator& operator--() {
Base::Decrement();
return *this;
}
// postfix -- intentionally omitted
Iterator operator--(int) {
Iterator tmp = *this;
--*this;
return tmp;
}
};
template <typename T,
......@@ -314,12 +325,23 @@ class DequeConstIterator
Base::Increment();
return *this;
}
// postfix ++ intentionally omitted
Iterator operator++(int) {
Iterator tmp = *this;
++*this;
return tmp;
}
Iterator& operator--() {
Base::Decrement();
return *this;
}
// postfix -- intentionally omitted
Iterator operator--(int) {
Iterator tmp = *this;
--*this;
return tmp;
}
};
template <typename T, wtf_size_t inlineCapacity, typename Allocator>
......
......@@ -40,6 +40,42 @@ TEST(DequeTest, Basic) {
EXPECT_EQ(0ul, int_deque.size());
}
TEST(DequeTest, Iterators) {
Deque<int, 2> deque;
deque.push_back(0);
deque.push_back(1);
{
auto it = deque.begin();
EXPECT_EQ(*it, 0);
EXPECT_EQ(*++it, 1);
EXPECT_EQ(++it, deque.end());
}
{
auto it = deque.begin();
EXPECT_EQ(*it++, 0);
EXPECT_EQ(*it++, 1);
EXPECT_EQ(it, deque.end());
}
{
const Deque<int, 2>& c_deque = deque;
auto c_it = c_deque.begin();
EXPECT_EQ(*c_it, 0);
EXPECT_EQ(*++c_it, 1);
EXPECT_EQ(++c_it, c_deque.end());
}
{
const Deque<int, 2>& c_deque = deque;
auto c_it = c_deque.begin();
EXPECT_EQ(*c_it++, 0);
EXPECT_EQ(*c_it++, 1);
EXPECT_EQ(c_it, c_deque.end());
}
}
template <wtf_size_t inlineCapacity>
void CheckNumberSequence(Deque<int, inlineCapacity>& deque,
int from,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment