Serializing enumerated values

An enumeratation is a distinct type, but it can be serialized by specializing x::serialization::serialize_integer_type:

enum errmsg_t {

// ...


namespace x {
    namespace serialization {
        template<> class serialize_integer_type<errmsg_t>

            typedef char int_t;

After declaring the above specialization, instances of errmsg_t can be serialized and deserialized normally. This example uses char values for serializing this enumeration type. Any natural integer type may be declared for int_t. The natural integer type must, of course, be wide enough to represent all values of the enumerated type.


This macro expands to the above definition, and is the preferred way to declare a serializable enumeration.