15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier
95a83710eSEric Fiselier // <vector>
105a83710eSEric Fiselier // vector<bool>
115a83710eSEric Fiselier
125a83710eSEric Fiselier // vector(const vector& v);
135a83710eSEric Fiselier
145a83710eSEric Fiselier #include <vector>
155a83710eSEric Fiselier #include <cassert>
161f4231f8SEric Fiselier
171f4231f8SEric Fiselier #include "test_macros.h"
185a83710eSEric Fiselier #include "test_allocator.h"
195a83710eSEric Fiselier #include "min_allocator.h"
205a83710eSEric Fiselier
215a83710eSEric Fiselier template <class C>
test(const C & x)22*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 void test(const C& x)
235a83710eSEric Fiselier {
24d4b83e6dSStephan T. Lavavej typename C::size_type s = x.size();
255a83710eSEric Fiselier C c(x);
261f4231f8SEric Fiselier LIBCPP_ASSERT(c.__invariants());
275a83710eSEric Fiselier assert(c.size() == s);
285a83710eSEric Fiselier assert(c == x);
295a83710eSEric Fiselier }
305a83710eSEric Fiselier
tests()31*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 bool tests()
325a83710eSEric Fiselier {
335a83710eSEric Fiselier {
345a83710eSEric Fiselier bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
355a83710eSEric Fiselier bool* an = a + sizeof(a)/sizeof(a[0]);
365a83710eSEric Fiselier test(std::vector<bool>(a, an));
375a83710eSEric Fiselier }
385a83710eSEric Fiselier {
39f81cfbabSEric Fiselier std::vector<bool, test_allocator<bool> > v(3, true, test_allocator<bool>(5));
405a83710eSEric Fiselier std::vector<bool, test_allocator<bool> > v2 = v;
415a83710eSEric Fiselier assert(v2 == v);
425a83710eSEric Fiselier assert(v2.get_allocator() == v.get_allocator());
435a83710eSEric Fiselier }
441f4231f8SEric Fiselier #if TEST_STD_VER >= 11
455a83710eSEric Fiselier {
46f81cfbabSEric Fiselier std::vector<bool, other_allocator<bool> > v(3, true, other_allocator<bool>(5));
475a83710eSEric Fiselier std::vector<bool, other_allocator<bool> > v2 = v;
485a83710eSEric Fiselier assert(v2 == v);
495a83710eSEric Fiselier assert(v2.get_allocator() == other_allocator<bool>(-2));
505a83710eSEric Fiselier }
515a83710eSEric Fiselier {
525a83710eSEric Fiselier bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
535a83710eSEric Fiselier bool* an = a + sizeof(a)/sizeof(a[0]);
545a83710eSEric Fiselier test(std::vector<bool, min_allocator<bool>>(a, an));
555a83710eSEric Fiselier }
565a83710eSEric Fiselier {
57f81cfbabSEric Fiselier std::vector<bool, min_allocator<bool> > v(3, true, min_allocator<bool>());
585a83710eSEric Fiselier std::vector<bool, min_allocator<bool> > v2 = v;
595a83710eSEric Fiselier assert(v2 == v);
605a83710eSEric Fiselier assert(v2.get_allocator() == v.get_allocator());
615a83710eSEric Fiselier }
625a83710eSEric Fiselier #endif
632df59c50SJF Bastien
64*c74059c5SNikolas Klauser return true;
65*c74059c5SNikolas Klauser }
66*c74059c5SNikolas Klauser
main(int,char **)67*c74059c5SNikolas Klauser int main(int, char**)
68*c74059c5SNikolas Klauser {
69*c74059c5SNikolas Klauser tests();
70*c74059c5SNikolas Klauser #if TEST_STD_VER > 17
71*c74059c5SNikolas Klauser static_assert(tests());
72*c74059c5SNikolas Klauser #endif
732df59c50SJF Bastien return 0;
745a83710eSEric Fiselier }
75