Add serializer for vector of non-trivial types#281
Conversation
|
A single level of template parameters works quite easily with the above code. Changing the test code to use: writer.Write<int>(data); // **Produces the following binary output: Here the vector has a length prefix written to the data. The individual strings do not. There it is calling the non-length-type prefixed version of the template<typename T, typename A, typename ... Args>The call would then be to: Write<Args...>(element); // Call custom serializerHowever, the Indeed, how do you differentiate between writing a vector with a length prefix, and writing a vector with no length prefix, but including a length prefix on the strings written: // Ambiguous
writer.Write<int>(vector); // Vector is length prefixed, strings are not
writer.Write<char>(vector); // Vector is not length prefixed, but strings areIt's a little more clear if both are length prefixed, but that might not always be desirable: // Probably still ambiguous due to T and A parameters
writer.Write<int, char>(vector); // Vector is int length prefixed, strings are char length prefixedEdit: This looks promising: |
Contains notes about future changes to `enable_if` guards, explaining where this is going.
7890b31 to
cd9645c
Compare
|
This branch was getting really stale. I squashed the commits together, as they were experimental and fixing up earlier commits in the branch. I then rebased the branch onto current code. Will still need to revisit this. I've lost context on it, though it seems there are good notes in the PR thread and associated issue. |
Work-in-progress:
This is a quick attempt that doesn't account for forwarding of template parameters. Care will need to be taken to properly forward types to custom serialization methods.
This requires the guard update in PR #280 in order to resolve calls to the new method.
Current output of the test code in Issue #276 is:
As can be seen, the strings are not length prefixed, and neither is the vector data as a whole. Forwarding of template type parameters will be needed to properly accomplish this.