pointer_string.pass.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 charT* lhs, const basic_string<charT,traits,Allocator>& rhs);
  13. // template<class charT, class traits, class Allocator>
  14. // basic_string<charT,traits,Allocator>&&
  15. // operator+(const charT* lhs, basic_string<charT,traits,Allocator>&& rhs);
  16. #include <string>
  17. #include <utility>
  18. #include <cassert>
  19. #include "min_allocator.h"
  20. template <class S>
  21. void
  22. test0(const typename S::value_type* lhs, const S& rhs, const S& x)
  23. {
  24. assert(lhs + rhs == x);
  25. }
  26. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  27. template <class S>
  28. void
  29. test1(const typename S::value_type* lhs, S&& rhs, const S& x)
  30. {
  31. assert(lhs + move(rhs) == x);
  32. }
  33. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  34. int main()
  35. {
  36. {
  37. typedef std::string S;
  38. test0("", S(""), S(""));
  39. test0("", S("12345"), S("12345"));
  40. test0("", S("1234567890"), S("1234567890"));
  41. test0("", S("12345678901234567890"), S("12345678901234567890"));
  42. test0("abcde", S(""), S("abcde"));
  43. test0("abcde", S("12345"), S("abcde12345"));
  44. test0("abcde", S("1234567890"), S("abcde1234567890"));
  45. test0("abcde", S("12345678901234567890"), S("abcde12345678901234567890"));
  46. test0("abcdefghij", S(""), S("abcdefghij"));
  47. test0("abcdefghij", S("12345"), S("abcdefghij12345"));
  48. test0("abcdefghij", S("1234567890"), S("abcdefghij1234567890"));
  49. test0("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  50. test0("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst"));
  51. test0("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345"));
  52. test0("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  53. test0("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  54. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  55. test1("", S(""), S(""));
  56. test1("", S("12345"), S("12345"));
  57. test1("", S("1234567890"), S("1234567890"));
  58. test1("", S("12345678901234567890"), S("12345678901234567890"));
  59. test1("abcde", S(""), S("abcde"));
  60. test1("abcde", S("12345"), S("abcde12345"));
  61. test1("abcde", S("1234567890"), S("abcde1234567890"));
  62. test1("abcde", S("12345678901234567890"), S("abcde12345678901234567890"));
  63. test1("abcdefghij", S(""), S("abcdefghij"));
  64. test1("abcdefghij", S("12345"), S("abcdefghij12345"));
  65. test1("abcdefghij", S("1234567890"), S("abcdefghij1234567890"));
  66. test1("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  67. test1("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst"));
  68. test1("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345"));
  69. test1("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  70. test1("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  71. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  72. }
  73. #if __cplusplus >= 201103L
  74. {
  75. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  76. test0("", S(""), S(""));
  77. test0("", S("12345"), S("12345"));
  78. test0("", S("1234567890"), S("1234567890"));
  79. test0("", S("12345678901234567890"), S("12345678901234567890"));
  80. test0("abcde", S(""), S("abcde"));
  81. test0("abcde", S("12345"), S("abcde12345"));
  82. test0("abcde", S("1234567890"), S("abcde1234567890"));
  83. test0("abcde", S("12345678901234567890"), S("abcde12345678901234567890"));
  84. test0("abcdefghij", S(""), S("abcdefghij"));
  85. test0("abcdefghij", S("12345"), S("abcdefghij12345"));
  86. test0("abcdefghij", S("1234567890"), S("abcdefghij1234567890"));
  87. test0("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  88. test0("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst"));
  89. test0("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345"));
  90. test0("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  91. test0("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  92. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  93. test1("", S(""), S(""));
  94. test1("", S("12345"), S("12345"));
  95. test1("", S("1234567890"), S("1234567890"));
  96. test1("", S("12345678901234567890"), S("12345678901234567890"));
  97. test1("abcde", S(""), S("abcde"));
  98. test1("abcde", S("12345"), S("abcde12345"));
  99. test1("abcde", S("1234567890"), S("abcde1234567890"));
  100. test1("abcde", S("12345678901234567890"), S("abcde12345678901234567890"));
  101. test1("abcdefghij", S(""), S("abcdefghij"));
  102. test1("abcdefghij", S("12345"), S("abcdefghij12345"));
  103. test1("abcdefghij", S("1234567890"), S("abcdefghij1234567890"));
  104. test1("abcdefghij", S("12345678901234567890"), S("abcdefghij12345678901234567890"));
  105. test1("abcdefghijklmnopqrst", S(""), S("abcdefghijklmnopqrst"));
  106. test1("abcdefghijklmnopqrst", S("12345"), S("abcdefghijklmnopqrst12345"));
  107. test1("abcdefghijklmnopqrst", S("1234567890"), S("abcdefghijklmnopqrst1234567890"));
  108. test1("abcdefghijklmnopqrst", S("12345678901234567890"), S("abcdefghijklmnopqrst12345678901234567890"));
  109. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  110. }
  111. #endif
  112. }