mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-04 12:43:24 +00:00
[C++]Support reverse iterator in Vector (#5128)
* Add `const` keyword to the `operator-(const uoffset_t &)` function in `VectorIterator` * Support reverse iterator in Vector Introduced a new VectorReverseIterator type. We cannot directly use `std::reverse_iterator<VectorIterator>` because the signature of `operator*` and `operator->` in the VectorIterator class are not standard signatures. Also added `rbegin()`, `rend()`, `cbegin()`, `cend()`, `crbegin()` and `crend()` in the Vector class.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
63d51afd11
commit
c2f40c37b2
@@ -255,6 +255,24 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length,
|
||||
TEST_EQ(*it, inv_data[indx]);
|
||||
}
|
||||
|
||||
for (auto it = inventory->cbegin(); it != inventory->cend(); ++it) {
|
||||
auto indx = it - inventory->cbegin();
|
||||
TEST_EQ(*it, inv_vec.at(indx)); // Use bounds-check.
|
||||
TEST_EQ(*it, inv_data[indx]);
|
||||
}
|
||||
|
||||
for (auto it = inventory->rbegin(); it != inventory->rend(); ++it) {
|
||||
auto indx = inventory->rend() - it;
|
||||
TEST_EQ(*it, inv_vec.at(indx)); // Use bounds-check.
|
||||
TEST_EQ(*it, inv_data[indx]);
|
||||
}
|
||||
|
||||
for (auto it = inventory->crbegin(); it != inventory->crend(); ++it) {
|
||||
auto indx = inventory->crend() - it;
|
||||
TEST_EQ(*it, inv_vec.at(indx)); // Use bounds-check.
|
||||
TEST_EQ(*it, inv_data[indx]);
|
||||
}
|
||||
|
||||
TEST_EQ(monster->color(), Color_Blue);
|
||||
|
||||
// Example of accessing a union:
|
||||
|
||||
Reference in New Issue
Block a user