string_view_string.pass.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // we get this comparison "for free" because the string implicitly converts to the string_view
  11. #include <string>
  12. #include <cassert>
  13. #include "min_allocator.h"
  14. template <class S, class SV>
  15. void
  16. test(SV lhs, const S& rhs, bool x)
  17. {
  18. assert((lhs != rhs) == x);
  19. }
  20. int main()
  21. {
  22. {
  23. typedef std::string S;
  24. typedef std::string_view SV;
  25. test(SV(""), S(""), false);
  26. test(SV(""), S("abcde"), true);
  27. test(SV(""), S("abcdefghij"), true);
  28. test(SV(""), S("abcdefghijklmnopqrst"), true);
  29. test(SV("abcde"), S(""), true);
  30. test(SV("abcde"), S("abcde"), false);
  31. test(SV("abcde"), S("abcdefghij"), true);
  32. test(SV("abcde"), S("abcdefghijklmnopqrst"), true);
  33. test(SV("abcdefghij"), S(""), true);
  34. test(SV("abcdefghij"), S("abcde"), true);
  35. test(SV("abcdefghij"), S("abcdefghij"), false);
  36. test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true);
  37. test(SV("abcdefghijklmnopqrst"), S(""), true);
  38. test(SV("abcdefghijklmnopqrst"), S("abcde"), true);
  39. test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true);
  40. test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
  41. }
  42. #if TEST_STD_VER >= 11
  43. {
  44. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  45. typedef std::basic_string_view<char, std::char_traits<char>> SV;
  46. test(SV(""), S(""), false);
  47. test(SV(""), S("abcde"), true);
  48. test(SV(""), S("abcdefghij"), true);
  49. test(SV(""), S("abcdefghijklmnopqrst"), true);
  50. test(SV("abcde"), S(""), true);
  51. test(SV("abcde"), S("abcde"), false);
  52. test(SV("abcde"), S("abcdefghij"), true);
  53. test(SV("abcde"), S("abcdefghijklmnopqrst"), true);
  54. test(SV("abcdefghij"), S(""), true);
  55. test(SV("abcdefghij"), S("abcde"), true);
  56. test(SV("abcdefghij"), S("abcdefghij"), false);
  57. test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true);
  58. test(SV("abcdefghijklmnopqrst"), S(""), true);
  59. test(SV("abcdefghijklmnopqrst"), S("abcde"), true);
  60. test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true);
  61. test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false);
  62. }
  63. #endif
  64. }