C++ Logo

SG10

Advanced search

Subject: Re: [SG10] Over-aligned dynamic allocation
From: Jason Merrill (jason_at_[hidden])
Date: 2016-07-18 11:35:08


On Wed, Jun 22, 2016 at 1:07 AM, Daniel Krügler
<daniel.kruegler_at_[hidden]> wrote:
> 2016-06-22 6:04 GMT+02:00 Nelson, Clark <clark.nelson_at_[hidden]>:
>>> I can imagine that the macro would also be used by people who
>>> replace the global operator new, and who would also replace the
>>> aligned version if it were present.
>>
>> That's a good point. It would also serve to indicate whether
>> "std::align_val_t" were available as a type name.
>>
>> Would anyone else like to weigh in in one direction or the other?

I think we definitely want some macro for users to be able to check; I
don't feel strongly about having a feature test macro in addition to
the STDCPP macro.

I've previously written

template <class T, class...Args>
T* aligned_new(Args&&... args)
{
  void *p = aligned_alloc (alignof (T), sizeof (T));
  return new (p) T(std::forward<Args>(args)...);
}

and I can avoid the use of C11 aligned_alloc when C++17 aligned new is
available.

Jason


SG10 list run by sg10-owner@lists.isocpp.org