Skip to content

Serialize strings with an allocator of their own - #366

Merged
gennaroprota merged 1 commit into
developfrom
feature/serialize-strings-with-any-allocator
Aug 7, 2026
Merged

Serialize strings with an allocator of their own#366
gennaroprota merged 1 commit into
developfrom
feature/serialize-strings-with-any-allocator

Conversation

@gennaroprota

Copy link
Copy Markdown
Collaborator

The archives implement primitives for std::string and std::wstring only, so a basic_string with an allocator of its own, std::pmr::string being the usual case, could be serialized only by declaring it primitive_type. That declaration states the archive already handles the type, which is untrue here, and the generic fallbacks silently truncated the string at the first whitespace or, for the binary archives, copied its bytes.

Such a string now borrows the primitive of the correspondingly built default allocated string, so it needs no declaration at all. The name passed to make_nvp is null, which keeps the representation identical to that of std::string in every archive, xml included, and lets the two interoperate.

Fixes #267.

The archives implement primitives for `std::string` and `std::wstring`
only, so a `basic_string` with an allocator of its own,
`std::pmr::string` being the usual case, could be serialized only by
declaring it `primitive_type`.  That declaration states the archive
already handles the type, which is untrue here, and the generic
fallbacks silently truncated the string at the first whitespace or, for
the binary archives, copied its bytes.

Such a string now borrows the primitive of the correspondingly built
default allocated string, so it needs no declaration at all.  The name
passed to `make_nvp` is null, which keeps the representation identical
to that of `std::string` in every archive, xml included, and lets the
two interoperate.

Fixes #267.
@gennaroprota
gennaroprota added this pull request to the merge queue Aug 7, 2026
Merged via the queue into develop with commit e66bb7b Aug 7, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deserialization of XML archive fails with std::pmr::string

1 participant