Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-01-28 14:50:03

From: "Douglas Gregor" <gregod_at_[hidden]>
> On Monday 28 January 2002 02:12 pm, you wrote:
> > > But how would function<> ensure the proper
> > > alignment for the function object type?
> >
> > That shouldn't be hard if we wanted it. After all, we have
> > 'boost::alignment_of', Fernando Cacciola's "aligned_storage.hpp"
> > in the vault, I believe), and Andrei's paper -
> > - seems to provide a
> > solution as well.
> All solutions require knowing all of the types that storage must be
> with in advance. It works quite well for, e.g., a bounded variant class
> as those written by Brian Parker and Andrei Alexandrescu), but any
> variant (such as boost::any or boost::function) won't benefit because they
> don't haven't anything to align with.

The current alignment solutions don't work in their current form, f.ex.
aligned_storage<> needs the type beforehand.

But wouldn't it be possible to implement (using aligned_storage<> as a
starting point)

template<class T> (T|void) * placement_allocate(unsigned char *,

which then could be used by function<>:

operator= (F f)
    if(void * p = placement_allocate<F>(small_string_buffer, 16))
        new(p) F(f);
        // new F(f)

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