Boost logo

Boost :

From: Douglas Paul Gregor (gregod_at_[hidden])
Date: 2002-03-27 14:36:09


On Wed, 27 Mar 2002, Ralf W. Grosse-Kunstleve wrote:

> Currently I am using code from Andrei Alexandrescu for computing
> proper alignments for a fixed-capacity array type (see URL below).
> Here is the hook that I am using (in auto_allocator.h):
>
> template <typename T, std::size_t N>
> union auto_allocator {
> char buffer[N * sizeof(T)];
> typename cctbx::af::alignment_calculator::AlignmentCalculator<
> CCTBX_AF_TYPELIST1(T)>::Result dummy_;
> };
>
> And then (in small_plain.h):
>
> detail::auto_allocator<ElementType, N> m_elems;
>
> Could I use type_with_alignment to achieve the same?
>
> Does type_with_alignment or any other code that I would need
> for the auto_allocator depend on mpl?
>
> Thanks,
> Ralf

Yes, you can use type_with_alignment. Then auto_allocator would look like
this:

template<typename T, std::size_t N>
union auto_allocator {
  char buffer[N*sizeof(T)];
  typename boost::type_with_alignment<boost::alignment_of<T>::value>::type
    dummy_;
};

The type_with_alignment code does not use MPL - it uses the Boost
Preprocessor library only.

        Doug


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