blob: 62b3627edf6cdaf4446e8db06caf27fffcdc51ff [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 Clow7fc6a552019-05-31 18:35:30 +000016#include "test_macros.h"
Marshall Clowe34f6f62013-11-26 20:58:02 +000017#include "min_allocator.h"
Howard Hinnanteec72182013-06-28 16:59:19 +000018
Howard Hinnant3e519522010-05-11 19:42:16 +000019template <class S>
20void
21test(S s)
22{
23 s.clear();
24 assert(s.size() == 0);
25}
26
JF Bastien2df59c52019-02-04 20:31:13 +000027int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000028{
Howard Hinnanteec72182013-06-28 16:59:19 +000029 {
Howard Hinnant3e519522010-05-11 19:42:16 +000030 typedef std::string S;
31 S s;
32 test(s);
33
34 s.assign(10, 'a');
35 s.erase(5);
36 test(s);
37
38 s.assign(100, 'a');
39 s.erase(50);
40 test(s);
Howard Hinnanteec72182013-06-28 16:59:19 +000041 }
Eric Fiselierf2f2a632016-06-14 21:31:42 +000042#if TEST_STD_VER >= 11
Howard Hinnanteec72182013-06-28 16:59:19 +000043 {
44 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
45 S s;
46 test(s);
47
48 s.assign(10, 'a');
49 s.erase(5);
50 test(s);
51
52 s.assign(100, 'a');
53 s.erase(50);
54 test(s);
55 }
56#endif
JF Bastien2df59c52019-02-04 20:31:13 +000057
58 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000059}