construct_iter_iter_alloc.pass.cpp 2.3 KB

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