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); // constexpr since C++20 12 13 #include <string> 14 #include <cassert> 15 16 #include "test_macros.h" 17 #include "min_allocator.h" 18 19 template <class S> 20 TEST_CONSTEXPR_CXX20 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 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 31 TEST_CONSTEXPR_CXX20 bool test() { 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 TEST_STD_VER >= 11 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 return true; 66 } 67 68 int main(int, char**) 69 { 70 test(); 71 #if TEST_STD_VER > 17 72 static_assert(test()); 73 #endif 74 75 return 0; 76 } 77