|
Boost : |
From: Andrei Alexandrescu (andrewalex_at_[hidden])
Date: 2002-01-28 15:16:39
> > That shouldn't be hard if we wanted it. After all, we have
> > 'boost::alignment_of', Fernando Cacciola's "aligned_storage.hpp"
(somewhere
> > in the vault, I believe), and Andrei's paper -
> > http://www.oonumerics.org/tmpw01/alexandrescu.pdf - seems to provide a
> > solution as well.
>
> All solutions require knowing all of the types that storage must be
aligned
> with in advance. It works quite well for, e.g., a bounded variant class
(such
> as those written by Brian Parker and Andrei Alexandrescu), but any
unbounded
> variant (such as boost::any or boost::function) won't benefit because they
> don't haven't anything to align with.
My solution is not based on knowing the types in advance. It just uses that
information to optimize the storage size. The TypesOfAllAlignments type in
the paper can be arguably quite a portable storage for any type. The code is
not 100% portable, but in practice it's hard to imagine a system that's as
perverse as to break its assumptions.
Just a quick remark, I just can't hold it - aligned_storage.hpp in the files
section defines and uses a little typelist and int2type, type2type, and
select (some with changed names). A good argument for making them
first-class citizens of the library...
Andrei
---------------------------------
Check out THE C++ Seminar: 3 Days with 5 Experts
http://www.gotw.ca/cpp_seminar/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk