iter.pass.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 p);
  11. #include <string>
  12. #include <cassert>
  13. template <class S>
  14. void
  15. test(S s, typename S::difference_type pos, S expected)
  16. {
  17. typename S::const_iterator p = s.begin() + pos;
  18. typename S::iterator i = s.erase(p);
  19. assert(s.__invariants());
  20. assert(s == expected);
  21. assert(i - s.begin() == pos);
  22. }
  23. int main()
  24. {
  25. typedef std::string S;
  26. test(S("abcde"), 0, S("bcde"));
  27. test(S("abcde"), 1, S("acde"));
  28. test(S("abcde"), 2, S("abde"));
  29. test(S("abcde"), 4, S("abcd"));
  30. test(S("abcdefghij"), 0, S("bcdefghij"));
  31. test(S("abcdefghij"), 1, S("acdefghij"));
  32. test(S("abcdefghij"), 5, S("abcdeghij"));
  33. test(S("abcdefghij"), 9, S("abcdefghi"));
  34. test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
  35. test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
  36. test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
  37. test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
  38. }