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 // basic_string<charT,traits,Allocator>& operator+=(charT c); // constexpr since C++20
12
13 #include <string>
14 #include <cassert>
15
16 #include "test_macros.h"
17 #include "min_allocator.h"
18
19 template <class S>
20 TEST_CONSTEXPR_CXX20 void
test(S s,typename S::value_type str,S expected)21 test(S s, typename S::value_type str, S expected)
22 {
23 s += str;
24 LIBCPP_ASSERT(s.__invariants());
25 assert(s == expected);
26 }
27
test()28 TEST_CONSTEXPR_CXX20 bool test() {
29 {
30 typedef std::string S;
31 test(S(), 'a', S("a"));
32 test(S("12345"), 'a', S("12345a"));
33 test(S("1234567890"), 'a', S("1234567890a"));
34 test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
35 }
36 #if TEST_STD_VER >= 11
37 {
38 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
39 test(S(), 'a', S("a"));
40 test(S("12345"), 'a', S("12345a"));
41 test(S("1234567890"), 'a', S("1234567890a"));
42 test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
43 }
44 #endif
45
46 return true;
47 }
48
main(int,char **)49 int main(int, char**)
50 {
51 test();
52 #if TEST_STD_VER > 17
53 static_assert(test());
54 #endif
55
56 return 0;
57 }
58