move.pass.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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(basic_string<charT,traits,Allocator>&& str);
  12. #include <string>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. #include "test_allocator.h"
  16. #include "min_allocator.h"
  17. template <class S>
  18. void
  19. test(S s0)
  20. {
  21. S s1 = s0;
  22. S s2 = std::move(s0);
  23. LIBCPP_ASSERT(s2.__invariants());
  24. LIBCPP_ASSERT(s0.__invariants());
  25. assert(s2 == s1);
  26. assert(s2.capacity() >= s2.size());
  27. assert(s2.get_allocator() == s1.get_allocator());
  28. }
  29. int main()
  30. {
  31. {
  32. typedef test_allocator<char> A;
  33. typedef std::basic_string<char, std::char_traits<char>, A> S;
  34. test(S(A(3)));
  35. test(S("1", A(5)));
  36. test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
  37. }
  38. {
  39. typedef min_allocator<char> A;
  40. typedef std::basic_string<char, std::char_traits<char>, A> S;
  41. test(S(A{}));
  42. test(S("1", A()));
  43. test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
  44. }
  45. }