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
a5633380
Unverified
Commit
a5633380
authored
Jul 22, 2021
by
Niels Lohmann
Committed by
GitHub
Jul 22, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2825 from ldionne/ldionne-lazy
Properly constrain the basic_json conversion operator
parents
19a5e121
b0e5965d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
19 deletions
+41
-19
include/nlohmann/detail/meta/detected.hpp
include/nlohmann/detail/meta/detected.hpp
+3
-0
include/nlohmann/detail/meta/type_traits.hpp
include/nlohmann/detail/meta/type_traits.hpp
+3
-0
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+12
-10
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+17
-9
test/src/unit-regression2.cpp
test/src/unit-regression2.cpp
+6
-0
No files found.
include/nlohmann/detail/meta/detected.hpp
View file @
a5633380
...
...
@@ -39,6 +39,9 @@ struct detector<Default, void_t<Op<Args...>>, Op, Args...>
template
<
template
<
class
...
>
class
Op
,
class
...
Args
>
using
is_detected
=
typename
detector
<
nonesuch
,
void
,
Op
,
Args
...
>::
value_t
;
template
<
template
<
class
...
>
class
Op
,
class
...
Args
>
struct
is_detected_lazy
:
is_detected
<
Op
,
Args
...
>
{
};
template
<
template
<
class
...
>
class
Op
,
class
...
Args
>
using
detected_t
=
typename
detector
<
nonesuch
,
void
,
Op
,
Args
...
>::
type
;
...
...
include/nlohmann/detail/meta/type_traits.hpp
View file @
a5633380
...
...
@@ -157,6 +157,9 @@ template<class B1, class... Bn>
struct
conjunction
<
B1
,
Bn
...
>
:
std
::
conditional
<
bool
(
B1
::
value
),
conjunction
<
Bn
...
>
,
B1
>::
type
{};
// https://en.cppreference.com/w/cpp/types/negation
template
<
class
B
>
struct
negation
:
std
::
integral_constant
<
bool
,
!
B
::
value
>
{
};
// Reimplementation of is_constructible and is_default_constructible, due to them being broken for
// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367).
// This causes compile errors in e.g. clang 3.5 or gcc 4.9.
...
...
include/nlohmann/json.hpp
View file @
a5633380
...
...
@@ -3359,17 +3359,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
*/
template
<
typename
ValueType
,
typename
std
::
enable_if
<
!
std
::
is_pointer
<
ValueType
>
::
value
&&
!
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>::
value
&&
!
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
&&
!
detail
::
is_basic_json
<
ValueType
>::
value
&&
!
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
detail
::
conjunction
<
detail
::
negation
<
std
::
is_pointer
<
ValueType
>
>
,
detail
::
negation
<
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>>
,
detail
::
negation
<
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>>
,
detail
::
negation
<
detail
::
is_basic_json
<
ValueType
>>
,
detail
::
negation
<
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>>
,
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
&&
!
std
::
is_same
<
ValueType
,
typename
std
::
string_view
>::
value
detail
::
negation
<
std
::
is_same
<
ValueType
,
std
::
string_view
>>
,
#endif
&&
detail
::
is_detected
<
detail
::
get_template_function
,
const
basic_json_t
&
,
ValueType
>::
value
,
int
>::
type
=
0
>
JSON_EXPLICIT
operator
ValueType
()
const
detail
::
is_detected_lazy
<
detail
::
get_template_function
,
const
basic_json_t
&
,
ValueType
>
>::
value
,
int
>::
type
=
0
>
JSON_EXPLICIT
operator
ValueType
()
const
{
// delegate the call to get<>() const
return
get
<
ValueType
>
();
...
...
@@ -8907,7 +8909,7 @@ template<>
inline
void
swap
<
nlohmann
::
json
>
(
nlohmann
::
json
&
j1
,
nlohmann
::
json
&
j2
)
noexcept
(
// NOLINT(readability-inconsistent-declaration-parameter-name)
is_nothrow_move_constructible
<
nlohmann
::
json
>::
value
&&
// NOLINT(misc-redundant-expression)
is_nothrow_move_assignable
<
nlohmann
::
json
>::
value
)
)
{
j1
.
swap
(
j2
);
}
...
...
single_include/nlohmann/json.hpp
View file @
a5633380
...
...
@@ -3309,6 +3309,9 @@ struct detector<Default, void_t<Op<Args...>>, Op, Args...>
template
<
template
<
class
...
>
class
Op
,
class
...
Args
>
using
is_detected
=
typename
detector
<
nonesuch
,
void
,
Op
,
Args
...
>::
value_t
;
template
<
template
<
class
...
>
class
Op
,
class
...
Args
>
struct
is_detected_lazy
:
is_detected
<
Op
,
Args
...
>
{
};
template
<
template
<
class
...
>
class
Op
,
class
...
Args
>
using
detected_t
=
typename
detector
<
nonesuch
,
void
,
Op
,
Args
...
>::
type
;
...
...
@@ -3554,6 +3557,9 @@ template<class B1, class... Bn>
struct
conjunction
<
B1
,
Bn
...
>
:
std
::
conditional
<
bool
(
B1
::
value
),
conjunction
<
Bn
...
>
,
B1
>::
type
{};
// https://en.cppreference.com/w/cpp/types/negation
template
<
class
B
>
struct
negation
:
std
::
integral_constant
<
bool
,
!
B
::
value
>
{
};
// Reimplementation of is_constructible and is_default_constructible, due to them being broken for
// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367).
// This causes compile errors in e.g. clang 3.5 or gcc 4.9.
...
...
@@ -20422,17 +20428,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
*/
template
<
typename
ValueType
,
typename
std
::
enable_if
<
!
std
::
is_pointer
<
ValueType
>
::
value
&&
!
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>::
value
&&
!
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
&&
!
detail
::
is_basic_json
<
ValueType
>::
value
&&
!
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
detail
::
conjunction
<
detail
::
negation
<
std
::
is_pointer
<
ValueType
>
>
,
detail
::
negation
<
std
::
is_same
<
ValueType
,
detail
::
json_ref
<
basic_json
>>>
,
detail
::
negation
<
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>>
,
detail
::
negation
<
detail
::
is_basic_json
<
ValueType
>>
,
detail
::
negation
<
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>>
,
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
&&
!
std
::
is_same
<
ValueType
,
typename
std
::
string_view
>::
value
detail
::
negation
<
std
::
is_same
<
ValueType
,
std
::
string_view
>>
,
#endif
&&
detail
::
is_detected
<
detail
::
get_template_function
,
const
basic_json_t
&
,
ValueType
>::
value
,
int
>::
type
=
0
>
JSON_EXPLICIT
operator
ValueType
()
const
detail
::
is_detected_lazy
<
detail
::
get_template_function
,
const
basic_json_t
&
,
ValueType
>
>::
value
,
int
>::
type
=
0
>
JSON_EXPLICIT
operator
ValueType
()
const
{
// delegate the call to get<>() const
return
get
<
ValueType
>
();
...
...
test/src/unit-regression2.cpp
View file @
a5633380
...
...
@@ -39,6 +39,7 @@ using nlohmann::json;
#include <list>
#include <cstdio>
#include <type_traits>
#include <utility>
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
...
...
@@ -620,4 +621,9 @@ TEST_CASE("regression tests 2")
nlohmann
::
to_json
(
o
[
"foo"
],
s
);
}
}
SECTION
(
"issue #2825 - Properly constrain the basic_json conversion operator"
)
{
static_assert
(
std
::
is_copy_assignable
<
nlohmann
::
ordered_json
>::
value
,
""
);
}
}
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