Home | History | Annotate | Download | only in string_erase
      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[s.size()] == typename S::value_type());
     28     assert(s == expected);
     29     assert(i - s.begin() == pos);
     30 }
     31 
     32 int main()
     33 {
     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