mirror of
https://github.com/nlohmann/json.git
synced 2026-10-11 17:07:15 +00:00
Compare commits
3
Commits
a0a4e7cc0b
...
85cb7ea9aa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85cb7ea9aa | ||
|
|
7192763f15 | ||
|
|
93e49decbd |
No files matched your search
@@ -1,7 +1,7 @@
|
||||
wheel==0.47.0
|
||||
|
||||
mkdocs==1.6.1 # documentation framework
|
||||
mkdocs-git-revision-date-localized-plugin==1.5.1 # plugin "git-revision-date-localized"
|
||||
mkdocs-git-revision-date-localized-plugin==1.5.2 # plugin "git-revision-date-localized"
|
||||
mkdocs-material==9.7.6 # theme for mkdocs
|
||||
mkdocs-material-extensions==1.3.1 # extensions
|
||||
mkdocs-minify-plugin==0.8.0 # plugin "minify"
|
||||
|
||||
@@ -388,14 +388,10 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||
|
||||
ConstructibleObjectType ret;
|
||||
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
|
||||
using value_type = typename ConstructibleObjectType::value_type;
|
||||
std::transform(
|
||||
inner_object->begin(), inner_object->end(),
|
||||
std::inserter(ret, ret.begin()),
|
||||
[](typename BasicJsonType::object_t::value_type const & p)
|
||||
for (const auto& p : *inner_object)
|
||||
{
|
||||
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
});
|
||||
ret.emplace(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
}
|
||||
obj = std::move(ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -741,10 +741,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
#endif
|
||||
}
|
||||
|
||||
iterator set_parents(iterator it, typename iterator::difference_type count_set_parents)
|
||||
iterator set_parents(iterator it, std::ptrdiff_t count_set_parents)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
for (typename iterator::difference_type i = 0; i < count_set_parents; ++i)
|
||||
for (std::ptrdiff_t i = 0; i < count_set_parents; ++i)
|
||||
{
|
||||
(it + i)->m_parent = this;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,25 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
||||
: Container{first, last, alloc} {}
|
||||
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator() )
|
||||
: Container{init, alloc} {}
|
||||
ordered_map(const ordered_map&) = default;
|
||||
ordered_map(ordered_map&&) noexcept(std::is_nothrow_move_constructible<Container>::value) = default;
|
||||
~ordered_map() = default;
|
||||
|
||||
ordered_map& operator=(const ordered_map& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
ordered_map tmp(other);
|
||||
Container::operator=(std::move(static_cast<Container&>(tmp)));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ordered_map& operator=(ordered_map&& other) noexcept(std::is_nothrow_move_assignable<Container>::value)
|
||||
{
|
||||
Container::operator=(std::move(static_cast<Container&>(other)));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
|
||||
{
|
||||
|
||||
@@ -5306,14 +5306,10 @@ inline void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
|
||||
|
||||
ConstructibleObjectType ret;
|
||||
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
|
||||
using value_type = typename ConstructibleObjectType::value_type;
|
||||
std::transform(
|
||||
inner_object->begin(), inner_object->end(),
|
||||
std::inserter(ret, ret.begin()),
|
||||
[](typename BasicJsonType::object_t::value_type const & p)
|
||||
for (const auto& p : *inner_object)
|
||||
{
|
||||
return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
});
|
||||
ret.emplace(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
|
||||
}
|
||||
obj = std::move(ret);
|
||||
}
|
||||
|
||||
@@ -20032,6 +20028,25 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
||||
: Container{first, last, alloc} {}
|
||||
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator() )
|
||||
: Container{init, alloc} {}
|
||||
ordered_map(const ordered_map&) = default;
|
||||
ordered_map(ordered_map&&) noexcept(std::is_nothrow_move_constructible<Container>::value) = default;
|
||||
~ordered_map() = default;
|
||||
|
||||
ordered_map& operator=(const ordered_map& other)
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
ordered_map tmp(other);
|
||||
Container::operator=(std::move(static_cast<Container&>(tmp)));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ordered_map& operator=(ordered_map&& other) noexcept(std::is_nothrow_move_assignable<Container>::value)
|
||||
{
|
||||
Container::operator=(std::move(static_cast<Container&>(other)));
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
|
||||
{
|
||||
@@ -21020,10 +21035,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
#endif
|
||||
}
|
||||
|
||||
iterator set_parents(iterator it, typename iterator::difference_type count_set_parents)
|
||||
iterator set_parents(iterator it, std::ptrdiff_t count_set_parents)
|
||||
{
|
||||
#if JSON_DIAGNOSTICS
|
||||
for (typename iterator::difference_type i = 0; i < count_set_parents; ++i)
|
||||
for (std::ptrdiff_t i = 0; i < count_set_parents; ++i)
|
||||
{
|
||||
(it + i)->m_parent = this;
|
||||
}
|
||||
|
||||
@@ -69,3 +69,15 @@ TEST_CASE("ordered_json")
|
||||
CHECK(oj1.size() == 4);
|
||||
CHECK(oj1.dump() == "{\"c\":1,\"b\":2,\"a\":3,\"d\":42}");
|
||||
}
|
||||
|
||||
TEST_CASE("regression test for issue #3732 - iteration_proxy_value<iter_impl<ordered_json>>")
|
||||
{
|
||||
// Naming the proxy type in a function-parameter position forces eager
|
||||
// instantiation of basic_json<ordered_map>; previously this hit an
|
||||
// incomplete-type error in set_parents().
|
||||
auto fn = [](nlohmann::detail::iteration_proxy_value<nlohmann::detail::iter_impl<nlohmann::ordered_json>> const& val)
|
||||
{
|
||||
return val.value();
|
||||
};
|
||||
static_cast<void>(fn);
|
||||
}
|
||||
@@ -1240,4 +1240,93 @@ TEST_CASE("regression test #5074 - single-element brace init with JSON_BRACE_INI
|
||||
}
|
||||
#endif
|
||||
|
||||
struct Example_5122
|
||||
{
|
||||
float b = 2;
|
||||
nlohmann::ordered_map<std::string, std::string> c{}; // NOLINT(readability-redundant-member-init): needed for GCC -Weffc++
|
||||
int a = 1;
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Example_5122, b, c, a)
|
||||
};
|
||||
|
||||
TEST_CASE("regression test #5122 - from_json into types holding nlohmann::ordered_map")
|
||||
{
|
||||
Example_5122 src;
|
||||
src.c.emplace("first", "1");
|
||||
src.c.emplace("second", "2");
|
||||
|
||||
ordered_json const j = src;
|
||||
Example_5122 const dst = j.get<Example_5122>();
|
||||
|
||||
CHECK(dst.b == src.b);
|
||||
CHECK(dst.a == src.a);
|
||||
REQUIRE(dst.c.size() == src.c.size());
|
||||
auto src_it = src.c.begin();
|
||||
auto dst_it = dst.c.begin();
|
||||
for (; src_it != src.c.end(); ++src_it, ++dst_it)
|
||||
{
|
||||
CHECK(dst_it->first == src_it->first);
|
||||
CHECK(dst_it->second == src_it->second);
|
||||
}
|
||||
}
|
||||
|
||||
// -Wself-assign-overloaded was introduced in Clang 7. Gate the pragma on
|
||||
// __has_warning so older Clang versions do not error with "unknown warning
|
||||
// group". The __has_warning check has to stay inside the __clang__ branch
|
||||
// because GCC does not provide it and would tokenize-error on the argument.
|
||||
#if defined(__clang__) && defined(__has_warning)
|
||||
#if __has_warning("-Wself-assign-overloaded")
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING("-Wself-assign-overloaded")
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TEST_CASE("regression test #5122 - nlohmann::ordered_map copy-assignment is self-assignment safe")
|
||||
{
|
||||
nlohmann::ordered_map<std::string, std::string> m;
|
||||
m.emplace("first", "1");
|
||||
m.emplace("second", "2");
|
||||
|
||||
// Insertion order is preserved by ordered_map, so we can check it directly.
|
||||
m = m;
|
||||
|
||||
REQUIRE(m.size() == 2);
|
||||
auto it = m.begin();
|
||||
CHECK(it->first == "first");
|
||||
CHECK(it->second == "1");
|
||||
++it;
|
||||
CHECK(it->first == "second");
|
||||
CHECK(it->second == "2");
|
||||
}
|
||||
|
||||
#if defined(__clang__) && defined(__has_warning)
|
||||
#if __has_warning("-Wself-assign-overloaded")
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TEST_CASE("regression test #5122 - nlohmann::ordered_map move-assignment transfers contents")
|
||||
{
|
||||
nlohmann::ordered_map<std::string, std::string> src;
|
||||
src.emplace("first", "1");
|
||||
src.emplace("second", "2");
|
||||
|
||||
nlohmann::ordered_map<std::string, std::string> dst;
|
||||
dst.emplace("stale", "x");
|
||||
dst = std::move(src);
|
||||
|
||||
REQUIRE(dst.size() == 2);
|
||||
auto it = dst.begin();
|
||||
CHECK(it->first == "first");
|
||||
CHECK(it->second == "1");
|
||||
++it;
|
||||
CHECK(it->first == "second");
|
||||
CHECK(it->second == "2");
|
||||
|
||||
// Re-assigning into the moved-from object must leave it in a usable state.
|
||||
src = nlohmann::ordered_map<std::string, std::string>{};
|
||||
src.emplace("after-move", "3");
|
||||
REQUIRE(src.size() == 1);
|
||||
CHECK(src.begin()->first == "after-move");
|
||||
}
|
||||
|
||||
DOCTEST_CLANG_SUPPRESS_WARNING_POP
|
||||
Reference in new issue
Block a user