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 "test_macros.h" 18 #include "min_allocator.h" 19 20 template <class S> 21 void 22 test(S s, typename S::difference_type pos, S expected) 23 { 24 typename S::const_iterator p = s.begin() + pos; 25 typename S::iterator i = s.erase(p); 26 LIBCPP_ASSERT(s.__invariants()); 27 assert(s == expected); 28 assert(i - s.begin() == pos); 29 } 30 31 int main() 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