Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
7742859b
Unverified
Commit
7742859b
authored
Mar 24, 2021
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
⚗
add more std::string_view support
parent
d7705170
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
14 deletions
+62
-14
json.hpp
include/nlohmann/json.hpp
+31
-7
json.hpp
single_include/nlohmann/json.hpp
+31
-7
No files found.
include/nlohmann/json.hpp
View file @
7742859b
...
@@ -3680,7 +3680,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3680,7 +3680,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
reference
operator
[](
const
typename
object_t
::
key_type
&
key
)
template
<
class
KeyType
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
reference
operator
[](
const
KeyType
&
key
)
{
{
// implicitly convert null value to an empty object
// implicitly convert null value to an empty object
if
(
is_null
())
if
(
is_null
())
...
@@ -3729,7 +3734,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3729,7 +3734,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
const_reference
operator
[](
const
typename
object_t
::
key_type
&
key
)
const
template
<
class
KeyType
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
const_reference
operator
[](
const
KeyType
&
key
)
const
{
{
// const operator[] only works for objects
// const operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
@@ -3884,10 +3894,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3884,10 +3894,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
template
<
class
ValueType
,
typename
std
::
enable_if
<
template
<
class
KeyType
,
class
ValueType
,
typename
std
::
enable_if
<
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
,
int
>::
type
=
0
>
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
(
ValueType
value
(
const
typename
object_t
::
key_type
&
key
,
const
ValueType
&
default_value
)
const
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
ValueType
value
(
const
KeyType
&
key
,
const
ValueType
&
default_value
)
const
{
{
// at only works for objects
// at only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
@@ -3909,7 +3923,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -3909,7 +3923,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@brief overload for a default value of type const char*
@brief overload for a default value of type const char*
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
*/
*/
string_t
value
(
const
typename
object_t
::
key_type
&
key
,
const
char
*
default_value
)
const
template
<
class
KeyType
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
string_t
value
(
const
KeyType
&
key
,
const
char
*
default_value
)
const
{
{
return
value
(
key
,
string_t
(
default_value
));
return
value
(
key
,
string_t
(
default_value
));
}
}
...
@@ -4332,7 +4351,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -4332,7 +4351,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
size_type
erase
(
const
typename
object_t
::
key_type
&
key
)
template
<
class
KeyType
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
size_type
erase
(
const
KeyType
&
key
)
{
{
// this erase only works for objects
// this erase only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
...
single_include/nlohmann/json.hpp
View file @
7742859b
...
@@ -20493,7 +20493,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20493,7 +20493,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
reference
operator
[](
const
typename
object_t
::
key_type
&
key
)
template
<
class
KeyType
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
reference
operator
[](
const
KeyType
&
key
)
{
{
// implicitly convert null value to an empty object
// implicitly convert null value to an empty object
if
(
is_null
())
if
(
is_null
())
...
@@ -20542,7 +20547,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20542,7 +20547,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
const_reference
operator
[](
const
typename
object_t
::
key_type
&
key
)
const
template
<
class
KeyType
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
const_reference
operator
[](
const
KeyType
&
key
)
const
{
{
// const operator[] only works for objects
// const operator[] only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
@@ -20697,10 +20707,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20697,10 +20707,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
// using std::is_convertible in a std::enable_if will fail when using explicit conversions
template
<
class
ValueType
,
typename
std
::
enable_if
<
template
<
class
KeyType
,
class
ValueType
,
typename
std
::
enable_if
<
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
detail
::
is_getable
<
basic_json_t
,
ValueType
>::
value
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
,
int
>::
type
=
0
>
&&
!
std
::
is_same
<
value_t
,
ValueType
>::
value
&&
(
ValueType
value
(
const
typename
object_t
::
key_type
&
key
,
const
ValueType
&
default_value
)
const
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
),
int
>::
type
=
0
>
ValueType
value
(
const
KeyType
&
key
,
const
ValueType
&
default_value
)
const
{
{
// at only works for objects
// at only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
@@ -20722,7 +20736,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -20722,7 +20736,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@brief overload for a default value of type const char*
@brief overload for a default value of type const char*
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
@copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const
*/
*/
string_t
value
(
const
typename
object_t
::
key_type
&
key
,
const
char
*
default_value
)
const
template
<
class
KeyType
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
string_t
value
(
const
KeyType
&
key
,
const
char
*
default_value
)
const
{
{
return
value
(
key
,
string_t
(
default_value
));
return
value
(
key
,
string_t
(
default_value
));
}
}
...
@@ -21145,7 +21164,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
...
@@ -21145,7 +21164,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
@since version 1.0.0
*/
*/
size_type
erase
(
const
typename
object_t
::
key_type
&
key
)
template
<
class
KeyType
,
typename
std
::
enable_if
<
#if defined(JSON_HAS_CPP_17)
std
::
is_same
<
KeyType
,
std
::
string_view
>::
value
||
#endif
std
::
is_convertible
<
KeyType
,
typename
object_t
::
key_type
>::
value
,
int
>::
type
=
0
>
size_type
erase
(
const
KeyType
&
key
)
{
{
// this erase only works for objects
// this erase only works for objects
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
if
(
JSON_HEDLEY_LIKELY
(
is_object
()))
...
...
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