The following example demonstrates the (de-)serialization of dense and sparse vectors:
{
archive << d << s;
}
{
archive >> d1;
archive >> d2
}
Binary archive for the portable serialization of data.
Definition: Archive.h:140
Efficient implementation of an arbitrary sized sparse vector.
Definition: CompressedVector.h:220
Efficient implementation of an arbitrary sized vector.
Definition: DynamicVector.h:223
Efficient implementation of a fixed-sized vector.
Definition: StaticVector.h:230
constexpr bool columnVector
Transpose flag for column vectors.
Definition: TransposeFlag.h:58
constexpr bool rowVector
Transpose flag for row vectors.
Definition: TransposeFlag.h:73
The (de-)serialization of vectors is not restricted to vectors of built-in data type, but can also be used for vectors with vector or matrix element type:
{
archive << vec;
}
{
archive >> vec;
}
As the examples demonstrates, the vector serialization offers an enormous flexibility. However, several actions result in errors:
- vectors cannot be reconstituted as matrices (and vice versa)
- the element type of the serialized and reconstituted vector must match, which means that on the source and destination platform the general type (signed/unsigned integral or floating point) and the size of the type must be exactly the same
- when reconstituting a
StaticVector
, its size must match the size of the serialized vector
In case an error is encountered during (de-)serialization, a std::runtime_exception
is thrown.
Previous: Serialization Next: Matrix Serialization