move.pass.cpp 1.4 KB

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