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 // XFAIL: LIBCXX-AIX-FIXME 10 11 // <string> 12 13 // iterator erase(const_iterator p); // constexpr since C++20 14 15 #include <string> 16 #include <cassert> 17 18 #include "test_macros.h" 19 #include "min_allocator.h" 20 21 template <class S> 22 TEST_CONSTEXPR_CXX20 void 23 test(S s, typename S::difference_type pos, S expected) 24 { 25 typename S::const_iterator p = s.begin() + pos; 26 typename S::iterator i = s.erase(p); 27 LIBCPP_ASSERT(s.__invariants()); 28 assert(s[s.size()] == typename S::value_type()); 29 assert(s == expected); 30 assert(i - s.begin() == pos); 31 } 32 33 TEST_CONSTEXPR_CXX20 bool test() { 34 { 35 typedef std::string S; 36 test(S("abcde"), 0, S("bcde")); 37 test(S("abcde"), 1, S("acde")); 38 test(S("abcde"), 2, S("abde")); 39 test(S("abcde"), 4, S("abcd")); 40 test(S("abcdefghij"), 0, S("bcdefghij")); 41 test(S("abcdefghij"), 1, S("acdefghij")); 42 test(S("abcdefghij"), 5, S("abcdeghij")); 43 test(S("abcdefghij"), 9, S("abcdefghi")); 44 test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst")); 45 test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst")); 46 test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst")); 47 test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs")); 48 } 49 #if TEST_STD_VER >= 11 50 { 51 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 52 test(S("abcde"), 0, S("bcde")); 53 test(S("abcde"), 1, S("acde")); 54 test(S("abcde"), 2, S("abde")); 55 test(S("abcde"), 4, S("abcd")); 56 test(S("abcdefghij"), 0, S("bcdefghij")); 57 test(S("abcdefghij"), 1, S("acdefghij")); 58 test(S("abcdefghij"), 5, S("abcdeghij")); 59 test(S("abcdefghij"), 9, S("abcdefghi")); 60 test(S("abcdefghijklmnopqrst"), 0, S("bcdefghijklmnopqrst")); 61 test(S("abcdefghijklmnopqrst"), 1, S("acdefghijklmnopqrst")); 62 test(S("abcdefghijklmnopqrst"), 10, S("abcdefghijlmnopqrst")); 63 test(S("abcdefghijklmnopqrst"), 19, S("abcdefghijklmnopqrs")); 64 } 65 #endif 66 67 return true; 68 } 69 70 int main(int, char**) 71 { 72 test(); 73 #if TEST_STD_VER > 17 74 static_assert(test()); 75 #endif 76 77 return 0; 78 } 79