1 //===----------------------------------------------------------------------===// 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 // REQUIRES: c++experimental 11 // UNSUPPORTED: c++98, c++03 12 13 // <experimental/memory_resource> 14 15 // template <class T> class polymorphic_allocator 16 17 // T* polymorphic_allocator<T>::deallocate(T*, size_t size) 18 19 #include <experimental/memory_resource> 20 #include <type_traits> 21 #include <cassert> 22 23 #include "test_memory_resource.hpp" 24 25 namespace ex = std::experimental::pmr; 26 27 template <size_t S, size_t Align> 28 void testForSizeAndAlign() { 29 using T = typename std::aligned_storage<S, Align>::type; 30 31 TestResource R; 32 ex::polymorphic_allocator<T> a(&R); 33 34 for (int N = 1; N <= 5; ++N) { 35 auto ret = a.allocate(N); 36 assert(R.checkAlloc(ret, N * sizeof(T), alignof(T))); 37 38 a.deallocate(ret, N); 39 assert(R.checkDealloc(ret, N * sizeof(T), alignof(T))); 40 41 R.reset(); 42 } 43 } 44 45 int main() 46 { 47 { 48 ex::polymorphic_allocator<int> a; 49 static_assert( 50 std::is_same<decltype(a.deallocate(nullptr, 0)), void>::value, ""); 51 } 52 { 53 constexpr std::size_t MA = alignof(std::max_align_t); 54 testForSizeAndAlign<1, 1>(); 55 testForSizeAndAlign<1, 2>(); 56 testForSizeAndAlign<1, MA>(); 57 testForSizeAndAlign<2, 2>(); 58 testForSizeAndAlign<73, alignof(void*)>(); 59 testForSizeAndAlign<73, MA>(); 60 testForSizeAndAlign<13, MA>(); 61 } 62 } 63