Jamboree
Jamboree

Reputation: 5309

Does std::allocator handle over-aligned types in C++17?

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?

Upvotes: 5

Views: 1173

Answers (1)

Jamboree
Jamboree

Reputation: 5309

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.

Upvotes: 7

Related Questions