iter_iter.pass.cpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // iterator erase(const_iterator first, const_iterator last);
  11. #include <string>
  12. #include <cassert>
  13. template <class S>
  14. void
  15. test(S s, typename S::difference_type pos, typename S::difference_type n, S expected)
  16. {
  17. typename S::const_iterator first = s.cbegin() + pos;
  18. typename S::const_iterator last = s.cbegin() + pos + n;
  19. typename S::iterator i = s.erase(first, last);
  20. assert(s.__invariants());
  21. assert(s == expected);
  22. assert(i - s.begin() == pos);
  23. }
  24. int main()
  25. {
  26. typedef std::string S;
  27. test(S(""), 0, 0, S(""));
  28. test(S("abcde"), 0, 0, S("abcde"));
  29. test(S("abcde"), 0, 1, S("bcde"));
  30. test(S("abcde"), 0, 2, S("cde"));
  31. test(S("abcde"), 0, 4, S("e"));
  32. test(S("abcde"), 0, 5, S(""));
  33. test(S("abcde"), 1, 0, S("abcde"));
  34. test(S("abcde"), 1, 1, S("acde"));
  35. test(S("abcde"), 1, 2, S("ade"));
  36. test(S("abcde"), 1, 3, S("ae"));
  37. test(S("abcde"), 1, 4, S("a"));
  38. test(S("abcde"), 2, 0, S("abcde"));
  39. test(S("abcde"), 2, 1, S("abde"));
  40. test(S("abcde"), 2, 2, S("abe"));
  41. test(S("abcde"), 2, 3, S("ab"));
  42. test(S("abcde"), 4, 0, S("abcde"));
  43. test(S("abcde"), 4, 1, S("abcd"));
  44. test(S("abcde"), 5, 0, S("abcde"));
  45. test(S("abcdefghij"), 0, 0, S("abcdefghij"));
  46. test(S("abcdefghij"), 0, 1, S("bcdefghij"));
  47. test(S("abcdefghij"), 0, 5, S("fghij"));
  48. test(S("abcdefghij"), 0, 9, S("j"));
  49. test(S("abcdefghij"), 0, 10, S(""));
  50. test(S("abcdefghij"), 1, 0, S("abcdefghij"));
  51. test(S("abcdefghij"), 1, 1, S("acdefghij"));
  52. test(S("abcdefghij"), 1, 4, S("afghij"));
  53. test(S("abcdefghij"), 1, 8, S("aj"));
  54. test(S("abcdefghij"), 1, 9, S("a"));
  55. test(S("abcdefghij"), 5, 0, S("abcdefghij"));
  56. test(S("abcdefghij"), 5, 1, S("abcdeghij"));
  57. test(S("abcdefghij"), 5, 2, S("abcdehij"));
  58. test(S("abcdefghij"), 5, 4, S("abcdej"));
  59. test(S("abcdefghij"), 5, 5, S("abcde"));
  60. test(S("abcdefghij"), 9, 0, S("abcdefghij"));
  61. test(S("abcdefghij"), 9, 1, S("abcdefghi"));
  62. test(S("abcdefghij"), 10, 0, S("abcdefghij"));
  63. test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
  64. test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
  65. test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
  66. test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
  67. test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
  68. test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
  69. test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
  70. test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
  71. test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
  72. test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
  73. test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
  74. test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
  75. test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
  76. test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
  77. test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
  78. test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
  79. test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
  80. test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
  81. }