string_string.pass.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. // <string>
  10. // template<class charT, class traits, class Allocator>
  11. // basic_string<charT,traits,Allocator>
  12. // operator+(const basic_string<charT,traits,Allocator>& lhs,
  13. // const basic_string<charT,traits,Allocator>& rhs);
  14. // template<class charT, class traits, class Allocator>
  15. // basic_string<charT,traits,Allocator>&&
  16. // operator+(const basic_string<charT,traits,Allocator>&& lhs,
  17. // const basic_string<charT,traits,Allocator>& rhs);
  18. // template<class charT, class traits, class Allocator>
  19. // basic_string<charT,traits,Allocator>&&
  20. // operator+(const basic_string<charT,traits,Allocator>& lhs,
  21. // const basic_string<charT,traits,Allocator>&& rhs);
  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. #include <string>
  27. #include <utility>
  28. #include <cassert>
  29. #include "min_allocator.h"
  30. template <class S>
  31. void
  32. test0(const S& lhs, const S& rhs, const S& x)
  33. {
  34. assert(lhs + rhs == x);
  35. }
  36. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  37. template <class S>
  38. void
  39. test1(S&& lhs, const S& rhs, const S& x)
  40. {
  41. assert(move(lhs) + rhs == x);
  42. }
  43. template <class S>
  44. void
  45. test2(const S& lhs, S&& rhs, const S& x)
  46. {
  47. assert(lhs + move(rhs) == x);
  48. }
  49. template <class S>
  50. void
  51. test3(S&& lhs, S&& rhs, const S& x)
  52. {
  53. assert(move(lhs) + move(rhs) == x);
  54. }
  55. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  56. int main()
  57. {
  58. {
  59. typedef std::string S;
  60. test0(S(""), S(""), S(""));
  61. test0(S(""), S("12345"), S("12345"));
  62. test0(S(""), S("1234567890"), S("1234567890"));
  63. test0(S(""), S("12345678901234567890"), S("12345678901234567890"));
  64. test0(S("abcde"), S(""), S("abcde"));
  65. test0(S("abcde"), S("12345"), S("abcde12345"));
  66. test0(S("abcde"), S("1234567890"), S("abcde1234567890"));
  67. test0(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
  68. test0(S("abcdefghij"), S(""), S("abcdefghij"));
  69. test0(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
  70. test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
  71. test0(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  72. test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
  73. test0(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
  74. test0(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  75. test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  76. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  77. test1(S(""), S(""), S(""));
  78. test1(S(""), S("12345"), S("12345"));
  79. test1(S(""), S("1234567890"), S("1234567890"));
  80. test1(S(""), S("12345678901234567890"), S("12345678901234567890"));
  81. test1(S("abcde"), S(""), S("abcde"));
  82. test1(S("abcde"), S("12345"), S("abcde12345"));
  83. test1(S("abcde"), S("1234567890"), S("abcde1234567890"));
  84. test1(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
  85. test1(S("abcdefghij"), S(""), S("abcdefghij"));
  86. test1(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
  87. test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
  88. test1(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  89. test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
  90. test1(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
  91. test1(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  92. test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  93. test2(S(""), S(""), S(""));
  94. test2(S(""), S("12345"), S("12345"));
  95. test2(S(""), S("1234567890"), S("1234567890"));
  96. test2(S(""), S("12345678901234567890"), S("12345678901234567890"));
  97. test2(S("abcde"), S(""), S("abcde"));
  98. test2(S("abcde"), S("12345"), S("abcde12345"));
  99. test2(S("abcde"), S("1234567890"), S("abcde1234567890"));
  100. test2(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
  101. test2(S("abcdefghij"), S(""), S("abcdefghij"));
  102. test2(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
  103. test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
  104. test2(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  105. test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
  106. test2(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
  107. test2(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  108. test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  109. test3(S(""), S(""), S(""));
  110. test3(S(""), S("12345"), S("12345"));
  111. test3(S(""), S("1234567890"), S("1234567890"));
  112. test3(S(""), S("12345678901234567890"), S("12345678901234567890"));
  113. test3(S("abcde"), S(""), S("abcde"));
  114. test3(S("abcde"), S("12345"), S("abcde12345"));
  115. test3(S("abcde"), S("1234567890"), S("abcde1234567890"));
  116. test3(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
  117. test3(S("abcdefghij"), S(""), S("abcdefghij"));
  118. test3(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
  119. test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
  120. test3(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  121. test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
  122. test3(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
  123. test3(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  124. test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  125. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  126. }
  127. #if __cplusplus >= 201103L
  128. {
  129. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  130. test0(S(""), S(""), S(""));
  131. test0(S(""), S("12345"), S("12345"));
  132. test0(S(""), S("1234567890"), S("1234567890"));
  133. test0(S(""), S("12345678901234567890"), S("12345678901234567890"));
  134. test0(S("abcde"), S(""), S("abcde"));
  135. test0(S("abcde"), S("12345"), S("abcde12345"));
  136. test0(S("abcde"), S("1234567890"), S("abcde1234567890"));
  137. test0(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
  138. test0(S("abcdefghij"), S(""), S("abcdefghij"));
  139. test0(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
  140. test0(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
  141. test0(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  142. test0(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
  143. test0(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
  144. test0(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  145. test0(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  146. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  147. test1(S(""), S(""), S(""));
  148. test1(S(""), S("12345"), S("12345"));
  149. test1(S(""), S("1234567890"), S("1234567890"));
  150. test1(S(""), S("12345678901234567890"), S("12345678901234567890"));
  151. test1(S("abcde"), S(""), S("abcde"));
  152. test1(S("abcde"), S("12345"), S("abcde12345"));
  153. test1(S("abcde"), S("1234567890"), S("abcde1234567890"));
  154. test1(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
  155. test1(S("abcdefghij"), S(""), S("abcdefghij"));
  156. test1(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
  157. test1(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
  158. test1(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  159. test1(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
  160. test1(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
  161. test1(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  162. test1(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  163. test2(S(""), S(""), S(""));
  164. test2(S(""), S("12345"), S("12345"));
  165. test2(S(""), S("1234567890"), S("1234567890"));
  166. test2(S(""), S("12345678901234567890"), S("12345678901234567890"));
  167. test2(S("abcde"), S(""), S("abcde"));
  168. test2(S("abcde"), S("12345"), S("abcde12345"));
  169. test2(S("abcde"), S("1234567890"), S("abcde1234567890"));
  170. test2(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
  171. test2(S("abcdefghij"), S(""), S("abcdefghij"));
  172. test2(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
  173. test2(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
  174. test2(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  175. test2(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
  176. test2(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
  177. test2(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  178. test2(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  179. test3(S(""), S(""), S(""));
  180. test3(S(""), S("12345"), S("12345"));
  181. test3(S(""), S("1234567890"), S("1234567890"));
  182. test3(S(""), S("12345678901234567890"), S("12345678901234567890"));
  183. test3(S("abcde"), S(""), S("abcde"));
  184. test3(S("abcde"), S("12345"), S("abcde12345"));
  185. test3(S("abcde"), S("1234567890"), S("abcde1234567890"));
  186. test3(S("abcde"), S("12345678901234567890"), S("abcde12345678901234567890"));
  187. test3(S("abcdefghij"), S(""), S("abcdefghij"));
  188. test3(S("abcdefghij"), S("12345"), S("abcdefghij12345"));
  189. test3(S("abcdefghij"), S("1234567890"), S("abcdefghij1234567890"));
  190. test3(S("abcdefghij"), S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  191. test3(S("abcdefghijklmnopqrst"), S(""), S("abcdefghijklmnopqrst"));
  192. test3(S("abcdefghijklmnopqrst"), S("12345"), S("abcdefghijklmnopqrst12345"));
  193. test3(S("abcdefghijklmnopqrst"), S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  194. test3(S("abcdefghijklmnopqrst"), S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  195. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  196. }
  197. #endif
  198. }