David Abrahams wrote:

[...]

> OK, so what you really want is alignment_of<boost::detail::max_align>.

Ah, there it is.  Unions are great for this.

> By "STL" I presume you mean your particular STL implementation.

No I meant SGI's Standard Template Library (__STL_DATA_ALIGNMENT in
pthread_alloc).

[...]

>> Ex.:
>>
>> - The processor aligns each character to 8 bits.
>> - The processor aligns each integer to 32 bits.
>>
>> 0x8000    character
>> 0x8001    padding
>> 0x8002    padding
>> 0x8003    padding
>> 0x8004    integer
>> 0x8005    integer
>> 0x8006    integer
>> 0x8007    integer
>
>     template <class T>
>     struct padding_of
>     {
>         BOOST_STATIC_CONSTANT(
>             std::size_t, value = alignment_of<max_align>::value
>                      - sizeof(T) % alignment_of<T>::value
>         );
>     };
>
> or, if you don't trust max_align, then:
>
>     template <class T>
>     struct padding_of
>     {
>         BOOST_STATIC_CONSTANT(
>             std::size_t, value = alignment_of<max_align>::value
>                      % (sizeof(T) % alignment_of<T>::value)
>         );
>     };

Thanks!



Philippe




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to