Boost logo

Boost :

Subject: Re: [boost] [forward_declare] Interest Inquiry toward Faster Compile Times
From: Daniel Larimer (dlarimer_at_[hidden])
Date: 2012-08-02 00:28:25

On Aug 1, 2012, at 11:37 PM, Larry Evans <cppljevans_at_[hidden]> wrote:

> On 08/01/12 20:18, Daniel Larimer wrote:
>> Julien,
>> An extra 'byte' was just left over from me testing. It works with 8
>> bytes (2 ints) and it asserts on 7 bytes. I was trying to find a
>> way to 'warn' if you reserved too much. It looks like
>> BOOST_STATIC_WARN() has been removed.
>> I thought about alignment issues (I am no expert here), but my
>> understanding is that structs/classes are always 'aligned' in the
>> same manner regardless of what is stored. Therefore, if my fwd<>
>> class only has one data member (an array) it should be aligned
>> appropriately for any type.
> I'm pretty sure that you're array, char fwd<T,S>::_store[S], has an
> alignment of 1; thus, If T is double, it would not be aligned properly.
> You need to use an aligned buffer, which boost provides and is also in
> the standard someplace. boost::variant uses the boost aligned buffer
> for its storage buffer.

Yes, _store[S] has an alignment requirement of 1, but what is the alignment requirement for fwd<T,S>?

Can we assume that this == &_store[0] ?

Could we not just do 'reinterpret_cast<test*>(this)'?

template<typename T, int S>
struct fwd {
        fwd() {
                static_assert( sizeof(*this) >= sizeof(T) );
                new (this) T();
        char _store[S];

> HTH.
> -regards,
> Larry
> _______________________________________________
> Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at