1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // <string>
10
11 // iterator erase(const_iterator p);
12
13 #include <string>
14 #include <cassert>
15
16 #include "test_macros.h"
17 #include "min_allocator.h"
18
19 template <class S>
20 void
test(S s,typename S::difference_type pos,S expected)21 test(S s, typename S::difference_type pos, S expected)
22 {
23 typename S::const_iterator p = s.begin() + pos;
24 typename S::iterator i = s.erase(p);
25 LIBCPP_ASSERT(s.__invariants());
26 assert(s[s.size()] == typename S::value_type());
27 assert(s == expected);
28 assert(i - s.begin() == pos);
29 }
30
main(int,char **)31 int main(int, char**)
32 {
33 {
34 typedef std::string S;
35 test(S("abcde"), 0, S("bcde"));
36 test(S("abcde"), 1, S("acde"));
37 test(S("abcde"), 2, S("abde"));
38 test(S("abcde"), 4, S("abcd"));
39 test(S("abcdefghij"), 0, S("bcdefghij"));
40 test(S("abcdefghij"), 1, S("acdefghij"));
41 test(S("abcdefghij"), 5, S("abcdeghij"));
42 test(S("abcdefghij"), 9, S("abcdefghi"));
43 test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
44 test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
45 test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
46 test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
47 }
48 #if TEST_STD_VER >= 11
49 {
50 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
51 test(S("abcde"), 0, S("bcde"));
52 test(S("abcde"), 1, S("acde"));
53 test(S("abcde"), 2, S("abde"));
54 test(S("abcde"), 4, S("abcd"));
55 test(S("abcdefghij"), 0, S("bcdefghij"));
56 test(S("abcdefghij"), 1, S("acdefghij"));
57 test(S("abcdefghij"), 5, S("abcdeghij"));
58 test(S("abcdefghij"), 9, S("abcdefghi"));
59 test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
60 test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
61 test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
62 test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
63 }
64 #endif
65
66 return 0;
67 }
68