Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-03-01 11:01:35


----- Original Message -----
From: "Douglas Gregor" <gregod_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, March 01, 2002 12:31 PM
Subject: Re: [boost] Re: New version of valunion and stack_allocator
uploaded

> On Friday 01 March 2002 10:16 am, you wrote:
> > > template<typename T, size_t sz, size_t align>
> > > struct member {
> > > typedef typename ct_if<sizeof(T) <= sz && sizeof(U) <=
align,
> >
> > What is 'U'?
>
> My typo :(. It was supposed to be T.
>
> > > T,
> > > char>::type type;
> > > };
> > >
> > > template<size_t sz, size_t align>
> > > union force_align {
> >
> > What are 'sz' and 'align'?
>
> The size and alignment of the type for which we want an alignment type.
E.g.,
> if we need to create aligned storage for std::string, we could use:
>
> union std_string_raw_storage {
> force_align<sizeof(std::string), alignment_of<std::string>::value>::type
> align1;
>
> char buffer[sizeof(std::string)];
> };
>
In the files section, there is a header

http://groups.yahoo.com/group/boost/files/class_optional/aligned_storage.hpp

which provides a convenient interface (IMO) for this feature.
I believe it combines perfectly with Brian's force_align<> and
alignment_of<>
(it just adds a high-level user-friendly interface)

BTW, latest Brian's sources are in:

http://groups.yahoo.com/group/boost/files/align_of_to_boost.zip

Additionally, I haven't yet read it, but it would be relevant to look at the
recent Andrei's expert column:

Generic<Programming>: Discriminated Unions (I)
http://www.cuj.com/experts/2004/alexandr.htm

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


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