[flang] [unittests] Link to libMLIR in optimizer tests (#123476)
[llvm-project.git] / libcxx / test / std / containers / sequences / vector / vector.cons / copy_alloc.pass.cpp
blob0c03c50aed2e8b314f9a554226ff5e2f42150078
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 //===----------------------------------------------------------------------===//
9 // <vector>
11 // vector(const vector& v, const allocator_type& a);
13 #include <vector>
14 #include <cassert>
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
19 #include "asan_testing.h"
21 template <class C>
22 TEST_CONSTEXPR_CXX20 void
23 test(const C& x, const typename C::allocator_type& a)
25 typename C::size_type s = x.size();
26 C c(x, a);
27 LIBCPP_ASSERT(c.__invariants());
28 assert(c.size() == s);
29 assert(c == x);
30 LIBCPP_ASSERT(is_contiguous_container_asan_correct(c));
33 TEST_CONSTEXPR_CXX20 bool tests() {
35 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
36 int* an = a + sizeof(a)/sizeof(a[0]);
37 test(std::vector<int>(a, an), std::allocator<int>());
40 std::vector<int, test_allocator<int> > l(3, 2, test_allocator<int>(5));
41 std::vector<int, test_allocator<int> > l2(l, test_allocator<int>(3));
42 assert(l2 == l);
43 assert(l2.get_allocator() == test_allocator<int>(3));
46 std::vector<int, other_allocator<int> > l(3, 2, other_allocator<int>(5));
47 std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3));
48 assert(l2 == l);
49 assert(l2.get_allocator() == other_allocator<int>(3));
52 // Test copy ctor with allocator and empty source
53 std::vector<int, other_allocator<int> > l(other_allocator<int>(5));
54 std::vector<int, other_allocator<int> > l2(l, other_allocator<int>(3));
55 assert(l2 == l);
56 assert(l2.get_allocator() == other_allocator<int>(3));
57 assert(l2.empty());
59 #if TEST_STD_VER >= 11
61 int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
62 int* an = a + sizeof(a)/sizeof(a[0]);
63 test(std::vector<int, min_allocator<int>>(a, an), min_allocator<int>());
64 test(std::vector<int, safe_allocator<int>>(a, an), safe_allocator<int>());
67 std::vector<int, min_allocator<int> > l(3, 2, min_allocator<int>());
68 std::vector<int, min_allocator<int> > l2(l, min_allocator<int>());
69 assert(l2 == l);
70 assert(l2.get_allocator() == min_allocator<int>());
73 std::vector<int, safe_allocator<int> > l(3, 2, safe_allocator<int>());
74 std::vector<int, safe_allocator<int> > l2(l, safe_allocator<int>());
75 assert(l2 == l);
76 assert(l2.get_allocator() == safe_allocator<int>());
78 #endif
80 return true;
83 int main(int, char**)
85 tests();
86 #if TEST_STD_VER > 17
87 static_assert(tests());
88 #endif
89 return 0;