xref: /llvm-project/libcxx/test/std/utilities/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp (revision 4d3b502704809c9605b9568c6feb2a2f0ca51907)
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 // scoped_allocator_adaptor(const scoped_allocator_adaptor& other);
17 
18 #include <scoped_allocator>
19 #include <cassert>
20 
21 #include "test_macros.h"
22 #include "allocators.h"
23 
main(int,char **)24 int main(int, char**) {
25   {
26     typedef std::scoped_allocator_adaptor<A1<int>> A;
27     A a1(A1<int>(3));
28     A1<int>::copy_called = false;
29     A1<int>::move_called = false;
30     A a2                 = a1;
31     assert(A1<int>::copy_called == true);
32     assert(A1<int>::move_called == false);
33     assert(a2 == a1);
34   }
35   {
36     typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A;
37     A a1(A1<int>(4), A2<int>(5));
38     A1<int>::copy_called = false;
39     A1<int>::move_called = false;
40     A2<int>::copy_called = false;
41     A2<int>::move_called = false;
42     A a2                 = a1;
43     assert(A1<int>::copy_called == true);
44     assert(A1<int>::move_called == false);
45     assert(A2<int>::copy_called == true);
46     assert(A2<int>::move_called == false);
47     assert(a2 == a1);
48   }
49   {
50     typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A;
51     A a1(A1<int>(4), A2<int>(5), A3<int>(6));
52     A1<int>::copy_called = false;
53     A1<int>::move_called = false;
54     A2<int>::copy_called = false;
55     A2<int>::move_called = false;
56     A3<int>::copy_called = false;
57     A3<int>::move_called = false;
58     A a2                 = a1;
59     assert(A1<int>::copy_called == true);
60     assert(A1<int>::move_called == false);
61     assert(A2<int>::copy_called == true);
62     assert(A2<int>::move_called == false);
63     assert(A3<int>::copy_called == true);
64     assert(A3<int>::move_called == false);
65     assert(a2 == a1);
66   }
67 
68   return 0;
69 }
70