Boost logo

Boost :

Subject: [boost] Serialisation: Is is_trivial<T> a sufficient precondition to bypass serialisation?
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2015-02-04 06:54:56


A library user has raised an interesting question at:

https://github.com/BoostGSoC13/boost.afio/commit/ac32ebfceb9a08b133e8c
d47000d3b4807bc3e42#commitcomment-9574522

Basically, AFIO v1.3 has new pre-serialisation metaprogramming in
response to Robert's comments on his Incubator about it being too
hard to serialise and deserialise data with AFIO. AFIO will now
consume any STL container and will implicitly auto expand to ASIO
scatter gather buffers any:

1. Trivial type T
2. C array of trivial type T
3. STL container of trivial type T, including initializer_list.

A free function, to_asio_buffers(T), can be specialised by external
code to extend this with custom ASIO scatter gather buffers
generation. Note that AFIO explicitly and intentionally expects that
anyone interested in async file i/o will be doing their serialisation
and endian conversion far away from AFIO code, so to_asio_buffers(T)
is really for marking extra types to be treated as implicit auto
expand.

The user asks the question: Is is_trivial<T> a sufficient
precondition for this auto expansion to be safe, or should
is_standard_layout<T> also be required? The user notes that
is_trivial<T> && is_standard_layout<T> == is_pod<T> which seems a
little overkill to me.

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

Niall

-- 
ned Productions Limited Consulting
http://www.nedproductions.biz/ 
http://ie.linkedin.com/in/nialldouglas/



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