blob: b631f6eaaad72a23d1ecf8d34117d8365fd0ca6f [file] [log] [blame]
Eric Fiselier257fd692016-05-07 01:04:55 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// UNSUPPORTED: c++98, c++03
11
12// <experimental/memory_resource>
13
14// template <class T> class polymorphic_allocator
15
16// T* polymorphic_allocator<T>::deallocate(T*, size_t size)
17
18#include <experimental/memory_resource>
19#include <type_traits>
20#include <cassert>
21
22#include "test_memory_resource.hpp"
23
24namespace ex = std::experimental::pmr;
25
26template <size_t S, size_t Align>
27void testForSizeAndAlign() {
28 using T = typename std::aligned_storage<S, Align>::type;
29
30 TestResource R;
31 ex::polymorphic_allocator<T> a(&R);
32
33 for (int N = 1; N <= 5; ++N) {
34 auto ret = a.allocate(N);
35 assert(R.checkAlloc(ret, N * sizeof(T), alignof(T)));
36
37 a.deallocate(ret, N);
38 assert(R.checkDealloc(ret, N * sizeof(T), alignof(T)));
39
40 R.reset();
41 }
42}
43
44int main()
45{
46 {
47 ex::polymorphic_allocator<int> a;
48 static_assert(
49 std::is_same<decltype(a.deallocate(nullptr, 0)), void>::value, "");
50 }
51 {
52 constexpr std::size_t MA = alignof(std::max_align_t);
53 testForSizeAndAlign<1, 1>();
54 testForSizeAndAlign<1, 2>();
55 testForSizeAndAlign<1, MA>();
56 testForSizeAndAlign<2, 2>();
57 testForSizeAndAlign<73, alignof(void*)>();
58 testForSizeAndAlign<73, MA>();
59 testForSizeAndAlign<13, MA>();
60 }
61}