xref: /llvm-project/libcxx/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp (revision 10ec9276d40024c23a481e6671dad1521151dd85)
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 // <deque>
10 
11 // deque(const deque&);
12 
13 #include "asan_testing.h"
14 #include <deque>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "min_allocator.h"
20 
21 template <class C>
22 void
test(const C & x)23 test(const C& x)
24 {
25     C c(x);
26     assert(c == x);
27     LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
28     LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(x));
29 }
30 
main(int,char **)31 int main(int, char**)
32 {
33     {
34         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
35         int* an = ab + sizeof(ab)/sizeof(ab[0]);
36         test(std::deque<int>(ab, an));
37     }
38     {
39         std::deque<int, test_allocator<int> > v(3, 2, test_allocator<int>(5));
40         std::deque<int, test_allocator<int> > v2 = v;
41         assert(v2 == v);
42         assert(v2.get_allocator() == v.get_allocator());
43         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v));
44         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v2));
45     }
46 #if TEST_STD_VER >= 11
47     {
48         std::deque<int, other_allocator<int> > v(3, 2, other_allocator<int>(5));
49         std::deque<int, other_allocator<int> > v2 = v;
50         assert(v2 == v);
51         assert(v2.get_allocator() == other_allocator<int>(-2));
52         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v));
53         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v2));
54     }
55     {
56         int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45};
57         int* an = ab + sizeof(ab)/sizeof(ab[0]);
58         test(std::deque<int, min_allocator<int>>(ab, an));
59     }
60     {
61         std::deque<int, min_allocator<int> > v(3, 2, min_allocator<int>());
62         std::deque<int, min_allocator<int> > v2 = v;
63         assert(v2 == v);
64         assert(v2.get_allocator() == v.get_allocator());
65         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v));
66         LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(v2));
67     }
68 #endif
69 
70   return 0;
71 }
72