Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
ed62129f
Commit
ed62129f
authored
May 27, 2017
by
HenryLee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Override n + iterator operator in the iterator
parent
52adf3fd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
src/json.hpp
src/json.hpp
+13
-2
test/src/unit-iterators2.cpp
test/src/unit-iterators2.cpp
+20
-0
No files found.
src/json.hpp
View file @
ed62129f
...
...
@@ -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
;
...
...
test/src/unit-iterators2.cpp
View file @
ed62129f
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment