char_string.pass.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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+(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+(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(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(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('a', S(""), S("a"));
  39. test0('a', S("12345"), S("a12345"));
  40. test0('a', S("1234567890"), S("a1234567890"));
  41. test0('a', S("12345678901234567890"), S("a12345678901234567890"));
  42. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  43. test1('a', S(""), S("a"));
  44. test1('a', S("12345"), S("a12345"));
  45. test1('a', S("1234567890"), S("a1234567890"));
  46. test1('a', S("12345678901234567890"), S("a12345678901234567890"));
  47. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  48. }
  49. #if __cplusplus >= 201103L
  50. {
  51. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  52. test0('a', S(""), S("a"));
  53. test0('a', S("12345"), S("a12345"));
  54. test0('a', S("1234567890"), S("a1234567890"));
  55. test0('a', S("12345678901234567890"), S("a12345678901234567890"));
  56. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  57. test1('a', S(""), S("a"));
  58. test1('a', S("12345"), S("a12345"));
  59. test1('a', S("1234567890"), S("a1234567890"));
  60. test1('a', S("12345678901234567890"), S("a12345678901234567890"));
  61. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  62. }
  63. #endif
  64. }