
Thorsten Ottosen wrote:
class gps_position { public: int degrees; int minutes; float seconds; gps_position(){}; gps_position(int d, int m, float s) : degrees(d), minutes(m), seconds(s) {} };
I think it should be stated that this is not recommended practice, ie, this class has a non-trivial invariant and should not have public members.
I might add a friend rather than use public. But this small code snipet is used to illustrate the non-intrusive serialization - nothing more. BTW the actual demo programs don't use this. What is the non-trivial invariant here?
A better example might be to use std::pair.
The examples use pointers in arrays and pointers in standard containers. I think the text shouldstate that this is not recommended; or even better, throw in a shared_ptr instead. The code in the example is inherently exception unsafe.
Therefore I also think that container< shared_ptr<T> > should be supported by default whereas container< T* > is, well, ok if you don't have exceptions somehow.
Writing a good tutorial is much harder than it looks. My main motivation was to introduce one concept at a time. The basic building blocks of serialization are serialization of primitives, pointers and classes - both intrusive and non-intrusive. All the rest is the result of composition of these basic operations. My tutorial reflects this. That's why serialization implementations of standard library components such as pair, vector, etc are described at the end rather than at the beginning - they are not primitive operations. Anyway, I'll consider adding some comments to remind the reader of the intended purpose of he tutorial example. Robert Ramey