I expect from is_bitwise_serializable trait to serialize class like following (without serialize function):
class A { int a; char b; };
BOOST_IS_BITWISE_SERI
From the documentation:
Some simple classes could be serialized just by directly copying all bits of the class. This is, in particular, the case for POD data types containing no pointer members, and which are neither versioned nor tracked. Some archives, such as non-portable binary archives can make us of this information to substantially speed up serialization.
To indicate the possibility of bitwise serialization the type trait defined in the header file is_bitwise_serializable.hpp is used:
Here are the key points: this optimization
doesn't apply to all archive types e.g.
a binary archive that needs to be portable could not be implemented by copying out the raw memory representation (because it is implementation and platform depenedent)
a text archive might not desire to optimize this (e.g. it has different goals to, like "human readable XML", they might not want to encode your vector<A>
as a large bas64 encoded blob).
Note that this also explains that is_bit_wise_serializable<T>
is not partially specialized for any type that has is_pod<T>::value == true
(This could technically be done easily):
You didn't ask, specifically, but this is what the working implementation would look like:
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/serialization.hpp>
#include <sstream>
struct A { int a; char b;
template <typename Ar> void serialize(Ar& ar, unsigned) {
ar & a;
ar & b;
}
};
BOOST_IS_BITWISE_SERIALIZABLE(A)
int main() {
std::ostringstream oss;
boost::archive::binary_oarchive oa(oss);
A data { 1, 'z' };
oa << data;
}