xref: /llvm-project/libcxx/test/std/strings/basic.string/string.capacity/clear.pass.cpp (revision 57b08b0944046a6a57ee9b7b479181f548a5b9b4)
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 clear();
12 
13 #include <string>
14 #include <cassert>
15 
16 #include "min_allocator.h"
17 
18 template <class S>
19 void
20 test(S s)
21 {
22     s.clear();
23     assert(s.size() == 0);
24 }
25 
26 int main()
27 {
28     {
29     typedef std::string S;
30     S s;
31     test(s);
32 
33     s.assign(10, 'a');
34     s.erase(5);
35     test(s);
36 
37     s.assign(100, 'a');
38     s.erase(50);
39     test(s);
40     }
41 #if TEST_STD_VER >= 11
42     {
43     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
44     S s;
45     test(s);
46 
47     s.assign(10, 'a');
48     s.erase(5);
49     test(s);
50 
51     s.assign(100, 'a');
52     s.erase(50);
53     test(s);
54     }
55 #endif
56 }
57