5

C++17 introduces std::aligned_alloc and alignment-aware new that can do over-aligned allocations, but what about std::allocator? Does it handle over-aligned types?

3
  • oops, I deleted my wrong answer , a copy-paste horror story ... ( feel free to down vote me ... :) ) Commented Sep 25, 2017 at 7:56
  • 1
    Yes, open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0035r4.html removed the text making it implementation defined. Commented Sep 25, 2017 at 8:01
  • @MassimilianoJanes Never mind, I've found the section in N4659(C++17 DIS). Commented Sep 25, 2017 at 8:03

1 Answer 1

7

In N4659(C++17 DIS), 23.10.9.1 [allocator.members], bullet 2

T* allocate(size_t n);

Returns: A pointer to the initial element of an array of storage of size n * sizeof(T), aligned appropriately for objects of type T.

Compared to C++14, the sentence

It is implementation-defined whether over-aligned types are supported

has been removed. So std::allocator should support over-aligned types in C++17.

Sign up to request clarification or add additional context in comments.

5 Comments

uhm, N4659 ( the pdf version I found at www.open-std.org ) still reads verbatim as per my original answer, that is that overaligned types support is implementation defined ...
@MassimilianoJanes I found it at github.com/timsong-cpp/cppwp, not sure the one at www.open-std.org.
ok reading Marc Glisse's comment is clear you're right ( good to know that the allocation functions takes also an alignment parameter now ).
Could you click accept this answer? This is very why aligned_allocator is not longer neccessary.
@Jamboree This is great. Thanks for digging this up.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.