1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // UNSUPPORTED: c++03 |
10 | |
11 | // <memory> |
12 | |
13 | // template <class OuterAlloc, class... InnerAllocs> |
14 | // class scoped_allocator_adaptor |
15 | |
16 | // template <class T> void destroy(T* p); |
17 | |
18 | #include <scoped_allocator> |
19 | #include <cassert> |
20 | #include <string> |
21 | |
22 | #include "test_macros.h" |
23 | #include "allocators.h" |
24 | |
25 | struct B { |
26 | static bool constructed; |
27 | |
28 | B() { constructed = true; } |
29 | ~B() { constructed = false; } |
30 | }; |
31 | |
32 | bool B::constructed = false; |
33 | |
34 | int main(int, char**) { |
35 | { |
36 | typedef std::scoped_allocator_adaptor<A1<B>> A; |
37 | A a; |
38 | char buf[100]; |
39 | typedef B S; |
40 | S* s = (S*)buf; |
41 | assert(!S::constructed); |
42 | a.construct(s); |
43 | assert(S::constructed); |
44 | a.destroy(s); |
45 | assert(!S::constructed); |
46 | } |
47 | |
48 | { |
49 | typedef std::scoped_allocator_adaptor<A3<B>, A1<B>> A; |
50 | A a; |
51 | char buf[100]; |
52 | typedef B S; |
53 | S* s = (S*)buf; |
54 | assert(!S::constructed); |
55 | assert(!A3<S>::constructed); |
56 | assert(!A3<S>::destroy_called); |
57 | a.construct(s); |
58 | assert(S::constructed); |
59 | assert(A3<S>::constructed); |
60 | assert(!A3<S>::destroy_called); |
61 | a.destroy(s); |
62 | assert(!S::constructed); |
63 | assert(A3<S>::constructed); |
64 | assert(A3<S>::destroy_called); |
65 | } |
66 | |
67 | return 0; |
68 | } |
69 | |