copy.pass.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // vector(const vector& v);
  11. #include <vector>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "test_allocator.h"
  15. #include "min_allocator.h"
  16. template <class C>
  17. void
  18. test(const C& x)
  19. {
  20. typename C::size_type s = x.size();
  21. C c(x);
  22. LIBCPP_ASSERT(c.__invariants());
  23. assert(c.size() == s);
  24. assert(c == x);
  25. }
  26. int main(int, char**)
  27. {
  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>(a, an));
  32. }
  33. {
  34. std::vector<bool, test_allocator<bool> > v(3, true, test_allocator<bool>(5));
  35. std::vector<bool, test_allocator<bool> > v2 = v;
  36. assert(v2 == v);
  37. assert(v2.get_allocator() == v.get_allocator());
  38. }
  39. #if TEST_STD_VER >= 11
  40. {
  41. std::vector<bool, other_allocator<bool> > v(3, true, other_allocator<bool>(5));
  42. std::vector<bool, other_allocator<bool> > v2 = v;
  43. assert(v2 == v);
  44. assert(v2.get_allocator() == other_allocator<bool>(-2));
  45. }
  46. {
  47. bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
  48. bool* an = a + sizeof(a)/sizeof(a[0]);
  49. test(std::vector<bool, min_allocator<bool>>(a, an));
  50. }
  51. {
  52. std::vector<bool, min_allocator<bool> > v(3, true, min_allocator<bool>());
  53. std::vector<bool, min_allocator<bool> > v2 = v;
  54. assert(v2 == v);
  55. assert(v2.get_allocator() == v.get_allocator());
  56. }
  57. #endif
  58. return 0;
  59. }