copy_alloc.pass.cpp 2.0 KB

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