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