Take the output adapter by reference at the serializer ctor

Per review: the serializer still holds the adapter as a non-owning
pointer, but the constructor now takes output_adapter_protocol<char>&
and takes its address internally, so every call site passes a
reference. A reference cannot be null and reads as a borrow, which
makes the lifetime contract harder to get wrong than handing over a
raw pointer. The stored member and the write path are unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAYM1qhSA2FDaDcGfPW3fG
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-09-01 05:29:01 +00:00
committed by Claude
co-authored by Claude
parent 2998f2c731
commit c401d495a3
4 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -99,7 +99,7 @@ void check_escaped(const char* original, const char* escaped, const bool ensure_
{
std::stringstream ss;
nlohmann::detail::output_stream_adapter<char> adapter(ss);
json::serializer s(&adapter, ' ');
json::serializer s(adapter, ' ');
s.dump_escaped(original, ensure_ascii);
s.flush(); // dump_escaped writes into the serializer's internal buffer
CHECK(ss.str() == escaped);