• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <string>
10 
11 // constexpr template<class charT, class traits, class Allocator>
12 //   bool operator>(const charT* lhs, basic_string_view<charT,traits> rhs);
13 // constexpr template<class charT, class traits, class Allocator>
14 //   bool operator>(basic_string_view<charT,traits> lhs, const charT* rhs);
15 
16 #include <string_view>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "constexpr_char_traits.h"
21 
22 template <class S>
23 void
test(const typename S::value_type * lhs,const S & rhs,bool x,bool y)24 test(const typename S::value_type* lhs, const S& rhs, bool x, bool y)
25 {
26     assert((lhs > rhs) == x);
27     assert((rhs > lhs) == y);
28 }
29 
main(int,char **)30 int main(int, char**)
31 {
32     {
33     typedef std::string_view S;
34     test("", S(""), false, false);
35     test("", S("abcde"), false, true);
36     test("", S("abcdefghij"), false, true);
37     test("", S("abcdefghijklmnopqrst"), false, true);
38     test("abcde", S(""), true, false);
39     test("abcde", S("abcde"), false, false);
40     test("abcde", S("abcdefghij"), false, true);
41     test("abcde", S("abcdefghijklmnopqrst"), false, true);
42     test("abcdefghij", S(""), true, false);
43     test("abcdefghij", S("abcde"), true, false);
44     test("abcdefghij", S("abcdefghij"), false, false);
45     test("abcdefghij", S("abcdefghijklmnopqrst"), false, true);
46     test("abcdefghijklmnopqrst", S(""), true, false);
47     test("abcdefghijklmnopqrst", S("abcde"), true, false);
48     test("abcdefghijklmnopqrst", S("abcdefghij"), true, false);
49     test("abcdefghijklmnopqrst", S("abcdefghijklmnopqrst"), false, false);
50     }
51 
52 #if TEST_STD_VER > 11
53     {
54     typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
55     constexpr SV  sv1;
56     constexpr SV  sv2 { "abcde", 5 };
57 
58     static_assert (!(sv1     > ""), "" );
59     static_assert (!(""      > sv1), "" );
60     static_assert (!(sv1     > "abcde"), "" );
61     static_assert (  "abcde" > sv1, "" );
62 
63     static_assert (  sv2      > "", "" );
64     static_assert (!(""       > sv2), "" );
65     static_assert (!(sv2      > "abcde"), "" );
66     static_assert (!("abcde"  > sv2), "" );
67     static_assert (!(sv2      > "abcde0"), "" );
68     static_assert (  "abcde0" > sv2, "" );
69     }
70 #endif
71 
72   return 0;
73 }
74