string_string_view.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(const S& lhs, SV 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(S(""), SV(""), false);
  26. test(S(""), SV("abcde"), true);
  27. test(S(""), SV("abcdefghij"), true);
  28. test(S(""), SV("abcdefghijklmnopqrst"), true);
  29. test(S("abcde"), SV(""), false);
  30. test(S("abcde"), SV("abcde"), false);
  31. test(S("abcde"), SV("abcdefghij"), true);
  32. test(S("abcde"), SV("abcdefghijklmnopqrst"), true);
  33. test(S("abcdefghij"), SV(""), false);
  34. test(S("abcdefghij"), SV("abcde"), false);
  35. test(S("abcdefghij"), SV("abcdefghij"), false);
  36. test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true);
  37. test(S("abcdefghijklmnopqrst"), SV(""), false);
  38. test(S("abcdefghijklmnopqrst"), SV("abcde"), false);
  39. test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false);
  40. test(S("abcdefghijklmnopqrst"), SV("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(S(""), SV(""), false);
  47. test(S(""), SV("abcde"), true);
  48. test(S(""), SV("abcdefghij"), true);
  49. test(S(""), SV("abcdefghijklmnopqrst"), true);
  50. test(S("abcde"), SV(""), false);
  51. test(S("abcde"), SV("abcde"), false);
  52. test(S("abcde"), SV("abcdefghij"), true);
  53. test(S("abcde"), SV("abcdefghijklmnopqrst"), true);
  54. test(S("abcdefghij"), SV(""), false);
  55. test(S("abcdefghij"), SV("abcde"), false);
  56. test(S("abcdefghij"), SV("abcdefghij"), false);
  57. test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), true);
  58. test(S("abcdefghijklmnopqrst"), SV(""), false);
  59. test(S("abcdefghijklmnopqrst"), SV("abcde"), false);
  60. test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false);
  61. test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), false);
  62. }
  63. #endif
  64. }