swap.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <string>
  10. // void swap(basic_string& s);
  11. #include <string>
  12. #include <stdexcept>
  13. #include <algorithm>
  14. #include <cassert>
  15. template <class S>
  16. void
  17. test(S s1, S s2)
  18. {
  19. S s1_ = s1;
  20. S s2_ = s2;
  21. s1.swap(s2);
  22. assert(s1.__invariants());
  23. assert(s2.__invariants());
  24. assert(s1 == s2_);
  25. assert(s2 == s1_);
  26. }
  27. int main()
  28. {
  29. typedef std::string S;
  30. test(S(""), S(""));
  31. test(S(""), S("12345"));
  32. test(S(""), S("1234567890"));
  33. test(S(""), S("12345678901234567890"));
  34. test(S("abcde"), S(""));
  35. test(S("abcde"), S("12345"));
  36. test(S("abcde"), S("1234567890"));
  37. test(S("abcde"), S("12345678901234567890"));
  38. test(S("abcdefghij"), S(""));
  39. test(S("abcdefghij"), S("12345"));
  40. test(S("abcdefghij"), S("1234567890"));
  41. test(S("abcdefghij"), S("12345678901234567890"));
  42. test(S("abcdefghijklmnopqrst"), S(""));
  43. test(S("abcdefghijklmnopqrst"), S("12345"));
  44. test(S("abcdefghijklmnopqrst"), S("1234567890"));
  45. test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
  46. }