Rename the emit lambda in the image writer for Qt compatibility

Qt defines emit as an empty macro, so a Qt header included before
json_view.hpp broke the lambda's declaration (see #5865). The slots
variables in the image tests are renamed as well.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-17 14:22:23 +02:00
1 parent b4126cf3fd
commit d70d06dd43
3 files changed
+11 -11

No files matched your search

+3 -3
View File
@@ -105,7 +105,7 @@ inline void compact_nodes(const document_data& d, std::size_t arena_size, std::v
}
return r;
};
const auto emit = [&](const node * v)
const auto copy_node = [&](const node * v)
{
node r = *v;
switch (static_cast<value_t>(v->kind))
@@ -159,7 +159,7 @@ inline void compact_nodes(const document_data& d, std::size_t arena_size, std::v
}
out.push_back(r);
};
emit(d.nodes);
copy_node(d.nodes);
while (!stack.empty())
{
frame& top = stack.back();
@@ -184,7 +184,7 @@ inline void compact_nodes(const document_data& d, std::size_t arena_size, std::v
v = document_data::deref(top.cur);
top.cur = document_data::after(top.cur);
}
emit(v); // may grow the stack (top is not used afterwards)
copy_node(v); // may grow the stack (top is not used afterwards)
}
}
+3 -3
View File
@@ -4623,7 +4623,7 @@ inline void compact_nodes(const document_data& d, std::size_t arena_size, std::v
}
return r;
};
const auto emit = [&](const node * v)
const auto copy_node = [&](const node * v)
{
node r = *v;
switch (static_cast<value_t>(v->kind))
@@ -4677,7 +4677,7 @@ inline void compact_nodes(const document_data& d, std::size_t arena_size, std::v
}
out.push_back(r);
};
emit(d.nodes);
copy_node(d.nodes);
while (!stack.empty())
{
frame& top = stack.back();
@@ -4702,7 +4702,7 @@ inline void compact_nodes(const document_data& d, std::size_t arena_size, std::v
v = document_data::deref(top.cur);
top.cur = document_data::after(top.cur);
}
emit(v); // may grow the stack (top is not used afterwards)
copy_node(v); // may grow the stack (top is not used afterwards)
}
}
+5 -5
View File
@@ -294,7 +294,7 @@ TEST_CASE("json_view images: round trips")
{
// the hash is not seeded: keys can be found that land in one slot of
// a table (see json_view: "colliding keys")
const auto keys_for = [](std::size_t slots, std::size_t colliding_count, std::size_t spread_count)
const auto keys_for = [](std::size_t table_size, std::size_t colliding_count, std::size_t spread_count)
{
std::vector<std::string> colliding;
std::vector<std::string> spread;
@@ -306,7 +306,7 @@ TEST_CASE("json_view images: round trips")
{
key[i] = static_cast<char>('a' + (x % 26));
}
const bool lands_in_slot_zero = (nlohmann::detail::view::key_hash(key.data(), key.size()) & (slots - 1)) == 0;
const bool lands_in_slot_zero = (nlohmann::detail::view::key_hash(key.data(), key.size()) & (table_size - 1)) == 0;
if (lands_in_slot_zero && colliding.size() < colliding_count)
{
colliding.push_back(key);
@@ -335,14 +335,14 @@ TEST_CASE("json_view images: round trips")
// long chain
const struct // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays): an unnamed type
{
std::size_t slots;
std::size_t table_size;
std::size_t colliding;
std::size_t spread;
} cases[] = {{1024, 300, 0}, {512, 40, 160}};
for (const auto& c : cases)
{
CAPTURE(c.slots)
std::vector<std::string> keys = keys_for(c.slots, c.colliding, c.spread);
CAPTURE(c.table_size)
std::vector<std::string> keys = keys_for(c.table_size, c.colliding, c.spread);
const std::size_t members = keys.size();
// a duplicate of a colliding key, of the first and of a spread key
const std::vector<std::string> duplicated = {keys[c.colliding - 1], keys[0], keys[members - 1]};