blob: 001c6894b873a773a29705dadc560f81daf84197 [file] [log] [blame]
Dan Albert287553d2017-02-16 10:47:51 -08001//===----------------------------------------------------------------------===//
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// EXTENSION
17// std::size_t polymorphic_allocator<T>::max_size() const noexcept
18
19#include <experimental/memory_resource>
20#include <type_traits>
21#include <cassert>
22
23#include "test_memory_resource.hpp"
24
25namespace ex = std::experimental::pmr;
26
27template <std::size_t S>
28std::size_t getMaxSize() {
29 using T = typename std::aligned_storage<S>::type;
30 static_assert(sizeof(T) == S, "Required for test");
31 return ex::polymorphic_allocator<T>{}.max_size();
32}
33
34template <std::size_t S, std::size_t A>
35std::size_t getMaxSize() {
36 using T = typename std::aligned_storage<S, A>::type;
37 static_assert(sizeof(T) == S, "Required for test");
38 return ex::polymorphic_allocator<T>{}.max_size();
39}
40
41int main()
42{
43 {
44 using Alloc = ex::polymorphic_allocator<int>;
45 using Traits = std::allocator_traits<Alloc>;
46 const Alloc a;
47 static_assert(std::is_same<decltype(a.max_size()), Traits::size_type>::value, "");
48 static_assert(noexcept(a.max_size()), "");
49 }
50 {
51 constexpr std::size_t Max = std::numeric_limits<std::size_t>::max();
52 assert(getMaxSize<1>() == Max);
53 assert(getMaxSize<2>() == Max / 2);
54 assert(getMaxSize<4>() == Max / 4);
55 assert(getMaxSize<8>() == Max / 8);
56 assert(getMaxSize<16>() == Max / 16);
57 assert(getMaxSize<32>() == Max / 32);
58 assert(getMaxSize<64>() == Max / 64);
59 assert(getMaxSize<1024>() == Max / 1024);
60
61 assert((getMaxSize<6, 2>() == Max / 6));
62 assert((getMaxSize<12, 4>() == Max / 12));
63 }
64}