opge.string_view.pointer.pass.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // constexpr bool operator>=(const charT* lhs, basic_string_wiew<charT,traits> rhs);
  12. // template<class charT, class traits, class Allocator>
  13. // constexpr bool operator>=(basic_string_wiew<charT,traits> lhs, const charT* rhs);
  14. #include <string_view>
  15. #include <cassert>
  16. #include "constexpr_char_traits.hpp"
  17. template <class S>
  18. void
  19. test(const typename S::value_type* lhs, const S& rhs, bool x, bool y)
  20. {
  21. assert((lhs >= rhs) == x);
  22. assert((rhs >= lhs) == y);
  23. }
  24. int main()
  25. {
  26. {
  27. typedef std::string_view S;
  28. test("", S(""), true, true);
  29. test("", S("abcde"), false, true);
  30. test("", S("abcdefghij"), false, true);
  31. test("", S("abcdefghijklmnopqrst"), false, true);
  32. test("abcde", S(""), true, false);
  33. test("abcde", S("abcde"), true, true);
  34. test("abcde", S("abcdefghij"), false, true);
  35. test("abcde", S("abcdefghijklmnopqrst"), false, true);
  36. test("abcdefghij", S(""), true, false);
  37. test("abcdefghij", S("abcde"), true, false);
  38. test("abcdefghij", S("abcdefghij"), true, true);
  39. test("abcdefghij", S("abcdefghijklmnopqrst"), false, true);
  40. test("abcdefghijklmnopqrst", S(""), true, false);
  41. test("abcdefghijklmnopqrst", S("abcde"), true, false);
  42. test("abcdefghijklmnopqrst", S("abcdefghij"), true, false);
  43. test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), true, true);
  44. }
  45. #if _LIBCPP_STD_VER > 11
  46. {
  47. typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
  48. constexpr SV sv1;
  49. constexpr SV sv2 { "abcde", 5 };
  50. static_assert ( sv1 >= "", "" );
  51. static_assert ( "" >= sv1, "" );
  52. static_assert (!(sv1 >= "abcde"), "" );
  53. static_assert ( "abcde" >= sv1, "" );
  54. static_assert ( sv2 >= "", "" );
  55. static_assert (!("" >= sv2), "" );
  56. static_assert ( sv2 >= "abcde", "" );
  57. static_assert ( "abcde" >= sv2, "" );
  58. static_assert (!(sv2 >= "abcde0"), "" );
  59. static_assert ( "abcde0" >= sv2, "" );
  60. }
  61. #endif
  62. }