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