Subject: Re: [boost] Review request for Boost.Align
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-02-20 04:55:43
On Thu, Feb 20, 2014 at 1:21 PM, Glen Fernandes
>> Can this class be extended so that I can specify the alignment
>> explicitly in the template parameters?
> Definitely. Instead of specifying the alignment value as a template
> parameter, maybe a preferable design is:
> template<class T, template<class> class A = boost::alignment_of>
> class aligned_allocator;
> ...where 'A' could supply different alignment values for different
> rebound types.
I think it complicates things too much. For example, if I just want to
align memory at cache line boundary (64 bytes for Intel CPUs), I would
have to create a metafunction just to provide this single constant to
I can understand why you would want to use a metafunction here - you
want rebound allocator to use the proper alignment. But realistically,
no one ever wants to align memory weaker than malloc/new, and it is
already guaranteed to align properly for any builtin types. So you
would specify a stronger alignment than malloc/new provides, which
means it should already be strong enough for any T. That's why I think
a simple constant would be enough.
template< typename T, unsigned int Alignment = 0 >
static constexpr unsigned int alignment = Alignment > 0 ?
Alignment : alignment_of< T >::value;
static_assert(alignment >= alignment_of< T >::value, "Specified
alignment is too weak");
But if you decide to go with the metafunction, then at least provide a
boilerplate so that it is easy to specify a constant.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk