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 
10 // <string>
11 
12 // iterator erase(const_iterator p);
13 
14 #include <string>
15 #include <cassert>
16 
17 #include "../../min_allocator.h"
18 
19 template <class S>
20 void
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     assert(s.__invariants());
26     assert(s == expected);
27     assert(i - s.begin() == pos);
28 }
29 
30 int main()
31 {
32     {
33     typedef std::string S;
34     test(S("abcde"), 0, S("bcde"));
35     test(S("abcde"), 1, S("acde"));
36     test(S("abcde"), 2, S("abde"));
37     test(S("abcde"), 4, S("abcd"));
38     test(S("abcdefghij"), 0, S("bcdefghij"));
39     test(S("abcdefghij"), 1, S("acdefghij"));
40     test(S("abcdefghij"), 5, S("abcdeghij"));
41     test(S("abcdefghij"), 9, S("abcdefghi"));
42     test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
43     test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
44     test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
45     test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
46     }
47 #if __cplusplus >= 201103L
48     {
49     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
50     test(S("abcde"), 0, S("bcde"));
51     test(S("abcde"), 1, S("acde"));
52     test(S("abcde"), 2, S("abde"));
53     test(S("abcde"), 4, S("abcd"));
54     test(S("abcdefghij"), 0, S("bcdefghij"));
55     test(S("abcdefghij"), 1, S("acdefghij"));
56     test(S("abcdefghij"), 5, S("abcdeghij"));
57     test(S("abcdefghij"), 9, S("abcdefghi"));
58     test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst"));
59     test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst"));
60     test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst"));
61     test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs"));
62     }
63 #endif
64 }
65