mirror of
https://github.com/nlohmann/json.git
synced 2024-11-24 23:09:02 +08:00
Override n + iterator operator in the iterator
This commit is contained in:
parent
52adf3fd5b
commit
ed62129f8e
15
src/json.hpp
15
src/json.hpp
@ -8474,18 +8474,29 @@ class basic_json
|
||||
@brief add to iterator
|
||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||
*/
|
||||
iter_impl operator+(difference_type i)
|
||||
iter_impl operator+(difference_type i) const
|
||||
{
|
||||
auto result = *this;
|
||||
result += i;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief addition of distance and iterator
|
||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||
*/
|
||||
friend iter_impl operator+(difference_type i, const iter_impl& it)
|
||||
{
|
||||
auto result = it;
|
||||
result += i;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief subtract from iterator
|
||||
@pre The iterator is initialized; i.e. `m_object != nullptr`.
|
||||
*/
|
||||
iter_impl operator-(difference_type i)
|
||||
iter_impl operator-(difference_type i) const
|
||||
{
|
||||
auto result = *this;
|
||||
result -= i;
|
||||
|
@ -269,6 +269,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it + 1, json::invalid_iterator);
|
||||
CHECK_THROWS_WITH(it + 1, "[json.exception.invalid_iterator.209] cannot use offsets with object iterators");
|
||||
}
|
||||
{
|
||||
auto it = j_object.begin();
|
||||
CHECK_THROWS_AS(1 + it, json::invalid_iterator);
|
||||
CHECK_THROWS_WITH(1 + it, "[json.exception.invalid_iterator.209] cannot use offsets with object iterators");
|
||||
}
|
||||
{
|
||||
auto it = j_object.cbegin();
|
||||
CHECK_THROWS_AS(1 + it, json::invalid_iterator);
|
||||
CHECK_THROWS_WITH(1 + it, "[json.exception.invalid_iterator.209] cannot use offsets with object iterators");
|
||||
}
|
||||
{
|
||||
auto it = j_object.begin();
|
||||
CHECK_THROWS_AS(it -= 1, json::invalid_iterator);
|
||||
@ -688,6 +698,16 @@ TEST_CASE("iterators 2")
|
||||
CHECK_THROWS_AS(it + 1, json::invalid_iterator);
|
||||
CHECK_THROWS_WITH(it + 1, "[json.exception.invalid_iterator.209] cannot use offsets with object iterators");
|
||||
}
|
||||
{
|
||||
auto it = j_object.rbegin();
|
||||
CHECK_THROWS_AS(1 + it, json::invalid_iterator);
|
||||
CHECK_THROWS_WITH(1 + it, "[json.exception.invalid_iterator.209] cannot use offsets with object iterators");
|
||||
}
|
||||
{
|
||||
auto it = j_object.crbegin();
|
||||
CHECK_THROWS_AS(1 + it, json::invalid_iterator);
|
||||
CHECK_THROWS_WITH(1 + it, "[json.exception.invalid_iterator.209] cannot use offsets with object iterators");
|
||||
}
|
||||
{
|
||||
auto it = j_object.rbegin();
|
||||
CHECK_THROWS_AS(it -= 1, json::invalid_iterator);
|
||||
|
Loading…
Reference in New Issue
Block a user