construct_iter_iter.pass.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // <vector>
  9. // vector<bool>
  10. // template <class InputIter> vector(InputIter first, InputIter last);
  11. #include <vector>
  12. #include <cassert>
  13. #include <cstddef>
  14. #include "test_macros.h"
  15. #include "test_iterators.h"
  16. #include "min_allocator.h"
  17. template <class C, class Iterator>
  18. void
  19. test(Iterator first, Iterator last)
  20. {
  21. C c(first, last);
  22. LIBCPP_ASSERT(c.__invariants());
  23. assert(c.size() == static_cast<std::size_t>(std::distance(first, last)));
  24. for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first)
  25. assert(*i == *first);
  26. }
  27. int main(int, char**)
  28. {
  29. bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
  30. bool* an = a + sizeof(a)/sizeof(a[0]);
  31. test<std::vector<bool> >(input_iterator<const bool*>(a), input_iterator<const bool*>(an));
  32. test<std::vector<bool> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an));
  33. test<std::vector<bool> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an));
  34. test<std::vector<bool> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an));
  35. test<std::vector<bool> >(a, an);
  36. #if TEST_STD_VER >= 11
  37. test<std::vector<bool, min_allocator<bool>> >(input_iterator<const bool*>(a), input_iterator<const bool*>(an));
  38. test<std::vector<bool, min_allocator<bool>> >(forward_iterator<const bool*>(a), forward_iterator<const bool*>(an));
  39. test<std::vector<bool, min_allocator<bool>> >(bidirectional_iterator<const bool*>(a), bidirectional_iterator<const bool*>(an));
  40. test<std::vector<bool, min_allocator<bool>> >(random_access_iterator<const bool*>(a), random_access_iterator<const bool*>(an));
  41. test<std::vector<bool, min_allocator<bool>> >(a, an);
  42. #endif
  43. return 0;
  44. }