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
6661ec75
Commit
6661ec75
authored
Jun 07, 2017
by
HenryLee
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into iterator_arithmetic
parents
0f065edf
92ef1969
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
34 deletions
+88
-34
README.md
README.md
+1
-0
src/json.hpp
src/json.hpp
+19
-34
test/src/unit-iterators1.cpp
test/src/unit-iterators1.cpp
+68
-0
No files found.
README.md
View file @
6661ec75
...
...
@@ -840,6 +840,7 @@ I deeply appreciate the help of the following people.
-
[
tinloaf
](
https://github.com/tinloaf
)
made sure all pushed warnings are properly popped.
-
[
Fytch
](
https://github.com/Fytch
)
found a bug in the documentation.
-
[
Jay Sistar
](
https://github.com/Type1J
)
implemented a Meson build description
-
[
Henry Lee
](
https://github.com/HenryRLee
)
fixed a warning in ICC
Thanks a lot for helping out! Please
[
let me know
](
mailto:mail@nlohmann.me
)
if I forgot someone.
...
...
src/json.hpp
View file @
6661ec75
...
...
@@ -8053,50 +8053,35 @@ class basic_json
}
}
/*
Use operator `const_iterator` instead of `const_iterator(const iterator&
other) noexcept` to avoid two class definitions for @ref iterator and
@ref const_iterator.
This function is only called if this class is an @ref iterator. If this
class is a @ref const_iterator this function is not called.
/*!
@note The conventional copy constructor and copy assignment are
implicitly defined.
Combined with the following converting constructor and assigment,
they support: copy from iterator to iterator,
copy from const iterator to const iterator,
and conversion from iterator to const iterator.
However conversion from const iterator to iterator is not defined.
*/
operator
const_iterator
()
const
{
const_iterator
ret
;
if
(
m_object
)
{
ret
.
m_object
=
m_object
;
ret
.
m_it
=
m_it
;
}
return
ret
;
}
/*!
@brief co
py
constructor
@param[in] other iterator to copy from
@brief co
nverting
constructor
@param[in] other
non-const
iterator to copy from
@note It is not checked whether @a other is initialized.
*/
iter_impl
(
const
iter_impl
&
other
)
noexcept
iter_impl
(
const
iter_impl
<
basic_json
>
&
other
)
noexcept
:
m_object
(
other
.
m_object
),
m_it
(
other
.
m_it
)
{}
/*!
@brief copy assignment
@param[in,out] other iterator to copy from
@brief converting assignment
@param[in,out] other non-const iterator to copy from
@return const/non-const iterator
@note It is not checked whether @a other is initialized.
*/
iter_impl
&
operator
=
(
iter_impl
other
)
noexcept
(
std
::
is_nothrow_move_constructible
<
pointer
>::
value
and
std
::
is_nothrow_move_assignable
<
pointer
>::
value
and
std
::
is_nothrow_move_constructible
<
internal_iterator
>::
value
and
std
::
is_nothrow_move_assignable
<
internal_iterator
>::
value
)
iter_impl
&
operator
=
(
const
iter_impl
<
basic_json
>&
other
)
noexcept
{
std
::
swap
(
m_object
,
other
.
m_object
)
;
std
::
swap
(
m_it
,
other
.
m_it
)
;
m_object
=
other
.
m_object
;
m_it
=
other
.
m_it
;
return
*
this
;
}
...
...
@@ -8596,7 +8581,7 @@ class basic_json
/// associated JSON instance
pointer
m_object
=
nullptr
;
/// the actual iterator of the associated instance
internal_iterator
m_it
=
internal_iterator
();
struct
internal_iterator
m_it
=
internal_iterator
();
};
/*!
...
...
test/src/unit-iterators1.cpp
View file @
6661ec75
...
...
@@ -1511,4 +1511,72 @@ TEST_CASE("iterators 1")
}
}
}
SECTION
(
"conversion from iterator to const iterator"
)
{
SECTION
(
"boolean"
)
{
json
j
=
true
;
json
::
const_iterator
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
}
SECTION
(
"string"
)
{
json
j
=
"hello world"
;
json
::
const_iterator
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
}
SECTION
(
"array"
)
{
json
j
=
{
1
,
2
,
3
};
json
::
const_iterator
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
}
SECTION
(
"object"
)
{
json
j
=
{{
"A"
,
1
},
{
"B"
,
2
},
{
"C"
,
3
}};
json
::
const_iterator
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
}
SECTION
(
"number (integer)"
)
{
json
j
=
23
;
json
::
const_iterator
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
}
SECTION
(
"number (unsigned)"
)
{
json
j
=
23u
;
json
::
const_iterator
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
}
SECTION
(
"number (float)"
)
{
json
j
=
23.42
;
json
::
const_iterator
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
}
SECTION
(
"null"
)
{
json
j
=
nullptr
;
json
::
const_iterator
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
it
=
j
.
begin
();
CHECK
(
it
==
j
.
cbegin
());
}
}
}
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