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 | // <vector> |
10 | // vector<bool> |
11 | |
12 | // explicit vector(size_type n); |
13 | |
14 | #include <vector> |
15 | #include <cassert> |
16 | |
17 | #include "test_macros.h" |
18 | #include "min_allocator.h" |
19 | #include "test_allocator.h" |
20 | |
21 | template <class C> |
22 | TEST_CONSTEXPR_CXX20 void test2(typename C::size_type n, |
23 | typename C::allocator_type const& a = typename C::allocator_type ()) |
24 | { |
25 | #if TEST_STD_VER >= 14 |
26 | C c(n, a); |
27 | LIBCPP_ASSERT(c.__invariants()); |
28 | assert(c.size() == n); |
29 | assert(c.get_allocator() == a); |
30 | for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) |
31 | assert(*i == typename C::value_type()); |
32 | #else |
33 | ((void)n); |
34 | ((void)a); |
35 | #endif |
36 | } |
37 | |
38 | template <class C> |
39 | TEST_CONSTEXPR_CXX20 void test1(typename C::size_type n) |
40 | { |
41 | C c(n); |
42 | LIBCPP_ASSERT(c.__invariants()); |
43 | assert(c.size() == n); |
44 | assert(c.get_allocator() == typename C::allocator_type()); |
45 | for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) |
46 | assert(*i == typename C::value_type()); |
47 | } |
48 | |
49 | template <class C> |
50 | TEST_CONSTEXPR_CXX20 void test(typename C::size_type n) |
51 | { |
52 | test1<C> ( n ); |
53 | test2<C> ( n ); |
54 | } |
55 | |
56 | TEST_CONSTEXPR_CXX20 bool tests() |
57 | { |
58 | test<std::vector<bool> >(50); |
59 | #if TEST_STD_VER >= 11 |
60 | test<std::vector<bool, min_allocator<bool>> >(50); |
61 | test2<std::vector<bool, test_allocator<bool>> >( 100, test_allocator<bool>(23)); |
62 | #endif |
63 | |
64 | return true; |
65 | } |
66 | |
67 | int main(int, char**) |
68 | { |
69 | tests(); |
70 | #if TEST_STD_VER > 17 |
71 | static_assert(tests()); |
72 | #endif |
73 | return 0; |
74 | } |
75 | |