Boost logo

Boost :

From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-09-02 18:15:23

I see that there is some special code in type_with_alignment for Borland C++,
partly because it is broken and partly because we can do a better job using
compiler-specific features.

Why not do the same for other compilers? For instance, on GCC:

template<typename T>
  struct alignment_of
  { BOOST_STATIC_CONSTANT(std::size_t, value = __alignof__(T)); };


template<std::size_t Align>
  struct type_with_alignment
  { struct __attribute__((__aligned__)) type {}; };

template<> struct type_with_alignment<1>
  { struct __attribute__((__aligned__(1))) type {}; };
template<> struct type_with_alignment<2>
  { struct __attribute__((__aligned__(2))) type {}; };
template<> struct type_with_alignment<4>
  { struct __attribute__((__aligned__(4))) type {}; };
template<> struct type_with_alignment<8>
  { struct __attribute__((__aligned__(8))) type {}; };
template<> struct type_with_alignment<16>
  { struct __attribute__((__aligned__(16))) type {}; };
template<> struct type_with_alignment<32>
  { struct __attribute__((__aligned__(32))) type {}; };

It'll reduce the compile time for this platform and give us exact answers. The
only concern I can see is that we might miss some important alignment number
(say, 17); we could avert this problem by creating everything from 1 to 32,
and it would still be much simpler than the current code.

Would anyone object to me making this change for GCC?


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