brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · b862583 Raw
60 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// <vector>10// vector<bool>11 12// template <class InputIter> vector(InputIter first, InputIter last);13 14#include <algorithm>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 23template <class C, class Iterator>24TEST_CONSTEXPR_CXX20 void test(Iterator first, Iterator last) {25  C c(first, last);26  LIBCPP_ASSERT(c.__invariants());27  assert(c.size() == static_cast<std::size_t>(std::distance(first, last)));28  assert(std::equal(c.cbegin(), c.cend(), first));29}30 31TEST_CONSTEXPR_CXX20 bool tests() {32  bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};33  bool* an = a + sizeof(a) / sizeof(a[0]);34  test<std::vector<bool> >(cpp17_input_iterator<const bool*>(a), cpp17_input_iterator<const bool*>(an));35  test<std::vector<bool> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an));36  test<std::vector<bool> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an));37  test<std::vector<bool> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an));38  test<std::vector<bool> >(a, an);39#if TEST_STD_VER >= 1140  test<std::vector<bool, min_allocator<bool>> >(41      cpp17_input_iterator<const bool*>(a), cpp17_input_iterator<const bool*>(an));42  test<std::vector<bool, min_allocator<bool>> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an));43  test<std::vector<bool, min_allocator<bool>> >(44      bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an));45  test<std::vector<bool, min_allocator<bool>> >(46      random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an));47  test<std::vector<bool, min_allocator<bool>> >(a, an);48#endif49 50  return true;51}52 53int main(int, char**) {54  tests();55#if TEST_STD_VER > 1756  static_assert(tests());57#endif58  return 0;59}60