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
86a96b05
Unverified
Commit
86a96b05
authored
Jun 28, 2018
by
Niels Lohmann
Committed by
GitHub
Jun 28, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1134 from Daniel599/feature/items_iterator
fixed compile error for #1045
parents
396a914f
1566ad40
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
3 deletions
+82
-3
include/nlohmann/detail/conversions/to_json.hpp
include/nlohmann/detail/conversions/to_json.hpp
+10
-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
+33
-3
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+22
-0
No files found.
include/nlohmann/detail/conversions/to_json.hpp
View file @
86a96b05
...
...
@@ -294,6 +294,16 @@ void to_json(BasicJsonType& j, const std::pair<Args...>& p)
j
=
{
p
.
first
,
p
.
second
};
}
template
<
typename
IteratorType
>
class
iteration_proxy
;
// TODO: Forward decl needed, maybe move somewhere else
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
std
::
is_same
<
T
,
typename
iteration_proxy
<
typename
BasicJsonType
::
iterator
>
::
iteration_proxy_internal
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
T
b
)
noexcept
{
typename
BasicJsonType
::
object_t
tmp_obj
;
tmp_obj
[
b
.
key
()]
=
b
.
value
();
// TODO: maybe there is a better way?
external_constructor
<
value_t
::
object
>::
construct
(
j
,
std
::
move
(
tmp_obj
));
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
>
void
to_json_tuple_impl
(
BasicJsonType
&
j
,
const
Tuple
&
t
,
index_sequence
<
Idx
...
>
)
{
...
...
include/nlohmann/detail/iterators/iteration_proxy.hpp
View file @
86a96b05
...
...
@@ -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
;
...
...
@@ -31,6 +39,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
*
()
{
...
...
@@ -46,6 +57,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 @
86a96b05
...
...
@@ -1606,6 +1606,16 @@ void to_json(BasicJsonType& j, const std::pair<Args...>& p)
j
=
{
p
.
first
,
p
.
second
};
}
template
<
typename
IteratorType
>
class
iteration_proxy
;
// TODO: Forward decl needed, maybe move somewhere else
template
<
typename
BasicJsonType
,
typename
T
,
enable_if_t
<
std
::
is_same
<
T
,
typename
iteration_proxy
<
typename
BasicJsonType
::
iterator
>
::
iteration_proxy_internal
>::
value
,
int
>
=
0
>
void
to_json
(
BasicJsonType
&
j
,
T
b
)
noexcept
{
typename
BasicJsonType
::
object_t
tmp_obj
;
tmp_obj
[
b
.
key
()]
=
b
.
value
();
// TODO: maybe there is a better way?
external_constructor
<
value_t
::
object
>::
construct
(
j
,
std
::
move
(
tmp_obj
));
}
template
<
typename
BasicJsonType
,
typename
Tuple
,
std
::
size_t
...
Idx
>
void
to_json_tuple_impl
(
BasicJsonType
&
j
,
const
Tuple
&
t
,
index_sequence
<
Idx
...
>
)
{
...
...
@@ -5329,6 +5339,7 @@ class iter_impl
#include <cstddef> // size_t
#include <string> // string, to_string
#include <iterator> // input_iterator_tag
// #include <nlohmann/detail/value_t.hpp>
...
...
@@ -5344,6 +5355,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
;
...
...
@@ -5359,6 +5377,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
*
()
{
...
...
@@ -5374,6 +5395,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
{
...
...
@@ -8544,7 +8571,7 @@ boundaries compute_boundaries(FloatType value)
constexpr
int
kMinExp
=
1
-
kBias
;
constexpr
uint64_t
kHiddenBit
=
uint64_t
{
1
}
<<
(
kPrecision
-
1
);
// = 2^(p-1)
using
bits_type
=
typename
std
::
conditional
<
kPrecision
==
24
,
uint32_t
,
uint64_t
>::
type
;
using
bits_type
=
typename
std
::
conditional
<
kPrecision
==
24
,
uint32_t
,
uint64_t
>::
type
;
const
uint64_t
bits
=
reinterpret_bits
<
bits_type
>
(
value
);
const
uint64_t
E
=
bits
>>
(
kPrecision
-
1
);
...
...
@@ -8955,7 +8982,10 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent,
// = ((p1 ) * 2^-e + (p2 )) * 2^e
// = p1 + p2 * 2^e
const
diyfp
one
(
uint64_t
{
1
}
<<
-
M_plus
.
e
,
M_plus
.
e
);
const
diyfp
one
(
uint64_t
{
1
}
<<
-
M_plus
.
e
,
M_plus
.
e
);
uint32_t
p1
=
static_cast
<
uint32_t
>
(
M_plus
.
f
>>
-
one
.
e
);
// p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.)
uint64_t
p2
=
M_plus
.
f
&
(
one
.
f
-
1
);
// p2 = f mod 2^-e
...
...
@@ -18475,7 +18505,7 @@ struct hash<nlohmann::json>
/// @note: do not remove the space after '<',
/// see https://github.com/nlohmann/json/pull/679
template
<
>
struct
less
<
::
nlohmann
::
detail
::
value_t
>
struct
less
<::
nlohmann
::
detail
::
value_t
>
{
/*!
@brief compare two value_t enum values
...
...
test/src/unit-regression.cpp
View file @
86a96b05
...
...
@@ -1581,4 +1581,26 @@ 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
{
using
comper_pair
=
std
::
pair
<
std
::
string
,
decltype
(
e1
.
value
())
>
;
// Trying to avoid unneeded copy
return
comper_pair
(
e1
.
key
(),
e1
.
value
())
<
comper_pair
(
e2
.
key
(),
e2
.
value
());
// Using pair comper
});
CHECK
(
diffs
.
size
()
==
1
);
// Note the change here, was 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