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
48aa4416
Unverified
Commit
48aa4416
authored
May 04, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
add swap function for binary type
parent
a50a1408
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
2 deletions
+68
-2
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+34
-1
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+34
-1
No files found.
include/nlohmann/json.hpp
View file @
48aa4416
...
...
@@ -876,7 +876,6 @@ class basic_json
@since version 3.8.0
*/
using
binary_t
=
BinaryType
;
/*!
...
...
@@ -1204,6 +1203,7 @@ class basic_json
assert
(
m_type
!=
value_t
::
object
or
m_value
.
object
!=
nullptr
);
assert
(
m_type
!=
value_t
::
array
or
m_value
.
array
!=
nullptr
);
assert
(
m_type
!=
value_t
::
string
or
m_value
.
string
!=
nullptr
);
assert
(
m_type
!=
value_t
::
binary
or
m_value
.
binary
!=
nullptr
);
}
public:
...
...
@@ -6015,6 +6015,39 @@ class basic_json
}
}
/*!
@brief exchanges the values
Exchanges the contents of a JSON string with those of @a other. Does not
invoke any move, copy, or swap operations on individual elements. All
iterators and references remain valid. The past-the-end iterator is
invalidated.
@param[in,out] other binary to exchange the contents with
@throw type_error.310 when JSON value is not a string; example: `"cannot
use swap() with boolean"`
@complexity Constant.
@liveexample{The example below shows how strings can be swapped with
`swap()`.,swap__binary_t}
@since version 3.8.0
*/
void
swap
(
binary_t
&
other
)
{
// swap only works for strings
if
(
JSON_HEDLEY_LIKELY
(
is_binary
()))
{
std
::
swap
(
*
(
m_value
.
binary
),
other
);
}
else
{
JSON_THROW
(
type_error
::
create
(
310
,
"cannot use swap() with "
+
std
::
string
(
type_name
())));
}
}
/// @}
public:
...
...
single_include/nlohmann/json.hpp
View file @
48aa4416
...
...
@@ -16383,7 +16383,6 @@ class basic_json
@since version 3.8.0
*/
using
binary_t
=
BinaryType
;
/*!
...
...
@@ -16711,6 +16710,7 @@ class basic_json
assert
(
m_type
!=
value_t
::
object
or
m_value
.
object
!=
nullptr
);
assert
(
m_type
!=
value_t
::
array
or
m_value
.
array
!=
nullptr
);
assert
(
m_type
!=
value_t
::
string
or
m_value
.
string
!=
nullptr
);
assert
(
m_type
!=
value_t
::
binary
or
m_value
.
binary
!=
nullptr
);
}
public:
...
...
@@ -21522,6 +21522,39 @@ class basic_json
}
}
/*!
@brief exchanges the values
Exchanges the contents of a JSON string with those of @a other. Does not
invoke any move, copy, or swap operations on individual elements. All
iterators and references remain valid. The past-the-end iterator is
invalidated.
@param[in,out] other binary to exchange the contents with
@throw type_error.310 when JSON value is not a string; example: `"cannot
use swap() with boolean"`
@complexity Constant.
@liveexample{The example below shows how strings can be swapped with
`swap()`.,swap__binary_t}
@since version 3.8.0
*/
void
swap
(
binary_t
&
other
)
{
// swap only works for strings
if
(
JSON_HEDLEY_LIKELY
(
is_binary
()))
{
std
::
swap
(
*
(
m_value
.
binary
),
other
);
}
else
{
JSON_THROW
(
type_error
::
create
(
310
,
"cannot use swap() with "
+
std
::
string
(
type_name
())));
}
}
/// @}
public:
...
...
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