iter_iter.pass.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // <string>
  10. // iterator erase(const_iterator first, const_iterator last);
  11. #include <string>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "min_allocator.h"
  15. template <class S>
  16. void
  17. test(S s, typename S::difference_type pos, typename S::difference_type n, S expected)
  18. {
  19. typename S::const_iterator first = s.cbegin() + pos;
  20. typename S::const_iterator last = s.cbegin() + pos + n;
  21. typename S::iterator i = s.erase(first, last);
  22. LIBCPP_ASSERT(s.__invariants());
  23. assert(s == expected);
  24. assert(i - s.begin() == pos);
  25. }
  26. int main()
  27. {
  28. {
  29. typedef std::string S;
  30. test(S(""), 0, 0, S(""));
  31. test(S("abcde"), 0, 0, S("abcde"));
  32. test(S("abcde"), 0, 1, S("bcde"));
  33. test(S("abcde"), 0, 2, S("cde"));
  34. test(S("abcde"), 0, 4, S("e"));
  35. test(S("abcde"), 0, 5, S(""));
  36. test(S("abcde"), 1, 0, S("abcde"));
  37. test(S("abcde"), 1, 1, S("acde"));
  38. test(S("abcde"), 1, 2, S("ade"));
  39. test(S("abcde"), 1, 3, S("ae"));
  40. test(S("abcde"), 1, 4, S("a"));
  41. test(S("abcde"), 2, 0, S("abcde"));
  42. test(S("abcde"), 2, 1, S("abde"));
  43. test(S("abcde"), 2, 2, S("abe"));
  44. test(S("abcde"), 2, 3, S("ab"));
  45. test(S("abcde"), 4, 0, S("abcde"));
  46. test(S("abcde"), 4, 1, S("abcd"));
  47. test(S("abcde"), 5, 0, S("abcde"));
  48. test(S("abcdefghij"), 0, 0, S("abcdefghij"));
  49. test(S("abcdefghij"), 0, 1, S("bcdefghij"));
  50. test(S("abcdefghij"), 0, 5, S("fghij"));
  51. test(S("abcdefghij"), 0, 9, S("j"));
  52. test(S("abcdefghij"), 0, 10, S(""));
  53. test(S("abcdefghij"), 1, 0, S("abcdefghij"));
  54. test(S("abcdefghij"), 1, 1, S("acdefghij"));
  55. test(S("abcdefghij"), 1, 4, S("afghij"));
  56. test(S("abcdefghij"), 1, 8, S("aj"));
  57. test(S("abcdefghij"), 1, 9, S("a"));
  58. test(S("abcdefghij"), 5, 0, S("abcdefghij"));
  59. test(S("abcdefghij"), 5, 1, S("abcdeghij"));
  60. test(S("abcdefghij"), 5, 2, S("abcdehij"));
  61. test(S("abcdefghij"), 5, 4, S("abcdej"));
  62. test(S("abcdefghij"), 5, 5, S("abcde"));
  63. test(S("abcdefghij"), 9, 0, S("abcdefghij"));
  64. test(S("abcdefghij"), 9, 1, S("abcdefghi"));
  65. test(S("abcdefghij"), 10, 0, S("abcdefghij"));
  66. test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
  67. test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
  68. test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
  69. test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
  70. test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
  71. test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
  72. test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
  73. test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
  74. test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
  75. test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
  76. test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
  77. test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
  78. test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
  79. test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
  80. test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
  81. test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
  82. test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
  83. test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
  84. }
  85. #if TEST_STD_VER >= 11
  86. {
  87. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  88. test(S(""), 0, 0, S(""));
  89. test(S("abcde"), 0, 0, S("abcde"));
  90. test(S("abcde"), 0, 1, S("bcde"));
  91. test(S("abcde"), 0, 2, S("cde"));
  92. test(S("abcde"), 0, 4, S("e"));
  93. test(S("abcde"), 0, 5, S(""));
  94. test(S("abcde"), 1, 0, S("abcde"));
  95. test(S("abcde"), 1, 1, S("acde"));
  96. test(S("abcde"), 1, 2, S("ade"));
  97. test(S("abcde"), 1, 3, S("ae"));
  98. test(S("abcde"), 1, 4, S("a"));
  99. test(S("abcde"), 2, 0, S("abcde"));
  100. test(S("abcde"), 2, 1, S("abde"));
  101. test(S("abcde"), 2, 2, S("abe"));
  102. test(S("abcde"), 2, 3, S("ab"));
  103. test(S("abcde"), 4, 0, S("abcde"));
  104. test(S("abcde"), 4, 1, S("abcd"));
  105. test(S("abcde"), 5, 0, S("abcde"));
  106. test(S("abcdefghij"), 0, 0, S("abcdefghij"));
  107. test(S("abcdefghij"), 0, 1, S("bcdefghij"));
  108. test(S("abcdefghij"), 0, 5, S("fghij"));
  109. test(S("abcdefghij"), 0, 9, S("j"));
  110. test(S("abcdefghij"), 0, 10, S(""));
  111. test(S("abcdefghij"), 1, 0, S("abcdefghij"));
  112. test(S("abcdefghij"), 1, 1, S("acdefghij"));
  113. test(S("abcdefghij"), 1, 4, S("afghij"));
  114. test(S("abcdefghij"), 1, 8, S("aj"));
  115. test(S("abcdefghij"), 1, 9, S("a"));
  116. test(S("abcdefghij"), 5, 0, S("abcdefghij"));
  117. test(S("abcdefghij"), 5, 1, S("abcdeghij"));
  118. test(S("abcdefghij"), 5, 2, S("abcdehij"));
  119. test(S("abcdefghij"), 5, 4, S("abcdej"));
  120. test(S("abcdefghij"), 5, 5, S("abcde"));
  121. test(S("abcdefghij"), 9, 0, S("abcdefghij"));
  122. test(S("abcdefghij"), 9, 1, S("abcdefghi"));
  123. test(S("abcdefghij"), 10, 0, S("abcdefghij"));
  124. test(S("abcdefghijklmnopqrst"), 0, 0, S("abcdefghijklmnopqrst"));
  125. test(S("abcdefghijklmnopqrst"), 0, 1, S("bcdefghijklmnopqrst"));
  126. test(S("abcdefghijklmnopqrst"), 0, 10, S("klmnopqrst"));
  127. test(S("abcdefghijklmnopqrst"), 0, 19, S("t"));
  128. test(S("abcdefghijklmnopqrst"), 0, 20, S(""));
  129. test(S("abcdefghijklmnopqrst"), 1, 0, S("abcdefghijklmnopqrst"));
  130. test(S("abcdefghijklmnopqrst"), 1, 1, S("acdefghijklmnopqrst"));
  131. test(S("abcdefghijklmnopqrst"), 1, 9, S("aklmnopqrst"));
  132. test(S("abcdefghijklmnopqrst"), 1, 18, S("at"));
  133. test(S("abcdefghijklmnopqrst"), 1, 19, S("a"));
  134. test(S("abcdefghijklmnopqrst"), 10, 0, S("abcdefghijklmnopqrst"));
  135. test(S("abcdefghijklmnopqrst"), 10, 1, S("abcdefghijlmnopqrst"));
  136. test(S("abcdefghijklmnopqrst"), 10, 5, S("abcdefghijpqrst"));
  137. test(S("abcdefghijklmnopqrst"), 10, 9, S("abcdefghijt"));
  138. test(S("abcdefghijklmnopqrst"), 10, 10, S("abcdefghij"));
  139. test(S("abcdefghijklmnopqrst"), 19, 0, S("abcdefghijklmnopqrst"));
  140. test(S("abcdefghijklmnopqrst"), 19, 1, S("abcdefghijklmnopqrs"));
  141. test(S("abcdefghijklmnopqrst"), 20, 0, S("abcdefghijklmnopqrst"));
  142. }
  143. #endif
  144. }