Boost logo

Boost :

From: christopher diggins (cdiggins_at_[hidden])
Date: 2005-08-10 00:30:00

In the boost::any alternative implementation being developed by Pablo
Aguilar and myself (latest version at ) we have run into a
problem of alignment with no obvious answer.

We are trying to do the following:

struct any
  void* table;
  void* object;


  template<typename T>
  any(const T& x) {
    table = any_detail::get_table<T>::get();
    if (sizeof(T) <= sizeof(void*)) {
      if (new(&object) T(x) != &object) {
        throw runtime_error("can not align the data type ... pigs must be
  else {
    object = new T(x);

The question I have is whether in practice though are there are any
compilers which have stricter alignment requirements on small types (<=
sizeof(void*)) than a void pointer. In other words, is it possible with any
known compiler to actually throw the runtime error ?

Unfortunately there is another problem, I am not an expert in interepreting
the standard, but AFAICT placement new is guaranteed to return a pointer to
properly aligned memory ( / 2) which I leverage to check that
alignment occured. Apparently not every STL implementation does in fact do
that (I believe at least dinkumware is guilty of that).

Thanks in advance for your help!

Christopher Diggins

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