Reading Struct not Located at Four-boundary

L

Larry Evans

On 08/28/10 12:48, Gennaro Prota wrote:
[snip]
So, one thing that I'd be glad to have now is a way to tell if
two types have the same alignment (meant as *minimum*
alignment), without necessarily knowing what the alignment is.
If you know of any technique to do this please voice your voice
:)

A few years ago, I had a look at boost::variant which uses (IIRC)
boost::type_traits::aligned_storage. IIRC, somewhere in the code
there was a list of all fundamental types and their alignments
and I think those alignments were compared to.... Oh now I don't
know. All I can suggest is too see how boost variant does it.
Besides that, there's also a completely different approach which
has been wandering though my mind for a while. But I won't make
my ruminations public until I've some feeling that they may
really work.

I'd be interested in seeing that when you feel it may really work.

BTW, what I found interesting is both:
variant<T1,T2,...,Tn>
and:
tuple<T1,T2,...,Tn>
when implemented using a aligned_storage<Size,Align>,
can use the same Align argument. At least that's the way
it's done here:

http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/composite_storage/pack/

where instead of variant and tuple, the template names are:

container_one_of_maybe
container_all_of_aligned

The reason for the maybe is to allow an uninitialized variant.
That bother me a bit, but then another thread:

http://groups.google.com/group/comp.std.c++/msg/a226f4a643b104ae

suggested a benefit, i.e. if operator= didn't work, then
the variant would revert to the uninitialized state.

-regards,
Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top