Remove two-phase initialization
zserio's two-phase initialization (constructor + initialize(...)) doesn't allow those types to be used with modern C++ practices.
Two-phase initialization is bad practice in general, but concretely it doesn't allow to create fully-initialized immutable types with a single expression. It also allows for errors if people forget to initialize types.
I understand zserio uses it to initialize parameterized types, but perhaps another solution can be thought of.
Thank you for pointing this out. You are right, this is a real pain in generated C++ code and this solution is bad from object design point of view.
Recently, we were fighting with this (please see https://github.com/ndsev/zserio/issues/532#issuecomment-1789173920) but unfortunally we were not able to find out something better in reasonable time. Of course, this does not mean that better solution does not exist, so we will continue with this struggling.
The main reason of the two-phase initialization is that the zserio parameters are stored directly in objects as raw pointers (please see https://github.com/ndsev/zserio/discussions/484).
The clear solution for this should be usage of shared pointers but it would bring as well performance and memory penalties. But it might be that this won't be a big problem anymore.
Currently, the most promissing solution seems to be the following:
Parameterized types will not store parameters at all but parameters will be passed to all generated methods like write(), bitSizeOf(), etc...
However, because parameter can be a reference to a parent parameter, all parameters from parents should be passed to parameterized type as well. And this is too complicated for generic schema.
In all cases, we did not give it up and we are still trying to find out better solution for this problem.