blob: 6a1d85e2677b4f9d97bcd3dc680aa4bd93807206 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. 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
Howard Hinnante92c3d72010-08-19 18:39:17 +000019#include <scoped_allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020#include <cassert>
21
22#include "../allocators.h"
23
24int main()
25{
Howard Hinnant73d21a42010-09-04 23:28:19 +000026#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000027
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
Howard Hinnant73d21a42010-09-04 23:28:19 +0000111#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000112}