blob: 1007556a48578ec35d2036ad1575123bc4a0c232 [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// polymorphic_allocator<T>::polymorphic_allocator() noexcept
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
26int main()
27{
28 {
29 static_assert(
30 std::is_nothrow_default_constructible<ex::polymorphic_allocator<void>>::value
31 , "Must me nothrow default constructible"
32 );
33 }
34 {
35 // test that the allocator gets its resource from get_default_resource
36 TestResource R1(42);
37 ex::set_default_resource(&R1);
38
39 typedef ex::polymorphic_allocator<void> A;
40 A const a;
41 assert(a.resource() == &R1);
42
43 ex::set_default_resource(nullptr);
44 A const a2;
45 assert(a.resource() == &R1);
46 assert(a2.resource() == ex::new_delete_resource());
47 }
48}