These templates support serialization and deserialization of the following objects:
Native integer types.
Enumerated types, after manually specializing a helper template class.
Native floating point types.
Instances of classes that
implement the
serialize
() template method.
Containers of objects that themselves are serializable, and
which define a default constructor and a copy constructor. The
suitable containers are:
std::basic_string
(including native
string literals,
const char *
);
std::list
,
std::deque
,
std::vector
,
std::map
,
std::multimap
,
std::set
,
std::multiset
,
std::unordered_map
,
std::unordered_multimap
,
std::unordered_set
,
std::unordered_multiset
,
Also:
a std::pair
of two serializable types, a
std::reference_wrapper
of a serializable
type; a
std::tuple
of serializable types.
References to classes
that implement the serialize
() template method,
and the class defines a default constructor, or if serialization
uses custom traits that provide a suitable implementation for
instantiating a reference to the object to be deserialized.
A serialized object can be deserialized only into a structurally
compatible object.
It goes without saying that an object is structurally compatible
to any object of the same exact class.
All containers of the same class are structurally
compatible. A serialized
std::list<std::string>
can be deserialized into a
std::vector<std::string>
, and vice versa.
This applies to
all supported container types. A
std::map
is structurally
compatible to a container of a std::pair
of
the key and value types,
so a serialized
std::map<int, std::string>
may be deserialized
into a std::list<std::pair<int,
std::string> >
.
The opposite is
also true, but only as long as the serialized keys are unique.
An exception gets thrown if a deserialized value cannot be
inserted into its container.
All floating point types are converted to strings before
serialization, so floating point objects are structurally
compatible
with a std::string
. This also means
that a serialized std::string
may be
deserialized into a native floating point object. An exception
gets thrown if the serialized string cannot be parsed as a
floating point type. It is undefined
whether an exception gets thrown if the
floating point type has insufficient precision for the serialized
floating value.
Native character string literals are structurally compatible to their
corresponding std::basic_string
types.
Although native
character string literals may be serialized, deserializing native
character string literals is functionally meaningless. Literal strings
may be deserialized only into
std::basic_string
or its structurally compatible containers.