| 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 | // template <class InputIter> vector(InputIter first, InputIter last, |
| 13 | // const allocator_type& a); |
| 14 | |
| 15 | #include <vector> |
| 16 | #include <cassert> |
| 17 | #include <cstddef> |
| 18 | |
| 19 | #include "test_macros.h" |
| 20 | #include "test_iterators.h" |
| 21 | #include "min_allocator.h" |
| 22 | |
| 23 | template <class C, class Iterator> |
| 24 | TEST_CONSTEXPR_CXX20 void test(Iterator first, Iterator last, const typename C::allocator_type& a) { |
| 25 | C c(first, last, a); |
| 26 | LIBCPP_ASSERT(c.__invariants()); |
| 27 | assert(c.size() == static_cast<std::size_t>(std::distance(first, last))); |
| 28 | for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) |
| 29 | assert(*i == *first); |
| 30 | } |
| 31 | |
| 32 | TEST_CONSTEXPR_CXX20 bool tests() { |
| 33 | bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; |
| 34 | bool* an = a + sizeof(a) / sizeof(a[0]); |
| 35 | { |
| 36 | std::allocator<bool> alloc; |
| 37 | test<std::vector<bool> >(cpp17_input_iterator<const bool*>(a), cpp17_input_iterator<const bool*>(an), alloc); |
| 38 | test<std::vector<bool> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an), alloc); |
| 39 | test<std::vector<bool> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an), alloc); |
| 40 | test<std::vector<bool> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an), alloc); |
| 41 | test<std::vector<bool> >(a, an, alloc); |
| 42 | } |
| 43 | #if TEST_STD_VER >= 11 |
| 44 | { |
| 45 | min_allocator<bool> alloc; |
| 46 | test<std::vector<bool, min_allocator<bool>> >( |
| 47 | cpp17_input_iterator<const bool*>(a), cpp17_input_iterator<const bool*>(an), alloc); |
| 48 | test<std::vector<bool, min_allocator<bool>> >( |
| 49 | forward_iterator<const bool*>(a), forward_iterator<const bool*>(an), alloc); |
| 50 | test<std::vector<bool, min_allocator<bool>> >( |
| 51 | bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an), alloc); |
| 52 | test<std::vector<bool, min_allocator<bool>> >( |
| 53 | random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an), alloc); |
| 54 | test<std::vector<bool, min_allocator<bool>> >(a, an, alloc); |
| 55 | } |
| 56 | #endif |
| 57 | |
| 58 | return true; |
| 59 | } |
| 60 | |
| 61 | int main(int, char**) { |
| 62 | tests(); |
| 63 | #if TEST_STD_VER > 17 |
| 64 | static_assert(tests()); |
| 65 | #endif |
| 66 | return 0; |
| 67 | } |
| 68 | |