mirror of
https://github.com/nlohmann/json.git
synced 2026-09-11 18:57:58 +00:00
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:
@@ -1347,13 +1347,13 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
|
||||
if (indent >= 0)
|
||||
{
|
||||
serializer s(&string_adapter, indent_char,
|
||||
serializer s(string_adapter, indent_char,
|
||||
true, ensure_ascii, static_cast<std::size_t>(indent), error_handler);
|
||||
s.dump(*this);
|
||||
}
|
||||
else
|
||||
{
|
||||
serializer s(&string_adapter, indent_char,
|
||||
serializer s(string_adapter, indent_char,
|
||||
false, ensure_ascii, 0, error_handler);
|
||||
s.dump(*this);
|
||||
}
|
||||
@@ -4085,7 +4085,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
|
||||
// do the actual serialization
|
||||
detail::output_stream_adapter<char> stream_adapter(o);
|
||||
serializer s(&stream_adapter, o.fill(),
|
||||
serializer s(stream_adapter, o.fill(),
|
||||
pretty_print, false, static_cast<std::size_t>(indentation));
|
||||
s.dump(j);
|
||||
return o;
|
||||
|
||||
Reference in New Issue
Block a user