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
8d8f8907
Unverified
Commit
8d8f8907
authored
Apr 10, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
💩
first try on #1045
parent
acf10d9a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
0 deletions
+55
-0
include/nlohmann/detail/iterators/iteration_proxy.hpp
include/nlohmann/detail/iterators/iteration_proxy.hpp
+17
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+17
-0
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+21
-0
No files found.
include/nlohmann/detail/iterators/iteration_proxy.hpp
View file @
8d8f8907
...
...
@@ -2,6 +2,7 @@
#include <cstddef> // size_t
#include <string> // string, to_string
#include <iterator> // input_iterator_tag
#include <nlohmann/detail/value_t.hpp>
...
...
@@ -16,6 +17,13 @@ template<typename IteratorType> class iteration_proxy
/// helper class for iteration
class
iteration_proxy_internal
{
public:
using
difference_type
=
std
::
ptrdiff_t
;
using
value_type
=
iteration_proxy_internal
;
using
pointer
=
iteration_proxy_internal
*
;
using
reference
=
iteration_proxy_internal
&
;
using
iterator_category
=
std
::
input_iterator_tag
;
private:
/// the iterator
IteratorType
anchor
;
...
...
@@ -25,6 +33,9 @@ template<typename IteratorType> class iteration_proxy
public:
explicit
iteration_proxy_internal
(
IteratorType
it
)
noexcept
:
anchor
(
it
)
{}
iteration_proxy_internal
(
const
iteration_proxy_internal
&
)
=
default
;
iteration_proxy_internal
&
operator
=
(
const
iteration_proxy_internal
&
)
=
default
;
/// dereference operator (needed for range-based for)
iteration_proxy_internal
&
operator
*
()
{
...
...
@@ -40,6 +51,12 @@ template<typename IteratorType> class iteration_proxy
return
*
this
;
}
/// equality operator (needed for InputIterator)
bool
operator
==
(
const
iteration_proxy_internal
&
o
)
const
noexcept
{
return
anchor
==
o
.
anchor
;
}
/// inequality operator (needed for range-based for)
bool
operator
!=
(
const
iteration_proxy_internal
&
o
)
const
noexcept
{
...
...
single_include/nlohmann/json.hpp
View file @
8d8f8907
...
...
@@ -4491,6 +4491,7 @@ class iter_impl
#include <cstddef> // size_t
#include <string> // string, to_string
#include <iterator> // input_iterator_tag
// #include <nlohmann/detail/value_t.hpp>
...
...
@@ -4506,6 +4507,13 @@ template<typename IteratorType> class iteration_proxy
/// helper class for iteration
class
iteration_proxy_internal
{
public:
using
difference_type
=
std
::
ptrdiff_t
;
using
value_type
=
iteration_proxy_internal
;
using
pointer
=
iteration_proxy_internal
*
;
using
reference
=
iteration_proxy_internal
&
;
using
iterator_category
=
std
::
input_iterator_tag
;
private:
/// the iterator
IteratorType
anchor
;
...
...
@@ -4515,6 +4523,9 @@ template<typename IteratorType> class iteration_proxy
public:
explicit
iteration_proxy_internal
(
IteratorType
it
)
noexcept
:
anchor
(
it
)
{}
iteration_proxy_internal
(
const
iteration_proxy_internal
&
)
=
default
;
iteration_proxy_internal
&
operator
=
(
const
iteration_proxy_internal
&
)
=
default
;
/// dereference operator (needed for range-based for)
iteration_proxy_internal
&
operator
*
()
{
...
...
@@ -4530,6 +4541,12 @@ template<typename IteratorType> class iteration_proxy
return
*
this
;
}
/// equality operator (needed for InputIterator)
bool
operator
==
(
const
iteration_proxy_internal
&
o
)
const
noexcept
{
return
anchor
==
o
.
anchor
;
}
/// inequality operator (needed for range-based for)
bool
operator
!=
(
const
iteration_proxy_internal
&
o
)
const
noexcept
{
...
...
test/src/unit-regression.cpp
View file @
8d8f8907
...
...
@@ -1615,4 +1615,25 @@ TEST_CASE("regression tests")
float_json
j2
=
{
1000.0
,
2000.0
,
3000.0
};
CHECK
(
float_json
::
from_ubjson
(
float_json
::
to_ubjson
(
j2
,
true
,
true
))
==
j2
);
}
SECTION
(
"issue #1045 - Using STL algorithms with JSON containers with expected results?"
)
{
json
diffs
=
nlohmann
::
json
::
array
();
json
m1
{{
"key1"
,
42
}};
json
m2
{{
"key2"
,
42
}};
auto
p1
=
m1
.
items
();
auto
p2
=
m2
.
items
();
using
it_type
=
decltype
(
p1
.
begin
());
std
::
set_difference
(
p1
.
begin
(),
p1
.
end
(),
p2
.
begin
(),
p2
.
end
(),
std
::
inserter
(
diffs
,
diffs
.
end
()),
[
&
](
const
it_type
&
e1
,
const
it_type
&
e2
)
->
bool
{
return
(
e1
.
key
()
<
e2
.
key
())
and
(
e1
.
value
()
<
e2
.
value
());
});
CHECK
(
diffs
.
size
()
==
2
);
}
}
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