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
3ad6992f
Unverified
Commit
3ad6992f
authored
4 years ago
by
Niels Lohmann
Committed by
GitHub
4 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2405 from karzhenkov/fix-json_ref-move
Fix move constructor of json_ref
parents
e3643aad
42a9dc0b
develop
bon8
coverity_scan
feature/optional
gcc_warning_flags
icpc
issue2615
issue2932
issue3232_use_catch
master
release/3.10.2
release/3.10.3
release/3.10.4
release/3.10.5
string_view
string_view2
update_doctest
v3.10.5
v3.10.4
v3.10.3
v3.10.2
v3.10.1
v3.10.0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
28 deletions
+12
-28
include/nlohmann/detail/json_ref.hpp
include/nlohmann/detail/json_ref.hpp
+6
-14
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+6
-14
No files found.
include/nlohmann/detail/json_ref.hpp
View file @
3ad6992f
...
...
@@ -17,19 +17,14 @@ class json_ref
json_ref
(
value_type
&&
value
)
:
owned_value
(
std
::
move
(
value
))
,
value_ref
(
&
owned_value
)
,
is_rvalue
(
true
)
{}
json_ref
(
const
value_type
&
value
)
:
value_ref
(
const_cast
<
value_type
*>
(
&
value
))
,
is_rvalue
(
false
)
:
value_ref
(
&
value
)
{}
json_ref
(
std
::
initializer_list
<
json_ref
>
init
)
:
owned_value
(
init
)
,
value_ref
(
&
owned_value
)
,
is_rvalue
(
true
)
{}
template
<
...
...
@@ -37,8 +32,6 @@ class json_ref
enable_if_t
<
std
::
is_constructible
<
value_type
,
Args
...>
::
value
,
int
>
=
0
>
json_ref
(
Args
&&
...
args
)
:
owned_value
(
std
::
forward
<
Args
>
(
args
)...)
,
value_ref
(
&
owned_value
)
,
is_rvalue
(
true
)
{}
// class should be movable only
...
...
@@ -50,27 +43,26 @@ class json_ref
value_type
moved_or_copied
()
const
{
if
(
is_rvalue
)
if
(
value_ref
==
nullptr
)
{
return
std
::
move
(
*
value_ref
);
return
std
::
move
(
owned_value
);
}
return
*
value_ref
;
}
value_type
const
&
operator
*
()
const
{
return
*
static_cast
<
value_type
const
*>
(
value_ref
)
;
return
value_ref
?
*
value_ref
:
owned_value
;
}
value_type
const
*
operator
->
()
const
{
return
static_cast
<
value_type
const
*>
(
value_ref
)
;
return
&**
this
;
}
private:
mutable
value_type
owned_value
=
nullptr
;
value_type
*
value_ref
=
nullptr
;
const
bool
is_rvalue
=
true
;
value_type
const
*
value_ref
=
nullptr
;
};
}
// namespace detail
}
// namespace nlohmann
This diff is collapsed.
Click to expand it.
single_include/nlohmann/json.hpp
View file @
3ad6992f
...
...
@@ -12605,19 +12605,14 @@ class json_ref
json_ref(value_type&& value)
: owned_value(std::move(value))
, value_ref(&owned_value)
, is_rvalue(true)
{}
json_ref(const value_type& value)
: value_ref(const_cast<value_type*>(&value))
, is_rvalue(false)
: value_ref(&value)
{}
json_ref(std::initializer_list<json_ref> init)
: owned_value(init)
, value_ref(&owned_value)
, is_rvalue(true)
{}
template <
...
...
@@ -12625,8 +12620,6 @@ class json_ref
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
json_ref(Args && ... args)
: owned_value(std::forward<Args>(args)...)
, value_ref(&owned_value)
, is_rvalue(true)
{}
// class should be movable only
...
...
@@ -12638,27 +12631,26 @@ class json_ref
value_type moved_or_copied() const
{
if (
is_rvalue
)
if (
value_ref == nullptr
)
{
return std::move(
*value_ref
);
return std::move(
owned_value
);
}
return *value_ref;
}
value_type const& operator*() const
{
return
*static_cast<value_type const*>(value_ref)
;
return
value_ref ? *value_ref : owned_value
;
}
value_type const* operator->() const
{
return
static_cast<value_type const*>(value_ref)
;
return
&**this
;
}
private:
mutable value_type owned_value = nullptr;
value_type* value_ref = nullptr;
const bool is_rvalue = true;
value_type const* value_ref = nullptr;
};
} // namespace detail
} // namespace nlohmann
...
...
This diff is collapsed.
Click to expand it.
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