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