Skip to content

Commit

Permalink
Adapt code to review
Browse files Browse the repository at this point in the history
  • Loading branch information
barcode committed Jul 5, 2022
1 parent 477e417 commit b2f9dc0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions docs/examples/json_base_class_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ void visitor_adaptor_with_metadata::do_visit(const Ptr& ptr, const Fnc& fnc) con
j.at(i).do_visit(ptr / std::to_string(i), fnc);
}
break;
case value_t::discarded:
break;
case value_t::null:
case value_t::string:
case value_t::boolean:
case value_t::number_integer:
case value_t::number_unsigned:
case value_t::number_float:
case value_t::binary:
default:
fnc(ptr, j);
break;
case value_t::discarded:
default:
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/mkdocs/docs/api/basic_json/json_base_class_t.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The default value for `CustomBaseClass` is `void`. In this case an empty base cl
#### Limitations

The type `CustomBaseClass` has to be a default constructible class.
`basic_json` only supports copy/move construction/assignement if `CustomBaseClass` does so as well.
`basic_json` only supports copy/move construction/assignment if `CustomBaseClass` does so as well.

## Examples

Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,12 +1238,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @brief move constructor
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
basic_json(basic_json&& other) noexcept
: json_base_class_t(static_cast < json_base_class_t&& > (other)),
: json_base_class_t(std::move(other)),
m_type(std::move(other.m_type)),
m_value(std::move(other.m_value))
{
// check that passed value is valid
other.assert_invariant(false);
other.assert_invariant(false); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved)

// invalidate payload
other.m_type = value_t::null;
Expand Down
2 changes: 1 addition & 1 deletion include/nlohmann/json_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ template<template<typename U, typename V, typename... Args> class ObjectType =
template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer =
adl_serializer,
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
class BinaryType = std::vector<std::uint8_t>,
class CustomBaseClass = void>
class basic_json;

Expand Down
6 changes: 3 additions & 3 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3182,7 +3182,7 @@ template<template<typename U, typename V, typename... Args> class ObjectType =
template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer =
adl_serializer,
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
class BinaryType = std::vector<std::uint8_t>,
class CustomBaseClass = void>
class basic_json;

Expand Down Expand Up @@ -19670,12 +19670,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @brief move constructor
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
basic_json(basic_json&& other) noexcept
: json_base_class_t(static_cast < json_base_class_t&& > (other)),
: json_base_class_t(std::move(other)),
m_type(std::move(other.m_type)),
m_value(std::move(other.m_value))
{
// check that passed value is valid
other.assert_invariant(false);
other.assert_invariant(false); // NOLINT(bugprone-use-after-move,hicpp-invalid-access-moved)

// invalidate payload
other.m_type = value_t::null;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/unit-custom-base-class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ TEST_CASE("JSON Node Metadata")
{
using json = json_with_metadata<std::unique_ptr<int>>;
json value;
value.metadata().reset(new int(42)); // NOLINT
value.metadata().reset(new int(42)); // NOLINT(cppcoreguidelines-owning-memory)
auto moved = std::move(value);

CHECK(moved.metadata() != nullptr);
Expand Down

0 comments on commit b2f9dc0

Please sign in to comment.