blob: 914842bb7a65366ed2a125ea07281856416045d1 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Howard Hinnant3e519522010-05-11 19:42:16 +00006//
7//===----------------------------------------------------------------------===//
8
9// <string>
10
11// void clear();
12
13#include <string>
14#include <cassert>
15
Marshall Clowe34f6f62013-11-26 20:58:02 +000016#include "min_allocator.h"
Howard Hinnanteec72182013-06-28 16:59:19 +000017
Howard Hinnant3e519522010-05-11 19:42:16 +000018template <class S>
19void
20test(S s)
21{
22 s.clear();
23 assert(s.size() == 0);
24}
25
JF Bastien2df59c52019-02-04 20:31:13 +000026int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000027{
Howard Hinnanteec72182013-06-28 16:59:19 +000028 {
Howard Hinnant3e519522010-05-11 19:42:16 +000029 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);
Howard Hinnanteec72182013-06-28 16:59:19 +000040 }
Eric Fiselierf2f2a632016-06-14 21:31:42 +000041#if TEST_STD_VER >= 11
Howard Hinnanteec72182013-06-28 16:59:19 +000042 {
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
JF Bastien2df59c52019-02-04 20:31:13 +000056
57 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000058}