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 OuterAlloc, class... InnerAllocs>
13 //   class scoped_allocator_adaptor
14 
15 // template <class OuterA2>
16 //   scoped_allocator_adaptor(OuterA2&& outerAlloc,
17 //                            const InnerAllocs& ...innerAllocs);
18 
19 #include <scoped_allocator>
20 #include <cassert>
21 
22 #include "allocators.h"
23 
main()24 int main()
25 {
26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
27 
28     {
29         typedef std::scoped_allocator_adaptor<A1<int>> A;
30         A1<int> a3(3);
31         A a(a3);
32         assert(a.outer_allocator() == A1<int>(3));
33         assert(a.inner_allocator() == a);
34         assert(A1<int>::copy_called == true);
35         assert(A1<int>::move_called == false);
36     }
37     A1<int>::copy_called = false;
38     {
39         typedef std::scoped_allocator_adaptor<A1<int>> A;
40         A a(A1<int>(3));
41         assert(a.outer_allocator() == A1<int>(3));
42         assert(a.inner_allocator() == a);
43         assert(A1<int>::copy_called == false);
44         assert(A1<int>::move_called == true);
45     }
46     A1<int>::move_called = false;
47     {
48         typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
49         A1<int> a4(4);
50         A a(a4, A2<int>(5));
51         assert(A1<int>::copy_called == true);
52         assert(A1<int>::move_called == false);
53         assert(A2<int>::copy_called == true);
54         assert(A2<int>::move_called == false);
55         assert(a.outer_allocator() == A1<int>(4));
56         assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(5)));
57     }
58     A1<int>::copy_called = false;
59     A1<int>::move_called = false;
60     A2<int>::copy_called = false;
61     A2<int>::move_called = false;
62     {
63         typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
64         A a(A1<int>(4), A2<int>(5));
65         assert(A1<int>::copy_called == false);
66         assert(A1<int>::move_called == true);
67         assert(A2<int>::copy_called == true);
68         assert(A2<int>::move_called == false);
69         assert(a.outer_allocator() == A1<int>(4));
70         assert(a.inner_allocator() == std::scoped_allocator_adaptor<A2<int>>(A2<int>(5)));
71     }
72     A1<int>::copy_called = false;
73     A1<int>::move_called = false;
74     A2<int>::copy_called = false;
75     A2<int>::move_called = false;
76     A1<int>::move_called = false;
77     {
78         typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
79         A1<int> a4(4);
80         A a(a4, A2<int>(5), A3<int>(6));
81         assert(A1<int>::copy_called == true);
82         assert(A1<int>::move_called == false);
83         assert(A2<int>::copy_called == true);
84         assert(A2<int>::move_called == false);
85         assert(A3<int>::copy_called == true);
86         assert(A3<int>::move_called == false);
87         assert(a.outer_allocator() == A1<int>(4));
88         assert((a.inner_allocator() ==
89             std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6))));
90     }
91     A1<int>::copy_called = false;
92     A1<int>::move_called = false;
93     A2<int>::copy_called = false;
94     A2<int>::move_called = false;
95     A3<int>::copy_called = false;
96     A3<int>::move_called = false;
97     {
98         typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
99         A a(A1<int>(4), A2<int>(5), A3<int>(6));
100         assert(A1<int>::copy_called == false);
101         assert(A1<int>::move_called == true);
102         assert(A2<int>::copy_called == true);
103         assert(A2<int>::move_called == false);
104         assert(A3<int>::copy_called == true);
105         assert(A3<int>::move_called == false);
106         assert(a.outer_allocator() == A1<int>(4));
107         assert((a.inner_allocator() ==
108             std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6))));
109     }
110 
111 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
112 }
113