iter.pass.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 p);
  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, S expected)
  18. {
  19. typename S::const_iterator p = s.begin() + pos;
  20. typename S::iterator i = s.erase(p);
  21. LIBCPP_ASSERT(s.__invariants());
  22. assert(s == expected);
  23. assert(i - s.begin() == pos);
  24. }
  25. int main()
  26. {
  27. {
  28. typedef std::string S;
  29. test(S("abcde"), 0, S("bcde"));
  30. test(S("abcde"), 1, S("acde"));
  31. test(S("abcde"), 2, S("abde"));
  32. test(S("abcde"), 4, S("abcd"));
  33. test(S("abcdefghij"), 0, S("bcdefghij"));
  34. test(S("abcdefghij"), 1, S("acdefghij"));
  35. test(S("abcdefghij"), 5, S("abcdeghij"));
  36. test(S("abcdefghij"), 9, S("abcdefghi"));
  37. test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
  38. test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
  39. test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
  40. test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
  41. }
  42. #if TEST_STD_VER >= 11
  43. {
  44. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  45. test(S("abcde"), 0, S("bcde"));
  46. test(S("abcde"), 1, S("acde"));
  47. test(S("abcde"), 2, S("abde"));
  48. test(S("abcde"), 4, S("abcd"));
  49. test(S("abcdefghij"), 0, S("bcdefghij"));
  50. test(S("abcdefghij"), 1, S("acdefghij"));
  51. test(S("abcdefghij"), 5, S("abcdeghij"));
  52. test(S("abcdefghij"), 9, S("abcdefghi"));
  53. test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
  54. test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
  55. test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
  56. test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
  57. }
  58. #endif
  59. }