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