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
115a83710eSEric Fiselier // vector(const vector& v, const allocator_type& a);
125a83710eSEric Fiselier
135a83710eSEric Fiselier #include <vector>
145a83710eSEric Fiselier #include <cassert>
151f4231f8SEric Fiselier
161f4231f8SEric Fiselier #include "test_macros.h"
175a83710eSEric Fiselier #include "test_allocator.h"
185a83710eSEric Fiselier #include "min_allocator.h"
195a83710eSEric Fiselier
205a83710eSEric Fiselier template <class C>
test(const C & x,const typename C::allocator_type & a)21*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 void test(const C& x, const typename C::allocator_type& a)
225a83710eSEric Fiselier {
23d4b83e6dSStephan T. Lavavej typename C::size_type s = x.size();
245a83710eSEric Fiselier C c(x, a);
251f4231f8SEric Fiselier LIBCPP_ASSERT(c.__invariants());
265a83710eSEric Fiselier assert(c.size() == s);
275a83710eSEric Fiselier assert(c == x);
285a83710eSEric Fiselier }
295a83710eSEric Fiselier
tests()30*c74059c5SNikolas Klauser TEST_CONSTEXPR_CXX20 bool tests()
315a83710eSEric Fiselier {
325a83710eSEric Fiselier {
33f81cfbabSEric Fiselier bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
34f81cfbabSEric Fiselier bool* an = a + sizeof(a)/sizeof(a[0]);
355a83710eSEric Fiselier test(std::vector<bool>(a, an), std::allocator<bool>());
365a83710eSEric Fiselier }
375a83710eSEric Fiselier {
38f81cfbabSEric Fiselier std::vector<bool, test_allocator<bool> > l(3, true, test_allocator<bool>(5));
395a83710eSEric Fiselier std::vector<bool, test_allocator<bool> > l2(l, test_allocator<bool>(3));
405a83710eSEric Fiselier assert(l2 == l);
415a83710eSEric Fiselier assert(l2.get_allocator() == test_allocator<bool>(3));
425a83710eSEric Fiselier }
435a83710eSEric Fiselier {
44f81cfbabSEric Fiselier std::vector<bool, other_allocator<bool> > l(3, true, other_allocator<bool>(5));
455a83710eSEric Fiselier std::vector<bool, other_allocator<bool> > l2(l, other_allocator<bool>(3));
465a83710eSEric Fiselier assert(l2 == l);
475a83710eSEric Fiselier assert(l2.get_allocator() == other_allocator<bool>(3));
485a83710eSEric Fiselier }
491f4231f8SEric Fiselier #if TEST_STD_VER >= 11
505a83710eSEric Fiselier {
51f81cfbabSEric Fiselier bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
52f81cfbabSEric Fiselier bool* an = a + sizeof(a)/sizeof(a[0]);
535a83710eSEric Fiselier test(std::vector<bool, min_allocator<bool>>(a, an), min_allocator<bool>());
545a83710eSEric Fiselier }
555a83710eSEric Fiselier {
56f81cfbabSEric Fiselier std::vector<bool, min_allocator<bool> > l(3, true, min_allocator<bool>());
575a83710eSEric Fiselier std::vector<bool, min_allocator<bool> > l2(l, min_allocator<bool>());
585a83710eSEric Fiselier assert(l2 == l);
595a83710eSEric Fiselier assert(l2.get_allocator() == min_allocator<bool>());
605a83710eSEric Fiselier }
615a83710eSEric Fiselier #endif
622df59c50SJF Bastien
63*c74059c5SNikolas Klauser return true;
64*c74059c5SNikolas Klauser }
65*c74059c5SNikolas Klauser
main(int,char **)66*c74059c5SNikolas Klauser int main(int, char**)
67*c74059c5SNikolas Klauser {
68*c74059c5SNikolas Klauser tests();
69*c74059c5SNikolas Klauser #if TEST_STD_VER > 17
70*c74059c5SNikolas Klauser static_assert(tests());
71*c74059c5SNikolas Klauser #endif
722df59c50SJF Bastien return 0;
735a83710eSEric Fiselier }
74