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