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 // template<class charT, class traits, class Allocator>
12 // basic_string<charT,traits,Allocator>
13 // operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs); // constexpr since C++20
14
15 // template<class charT, class traits, class Allocator>
16 // basic_string<charT,traits,Allocator>&&
17 // operator+(basic_string<charT,traits,Allocator>&& lhs, charT rhs); // constexpr since C++20
18
19 #include <string>
20 #include <utility>
21 #include <cassert>
22
23 #include "test_macros.h"
24 #include "min_allocator.h"
25
26 template <class S>
test0(const S & lhs,typename S::value_type rhs,const S & x)27 TEST_CONSTEXPR_CXX20 void test0(const S& lhs, typename S::value_type rhs, const S& x) {
28 assert(lhs + rhs == x);
29 }
30
31 #if TEST_STD_VER >= 11
32 template <class S>
test1(S && lhs,typename S::value_type rhs,const S & x)33 TEST_CONSTEXPR_CXX20 void test1(S&& lhs, typename S::value_type rhs, const S& x) {
34 assert(std::move(lhs) + rhs == x);
35 }
36 #endif
37
test()38 TEST_CONSTEXPR_CXX20 bool test() {
39 {
40 typedef std::string S;
41 test0(S(""), '1', S("1"));
42 test0(S("abcde"), '1', S("abcde1"));
43 test0(S("abcdefghij"), '1', S("abcdefghij1"));
44 test0(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
45 }
46 #if TEST_STD_VER >= 11
47 {
48 typedef std::string S;
49 test1(S(""), '1', S("1"));
50 test1(S("abcde"), '1', S("abcde1"));
51 test1(S("abcdefghij"), '1', S("abcdefghij1"));
52 test1(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
53 }
54 {
55 typedef std::basic_string<char, std::char_traits<char>,
56 min_allocator<char> >
57 S;
58 test0(S(""), '1', S("1"));
59 test0(S("abcde"), '1', S("abcde1"));
60 test0(S("abcdefghij"), '1', S("abcdefghij1"));
61 test0(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
62
63 test1(S(""), '1', S("1"));
64 test1(S("abcde"), '1', S("abcde1"));
65 test1(S("abcdefghij"), '1', S("abcdefghij1"));
66 test1(S("abcdefghijklmnopqrst"), '1', S("abcdefghijklmnopqrst1"));
67 }
68 #endif
69
70 return true;
71 }
72
main(int,char **)73 int main(int, char**) {
74 test();
75 #if TEST_STD_VER > 17
76 static_assert(test());
77 #endif
78
79 return 0;
80 }
81