-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend Stream library to support serializing containers of non-trivial types #278
Comments
I was just thinking, the above method generalizes to any container type, even ones that use non-contiguous memory. The specific reference to I suppose technically you might want to guard the template with the notion of the container being iterable (and the element type being writable by the stream library). There's no built in type_trait check for iterable, but a solution can be found here: |
I came across Another point worth mentioning, which is touched on in that, is using I came across It allows for consistent treatment of containers with a More to the point here, I realized the only contiguous memory containers are likely to provide a |
Instead of trying to copy the whole vector to the stream at once (only possible for non-trivial types), we could instead iterate over each element of the vector, and serialize the element individually. This is possible if there is an appropriate
Write(T& object)
method. Such is already the case forstd::string
, as the Stream library natively supports this. The code of course generalizes to any non-trivial type, given the existence of an appropriate serialization method.Example vector write method for non-trivially-copyable objects:
Example usage:
In the above example, the serialization code would loop over the vector's elements, and call the custom
std::string
serialization code for each element.Combine this with the proposal in Issue #277, and it would also add support for other arbitrary non-trivial types, provided they supply an appropriate
T::Write(Stream::Writer& writer)
method.The text was updated successfully, but these errors were encountered: