assign_move.pass.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // UNSUPPORTED: c++98, c++03
  9. // <vector>
  10. // vector& operator=(vector&& c);
  11. #include <vector>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "test_allocator.h"
  15. #include "min_allocator.h"
  16. int main(int, char**)
  17. {
  18. {
  19. std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5));
  20. std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5));
  21. for (int i = 1; i <= 3; ++i)
  22. {
  23. l.push_back(i);
  24. lo.push_back(i);
  25. }
  26. std::vector<bool, test_allocator<bool> > l2(test_allocator<bool>(5));
  27. l2 = std::move(l);
  28. assert(l2 == lo);
  29. assert(l.empty());
  30. assert(l2.get_allocator() == lo.get_allocator());
  31. }
  32. {
  33. std::vector<bool, test_allocator<bool> > l(test_allocator<bool>(5));
  34. std::vector<bool, test_allocator<bool> > lo(test_allocator<bool>(5));
  35. for (int i = 1; i <= 3; ++i)
  36. {
  37. l.push_back(i);
  38. lo.push_back(i);
  39. }
  40. std::vector<bool, test_allocator<bool> > l2(test_allocator<bool>(6));
  41. l2 = std::move(l);
  42. assert(l2 == lo);
  43. assert(!l.empty());
  44. assert(l2.get_allocator() == test_allocator<bool>(6));
  45. }
  46. {
  47. std::vector<bool, other_allocator<bool> > l(other_allocator<bool>(5));
  48. std::vector<bool, other_allocator<bool> > lo(other_allocator<bool>(5));
  49. for (int i = 1; i <= 3; ++i)
  50. {
  51. l.push_back(i);
  52. lo.push_back(i);
  53. }
  54. std::vector<bool, other_allocator<bool> > l2(other_allocator<bool>(6));
  55. l2 = std::move(l);
  56. assert(l2 == lo);
  57. assert(l.empty());
  58. assert(l2.get_allocator() == lo.get_allocator());
  59. }
  60. {
  61. std::vector<bool, min_allocator<bool> > l(min_allocator<bool>{});
  62. std::vector<bool, min_allocator<bool> > lo(min_allocator<bool>{});
  63. for (int i = 1; i <= 3; ++i)
  64. {
  65. l.push_back(i);
  66. lo.push_back(i);
  67. }
  68. std::vector<bool, min_allocator<bool> > l2(min_allocator<bool>{});
  69. l2 = std::move(l);
  70. assert(l2 == lo);
  71. assert(l.empty());
  72. assert(l2.get_allocator() == lo.get_allocator());
  73. }
  74. return 0;
  75. }