blob: f117bf08dcb849ce9b97d1a04e96f38d16eb2f42 [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// template <class U>
17// void polymorphic_allocator<T>::destroy(U * ptr);
18
19#include <experimental/memory_resource>
20#include <type_traits>
21#include <new>
22#include <cassert>
23#include <cstdlib>
24
25namespace ex = std::experimental::pmr;
26
27int count = 0;
28
29struct destroyable
30{
31 destroyable() { ++count; }
32 ~destroyable() { --count; }
33};
34
35int main()
36{
37 typedef ex::polymorphic_allocator<double> A;
38 {
39 A a;
40 static_assert(
41 std::is_same<decltype(a.destroy((destroyable*)nullptr)), void>::value,
42 "");
43 }
44 {
45 destroyable * ptr = ::new (std::malloc(sizeof(destroyable))) destroyable();
46 assert(count == 1);
47 A{}.destroy(ptr);
48 assert(count == 0);
49 std::free(ptr);
50 }
51}