opne.string_view.pointer.pass.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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>
  11. // constexpr bool operator!=(basic_string_view<charT,traits> lhs, const charT* rhs);
  12. // template<class charT, class traits>
  13. // constexpr bool operator!=(const charT* lhs, basic_string_view<charT,traits> rhs);
  14. #include <string_view>
  15. #include <cassert>
  16. #include "constexpr_char_traits.hpp"
  17. template <class S>
  18. void
  19. test(S lhs, const typename S::value_type* rhs, bool x)
  20. {
  21. assert((lhs != rhs) == x);
  22. assert((rhs != lhs) == x);
  23. }
  24. int main()
  25. {
  26. {
  27. typedef std::string_view S;
  28. test(S(""), "", false);
  29. test(S(""), "abcde", true);
  30. test(S(""), "abcdefghij", true);
  31. test(S(""), "abcdefghijklmnopqrst", true);
  32. test(S("abcde"), "", true);
  33. test(S("abcde"), "abcde", false);
  34. test(S("abcde"), "abcdefghij", true);
  35. test(S("abcde"), "abcdefghijklmnopqrst", true);
  36. test(S("abcdefghij"), "", true);
  37. test(S("abcdefghij"), "abcde", true);
  38. test(S("abcdefghij"), "abcdefghij", false);
  39. test(S("abcdefghij"), "abcdefghijklmnopqrst", true);
  40. test(S("abcdefghijklmnopqrst"), "", true);
  41. test(S("abcdefghijklmnopqrst"), "abcde", true);
  42. test(S("abcdefghijklmnopqrst"), "abcdefghij", true);
  43. test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", false);
  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 != "abcde"), "" );
  55. static_assert (!("abcde" != sv2), "" );
  56. static_assert ( sv2 != "abcde0", "" );
  57. static_assert ( "abcde0" != sv2, "" );
  58. }
  59. #endif
  60. }