Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2003-02-11 01:08:43


Hi again,

    I am doing some helper class that will pad the space after a given type
until it reaches a machine word boundary. This word boundary would be the
maximum of (alignment_of<T>::value - sizeof(char)) where T is any
'typename', 'typename' is one of {is_class<U>::value == false} and U is any
type.

    I would like some help to isolate the most effective way to define
BOOST_DATA_ALIGNMENT in the following example (defined by default to 8 --
based on std headers).

    I would like to propose padding_of<> at the same time.

template <typename T>
    struct padding_of
    {
        size_t const BOOST_DATA_ALIGNMENT = 8;

        size_t const value = (BOOST_DATA_ALIGNMENT - sizeof(T) %
BOOST_DATA_ALIGNMENT) % BOOST_DATA_ALIGNMENT;
    };

template <typename T>
    struct padded
    {
        T type;
        char padding[padding_of<T>::value]; // can be of size 0!
    };

template <typename T>
    struct shifted_object : padded<counted_base>
    {
        T value;
    };

Thanks,

Philippe A. Bouchard


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