blob: acec1a02def0475096bc482dc5accdc367da8150 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: c++experimental
// UNSUPPORTED: c++98, c++03
// <experimental/memory_resource>
// template <class T> class polymorphic_allocator
// polymorphic_allocator<T>::polymorphic_allocator() noexcept
#include <experimental/memory_resource>
#include <type_traits>
#include <cassert>
#include "test_memory_resource.hpp"
namespace ex = std::experimental::pmr;
int main()
{
{
static_assert(
std::is_nothrow_default_constructible<ex::polymorphic_allocator<void>>::value
, "Must me nothrow default constructible"
);
}
{
// test that the allocator gets its resource from get_default_resource
TestResource R1(42);
ex::set_default_resource(&R1);
typedef ex::polymorphic_allocator<void> A;
A const a;
assert(a.resource() == &R1);
ex::set_default_resource(nullptr);
A const a2;
assert(a.resource() == &R1);
assert(a2.resource() == ex::new_delete_resource());
}
}
|