Fix reverse iterator subscript exception for objects (#6125)
* Fix reverse iterator subscript exception for objects Signed-off-by: Anshika Grover <anshikag.151107@gmail.com> * Add reverse iterator subscript tests and comment Signed-off-by: Anshika Grover <anshikag.151107@gmail.com> * Add primitive reverse iterator subscript tests Signed-off-by: Anshika Grover <anshikag.151107@gmail.com> --------- Signed-off-by: Anshika Grover <anshikag.151107@gmail.com>
This commit is contained in:
1 parent
d732d616ba
commit
555ef48fb6
3 files changed
+17
-6
No files matched your search
@@ -108,7 +108,9 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
|
|||||||
/// access to successor
|
/// access to successor
|
||||||
reference operator[](difference_type n) const
|
reference operator[](difference_type n) const
|
||||||
{
|
{
|
||||||
return *(this->operator+(n));
|
// the element n positions after *this is the one n + 1 positions before base();
|
||||||
|
// Base::operator[] then reports invalid_iterator.208 for object iterators
|
||||||
|
return this->base()[-n - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return the key of an object iterator
|
/// return the key of an object iterator
|
||||||
|
|||||||
Generated
+3
-1
@@ -26795,7 +26795,9 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
|
|||||||
/// access to successor
|
/// access to successor
|
||||||
reference operator[](difference_type n) const
|
reference operator[](difference_type n) const
|
||||||
{
|
{
|
||||||
return *(this->operator+(n));
|
// the element n positions after *this is the one n + 1 positions before base();
|
||||||
|
// Base::operator[] then reports invalid_iterator.208 for object iterators
|
||||||
|
return this->base()[-n - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return the key of an object iterator
|
/// return the key of an object iterator
|
||||||
|
|||||||
@@ -830,13 +830,13 @@ TEST_CASE("iterators 2")
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
auto it = j_object.rbegin();
|
auto it = j_object.rbegin();
|
||||||
CHECK_THROWS_WITH_AS(it[0], "[json.exception.invalid_iterator.209] cannot use offsets with object iterators", json::invalid_iterator&);
|
CHECK_THROWS_WITH_AS(it[0], "[json.exception.invalid_iterator.208] cannot use operator[] for object iterators", json::invalid_iterator&);
|
||||||
CHECK_THROWS_WITH_AS(it[1], "[json.exception.invalid_iterator.209] cannot use offsets with object iterators", json::invalid_iterator&);
|
CHECK_THROWS_WITH_AS(it[1], "[json.exception.invalid_iterator.208] cannot use operator[] for object iterators", json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = j_object.crbegin();
|
auto it = j_object.crbegin();
|
||||||
CHECK_THROWS_WITH_AS(it[0], "[json.exception.invalid_iterator.209] cannot use offsets with object iterators", json::invalid_iterator&);
|
CHECK_THROWS_WITH_AS(it[0], "[json.exception.invalid_iterator.208] cannot use operator[] for object iterators", json::invalid_iterator&);
|
||||||
CHECK_THROWS_WITH_AS(it[1], "[json.exception.invalid_iterator.209] cannot use offsets with object iterators", json::invalid_iterator&);
|
CHECK_THROWS_WITH_AS(it[1], "[json.exception.invalid_iterator.208] cannot use operator[] for object iterators", json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -850,6 +850,7 @@ TEST_CASE("iterators 2")
|
|||||||
CHECK(it[3] == json(3));
|
CHECK(it[3] == json(3));
|
||||||
CHECK(it[4] == json(2));
|
CHECK(it[4] == json(2));
|
||||||
CHECK(it[5] == json(1));
|
CHECK(it[5] == json(1));
|
||||||
|
CHECK((j_array.rbegin() + 2)[1] == json(3));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto it = j_array.crbegin();
|
auto it = j_array.crbegin();
|
||||||
@@ -859,6 +860,7 @@ TEST_CASE("iterators 2")
|
|||||||
CHECK(it[3] == json(3));
|
CHECK(it[3] == json(3));
|
||||||
CHECK(it[4] == json(2));
|
CHECK(it[4] == json(2));
|
||||||
CHECK(it[5] == json(1));
|
CHECK(it[5] == json(1));
|
||||||
|
CHECK((j_array.crbegin() + 2)[3] == json(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -888,6 +890,11 @@ TEST_CASE("iterators 2")
|
|||||||
CHECK(it[0] == json(42));
|
CHECK(it[0] == json(42));
|
||||||
CHECK_THROWS_WITH_AS(it[1], "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&);
|
CHECK_THROWS_WITH_AS(it[1], "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
|
CHECK(json(1).rbegin()[0] == json(1));
|
||||||
|
CHECK_THROWS_WITH_AS(json(1).rbegin()[1], "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&);
|
||||||
|
|
||||||
|
CHECK(json(1).crbegin()[0] == json(1));
|
||||||
|
CHECK_THROWS_WITH_AS(json(1).crbegin()[1], "[json.exception.invalid_iterator.214] cannot get value", json::invalid_iterator&);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user