Boost logo

Boost :

Subject: Re: [boost] Serialisation: Is is_trivial<T> a sufficient precondition to bypass serialisation?
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2015-02-04 12:02:24


2015-02-04 15:54 GMT+04:00 Niall Douglas <s_sourceforge_at_[hidden]>:

> There is also the possibility that is_trivial<T> is too conservative.
> Some may argue that is_trivially_copyable<T> would be sufficient.
> Thoughts?
>

There could be problems with alignment if a serialized data will be
deserialized by other compiler. For example:

struct A { int i, char c; };
struct B : public A { char c2[3]; int i2; };

Here structure B would be serialized differently by different compilers.
sizeof(B) == 12 on GCC, some of the MSVC give 16. is_trivial<B> and
is_trivially_copyable<B> would not be sufficient for that case.
is_standard_layout<B> is required here.

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk