opeq.string_view.pointer.pass.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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(""), "", true);
  29. test(S(""), "abcde", false);
  30. test(S(""), "abcdefghij", false);
  31. test(S(""), "abcdefghijklmnopqrst", false);
  32. test(S("abcde"), "", false);
  33. test(S("abcde"), "abcde", true);
  34. test(S("abcde"), "abcdefghij", false);
  35. test(S("abcde"), "abcdefghijklmnopqrst", false);
  36. test(S("abcdefghij"), "", false);
  37. test(S("abcdefghij"), "abcde", false);
  38. test(S("abcdefghij"), "abcdefghij", true);
  39. test(S("abcdefghij"), "abcdefghijklmnopqrst", false);
  40. test(S("abcdefghijklmnopqrst"), "", false);
  41. test(S("abcdefghijklmnopqrst"), "abcde", false);
  42. test(S("abcdefghijklmnopqrst"), "abcdefghij", false);
  43. test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", 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 == "abcde", "" );
  55. static_assert ( "abcde" == sv2, "" );
  56. static_assert (!(sv2 == "abcde0"), "" );
  57. static_assert (!("abcde0" == sv2), "" );
  58. }
  59. #endif
  60. }