]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / memory / allocator.traits / allocator.traits.members / destroy.pass.cpp
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 // <memory>
11
12 // template <class Alloc>
13 // struct allocator_traits
14 // {
15 //     template <class Ptr>
16 //         static void destroy(allocator_type& a, Ptr p);
17 //     ...
18 // };
19
20 #include <memory>
21 #include <new>
22 #include <type_traits>
23 #include <cassert>
24
25 #include "test_macros.h"
26
27 template <class T>
28 struct A
29 {
30     typedef T value_type;
31
32 };
33
34 int b_destroy = 0;
35
36 template <class T>
37 struct B
38 {
39     typedef T value_type;
40
41     template <class U>
42     void destroy(U* p)
43     {
44         ++b_destroy;
45         p->~U();
46     }
47 };
48
49 struct A0
50 {
51     static int count;
52     ~A0() {++count;}
53 };
54
55 int A0::count = 0;
56
57 int main()
58 {
59     {
60         A0::count = 0;
61         A<int> a;
62         std::aligned_storage<sizeof(A0)>::type a0;
63         std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
64         assert(A0::count == 0);
65         std::allocator_traits<A<int> >::destroy(a, (A0*)&a0);
66         assert(A0::count == 1);
67     }
68 #if TEST_STD_VER >= 11
69     {
70         A0::count = 0;
71         b_destroy = 0;
72         B<int> b;
73         std::aligned_storage<sizeof(A0)>::type a0;
74         std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
75         assert(A0::count == 0);
76         assert(b_destroy == 0);
77         std::allocator_traits<B<int> >::destroy(b, (A0*)&a0);
78         assert(A0::count == 1);
79         assert(b_destroy == 1);
80     }
81 #endif
82 }