xref: /llvm-project/libcxx/test/std/strings/basic.string/string.nonmembers/string_op+/string_string.pass.cpp (revision 2df59c50688c122bbcae7467d3eaf862c3ea3088)
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,
14 //             const basic_string<charT,traits,Allocator>& rhs);
15 
16 // template<class charT, class traits, class Allocator>
17 //   basic_string<charT,traits,Allocator>&&
18 //   operator+(const basic_string<charT,traits,Allocator>&& lhs,
19 //             const basic_string<charT,traits,Allocator>& rhs);
20 
21 // template<class charT, class traits, class Allocator>
22 //   basic_string<charT,traits,Allocator>&&
23 //   operator+(const basic_string<charT,traits,Allocator>& lhs,
24 //             const basic_string<charT,traits,Allocator>&& rhs);
25 
26 // template<class charT, class traits, class Allocator>
27 //   basic_string<charT,traits,Allocator>&&
28 //   operator+(const basic_string<charT,traits,Allocator>&& lhs,
29 //             const basic_string<charT,traits,Allocator>&& rhs);
30 
31 #include <string>
32 #include <utility>
33 #include <cassert>
34 
35 #include "test_macros.h"
36 #include "min_allocator.h"
37 
38 template <class S>
39 void test0(const S& lhs, const S& rhs, const S& x) {
40   assert(lhs + rhs == x);
41 }
42 
43 #if TEST_STD_VER >= 11
44 template <class S>
45 void test1(S&& lhs, const S& rhs, const S& x) {
46   assert(move(lhs) + rhs == x);
47 }
48 
49 template <class S>
50 void test2(const S& lhs, S&& rhs, const S& x) {
51   assert(lhs + move(rhs) == x);
52 }
53 
54 template <class S>
55 void test3(S&& lhs, S&& rhs, const S& x) {
56   assert(move(lhs) + move(rhs) == x);
57 }
58 
59 #endif
60 
61 int main(int, char**) {
62   {
63     typedef std::string S;
64     test0(S(""), S(""), S(""));
65     test0(S(""), S("12345"), S("12345"));
66     test0(S(""), S("1234567890"), S("1234567890"));
67     test0(S(""), S("12345678901234567890"), S("12345678901234567890"));
68     test0(S("abcde"), S(""), S("abcde"));
69     test0(S("abcde"), S("12345"), S("abcde12345"));
70     test0(S("abcde"), S("1234567890"), S("abcde1234567890"));
71     test0(S("abcde"), S("12345678901234567890"),
72           S("abcde12345678901234567890"));
73     test0(S("abcdefghij"), S(""), S("abcdefghij"));
74     test0(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
75     test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
76     test0(S("abcdefghij"), S("12345678901234567890"),
77           S("abcdefghij12345678901234567890"));
78     test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
79     test0(S("abcdefghijklmnopqrst"), S("12345"),
80           S("abcdefghijklmnopqrst12345"));
81     test0(S("abcdefghijklmnopqrst"), S("1234567890"),
82           S("abcdefghijklmnopqrst1234567890"));
83     test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"),
84           S("abcdefghijklmnopqrst12345678901234567890"));
85   }
86 #if TEST_STD_VER >= 11
87   {
88     typedef std::string S;
89     test1(S(""), S(""), S(""));
90     test1(S(""), S("12345"), S("12345"));
91     test1(S(""), S("1234567890"), S("1234567890"));
92     test1(S(""), S("12345678901234567890"), S("12345678901234567890"));
93     test1(S("abcde"), S(""), S("abcde"));
94     test1(S("abcde"), S("12345"), S("abcde12345"));
95     test1(S("abcde"), S("1234567890"), S("abcde1234567890"));
96     test1(S("abcde"), S("12345678901234567890"),
97           S("abcde12345678901234567890"));
98     test1(S("abcdefghij"), S(""), S("abcdefghij"));
99     test1(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
100     test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
101     test1(S("abcdefghij"), S("12345678901234567890"),
102           S("abcdefghij12345678901234567890"));
103     test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
104     test1(S("abcdefghijklmnopqrst"), S("12345"),
105           S("abcdefghijklmnopqrst12345"));
106     test1(S("abcdefghijklmnopqrst"), S("1234567890"),
107           S("abcdefghijklmnopqrst1234567890"));
108     test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"),
109           S("abcdefghijklmnopqrst12345678901234567890"));
110 
111     test2(S(""), S(""), S(""));
112     test2(S(""), S("12345"), S("12345"));
113     test2(S(""), S("1234567890"), S("1234567890"));
114     test2(S(""), S("12345678901234567890"), S("12345678901234567890"));
115     test2(S("abcde"), S(""), S("abcde"));
116     test2(S("abcde"), S("12345"), S("abcde12345"));
117     test2(S("abcde"), S("1234567890"), S("abcde1234567890"));
118     test2(S("abcde"), S("12345678901234567890"),
119           S("abcde12345678901234567890"));
120     test2(S("abcdefghij"), S(""), S("abcdefghij"));
121     test2(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
122     test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
123     test2(S("abcdefghij"), S("12345678901234567890"),
124           S("abcdefghij12345678901234567890"));
125     test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
126     test2(S("abcdefghijklmnopqrst"), S("12345"),
127           S("abcdefghijklmnopqrst12345"));
128     test2(S("abcdefghijklmnopqrst"), S("1234567890"),
129           S("abcdefghijklmnopqrst1234567890"));
130     test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"),
131           S("abcdefghijklmnopqrst12345678901234567890"));
132 
133     test3(S(""), S(""), S(""));
134     test3(S(""), S("12345"), S("12345"));
135     test3(S(""), S("1234567890"), S("1234567890"));
136     test3(S(""), S("12345678901234567890"), S("12345678901234567890"));
137     test3(S("abcde"), S(""), S("abcde"));
138     test3(S("abcde"), S("12345"), S("abcde12345"));
139     test3(S("abcde"), S("1234567890"), S("abcde1234567890"));
140     test3(S("abcde"), S("12345678901234567890"),
141           S("abcde12345678901234567890"));
142     test3(S("abcdefghij"), S(""), S("abcdefghij"));
143     test3(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
144     test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
145     test3(S("abcdefghij"), S("12345678901234567890"),
146           S("abcdefghij12345678901234567890"));
147     test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
148     test3(S("abcdefghijklmnopqrst"), S("12345"),
149           S("abcdefghijklmnopqrst12345"));
150     test3(S("abcdefghijklmnopqrst"), S("1234567890"),
151           S("abcdefghijklmnopqrst1234567890"));
152     test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"),
153           S("abcdefghijklmnopqrst12345678901234567890"));
154   }
155   {
156     typedef std::basic_string<char, std::char_traits<char>,
157                               min_allocator<char> >
158         S;
159     test0(S(""), S(""), S(""));
160     test0(S(""), S("12345"), S("12345"));
161     test0(S(""), S("1234567890"), S("1234567890"));
162     test0(S(""), S("12345678901234567890"), S("12345678901234567890"));
163     test0(S("abcde"), S(""), S("abcde"));
164     test0(S("abcde"), S("12345"), S("abcde12345"));
165     test0(S("abcde"), S("1234567890"), S("abcde1234567890"));
166     test0(S("abcde"), S("12345678901234567890"),
167           S("abcde12345678901234567890"));
168     test0(S("abcdefghij"), S(""), S("abcdefghij"));
169     test0(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
170     test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
171     test0(S("abcdefghij"), S("12345678901234567890"),
172           S("abcdefghij12345678901234567890"));
173     test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
174     test0(S("abcdefghijklmnopqrst"), S("12345"),
175           S("abcdefghijklmnopqrst12345"));
176     test0(S("abcdefghijklmnopqrst"), S("1234567890"),
177           S("abcdefghijklmnopqrst1234567890"));
178     test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"),
179           S("abcdefghijklmnopqrst12345678901234567890"));
180 
181     test1(S(""), S(""), S(""));
182     test1(S(""), S("12345"), S("12345"));
183     test1(S(""), S("1234567890"), S("1234567890"));
184     test1(S(""), S("12345678901234567890"), S("12345678901234567890"));
185     test1(S("abcde"), S(""), S("abcde"));
186     test1(S("abcde"), S("12345"), S("abcde12345"));
187     test1(S("abcde"), S("1234567890"), S("abcde1234567890"));
188     test1(S("abcde"), S("12345678901234567890"),
189           S("abcde12345678901234567890"));
190     test1(S("abcdefghij"), S(""), S("abcdefghij"));
191     test1(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
192     test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
193     test1(S("abcdefghij"), S("12345678901234567890"),
194           S("abcdefghij12345678901234567890"));
195     test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
196     test1(S("abcdefghijklmnopqrst"), S("12345"),
197           S("abcdefghijklmnopqrst12345"));
198     test1(S("abcdefghijklmnopqrst"), S("1234567890"),
199           S("abcdefghijklmnopqrst1234567890"));
200     test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"),
201           S("abcdefghijklmnopqrst12345678901234567890"));
202 
203     test2(S(""), S(""), S(""));
204     test2(S(""), S("12345"), S("12345"));
205     test2(S(""), S("1234567890"), S("1234567890"));
206     test2(S(""), S("12345678901234567890"), S("12345678901234567890"));
207     test2(S("abcde"), S(""), S("abcde"));
208     test2(S("abcde"), S("12345"), S("abcde12345"));
209     test2(S("abcde"), S("1234567890"), S("abcde1234567890"));
210     test2(S("abcde"), S("12345678901234567890"),
211           S("abcde12345678901234567890"));
212     test2(S("abcdefghij"), S(""), S("abcdefghij"));
213     test2(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
214     test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
215     test2(S("abcdefghij"), S("12345678901234567890"),
216           S("abcdefghij12345678901234567890"));
217     test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
218     test2(S("abcdefghijklmnopqrst"), S("12345"),
219           S("abcdefghijklmnopqrst12345"));
220     test2(S("abcdefghijklmnopqrst"), S("1234567890"),
221           S("abcdefghijklmnopqrst1234567890"));
222     test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"),
223           S("abcdefghijklmnopqrst12345678901234567890"));
224 
225     test3(S(""), S(""), S(""));
226     test3(S(""), S("12345"), S("12345"));
227     test3(S(""), S("1234567890"), S("1234567890"));
228     test3(S(""), S("12345678901234567890"), S("12345678901234567890"));
229     test3(S("abcde"), S(""), S("abcde"));
230     test3(S("abcde"), S("12345"), S("abcde12345"));
231     test3(S("abcde"), S("1234567890"), S("abcde1234567890"));
232     test3(S("abcde"), S("12345678901234567890"),
233           S("abcde12345678901234567890"));
234     test3(S("abcdefghij"), S(""), S("abcdefghij"));
235     test3(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
236     test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
237     test3(S("abcdefghij"), S("12345678901234567890"),
238           S("abcdefghij12345678901234567890"));
239     test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
240     test3(S("abcdefghijklmnopqrst"), S("12345"),
241           S("abcdefghijklmnopqrst12345"));
242     test3(S("abcdefghijklmnopqrst"), S("1234567890"),
243           S("abcdefghijklmnopqrst1234567890"));
244     test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"),
245           S("abcdefghijklmnopqrst12345678901234567890"));
246   }
247 #endif // TEST_STD_VER >= 11
248 
249   return 0;
250 }
251