move_assignment.pass.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // UNSUPPORTED: c++98, c++03
  10. // <string>
  11. // basic_string<charT,traits,Allocator>&
  12. // operator=(basic_string<charT,traits,Allocator>&& str);
  13. #include <string>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "test_allocator.h"
  17. #include "min_allocator.h"
  18. template <class S>
  19. void
  20. test(S s1, S s2)
  21. {
  22. S s0 = s2;
  23. s1 = std::move(s2);
  24. LIBCPP_ASSERT(s1.__invariants());
  25. LIBCPP_ASSERT(s2.__invariants());
  26. assert(s1 == s0);
  27. assert(s1.capacity() >= s1.size());
  28. }
  29. int main()
  30. {
  31. {
  32. typedef std::string S;
  33. test(S(), S());
  34. test(S("1"), S());
  35. test(S(), S("1"));
  36. test(S("1"), S("2"));
  37. test(S("1"), S("2"));
  38. test(S(),
  39. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  40. test(S("123456789"),
  41. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  42. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
  43. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  44. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
  45. "1234567890123456789012345678901234567890123456789012345678901234567890"),
  46. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  47. }
  48. {
  49. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  50. test(S(), S());
  51. test(S("1"), S());
  52. test(S(), S("1"));
  53. test(S("1"), S("2"));
  54. test(S("1"), S("2"));
  55. test(S(),
  56. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  57. test(S("123456789"),
  58. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  59. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
  60. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  61. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
  62. "1234567890123456789012345678901234567890123456789012345678901234567890"),
  63. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  64. }
  65. }