Boost logo

Boost :

Subject: Re: [boost] type_with_alignment.hpp / alignment_of.hpp too heavy
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2008-10-07 15:33:40


David Abrahams wrote:
> on Thu Oct 02 2008, "Christian Holmquist" <c.holmquist-AT-gmail.com> wrote:
>> 2008/10/1 Emil Dotchevski <emil_at_[hidden]>
>>
>>> So, at least I need to include alignment_of.hpp which is so heavy it
>>> practically nullifies my efforts to pimpl the U type away in the cpp.
>>
>> Have a look at boost/intrusive/detail/mpl.hpp, there's a alignment_of with
>> the following comment
>
> I would prefer to fix this dependency problem. AFAICT it only exists
> for VC6/7 support of mpl lambda expressions with boost type traits. Is
> this the only trait that exhibits that level of dependency?

I agree fixing alignment_of is the way to go and type_traits utilities
need some work to simplify dependencies. For Intrusive I wanted to
minimize nearly all external dependencies so I just took alignment_of
code and simplified it. This simple code should work for most compilers:

#include <cstddef>

template <typename T> struct alignment_of;

template <typename T>
struct alignment_of_hack
{
     char c;
     T t;
     alignment_of_hack();
};

template <unsigned A, unsigned S>
struct alignment_logic
{
    static const std::size_t value = A < S ? A : S;
};

template< typename T >
struct alignment_of
{
    static const std::size_t value = alignment_logic
             < sizeof(alignment_of_hack<T>) - sizeof(T)
             , sizeof(T)
>::value;
};

I don't think we need to include <boost/config.hpp> (which includes some
std header to detect std library configuration).

Regards,

Ion


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