xref: /llvm-project/libcxx/test/std/strings/basic.string/string.modifiers/string_erase/pop_back.pass.cpp (revision 2df59c50688c122bbcae7467d3eaf862c3ea3088)
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 // void pop_back();
12 
13 #include <string>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 #include "min_allocator.h"
18 
19 template <class S>
20 void
21 test(S s, S expected)
22 {
23     s.pop_back();
24     LIBCPP_ASSERT(s.__invariants());
25     assert(s[s.size()] == typename S::value_type());
26     assert(s == expected);
27 }
28 
29 int main(int, char**)
30 {
31     {
32     typedef std::string S;
33     test(S("abcde"), S("abcd"));
34     test(S("abcdefghij"), S("abcdefghi"));
35     test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrs"));
36     }
37 #if TEST_STD_VER >= 11
38     {
39     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
40     test(S("abcde"), S("abcd"));
41     test(S("abcdefghij"), S("abcdefghi"));
42     test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrs"));
43     }
44 #endif
45 
46   return 0;
47 }
48