• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,
14 //                  basic_string_view<charT,traits> rhs);
15 
16 #include <string_view>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 #include "constexpr_char_traits.hpp"
21 
22 template <class S>
23 void
test(const S & lhs,const S & rhs,bool x,bool y)24 test(const S& lhs, const S& rhs, bool x, bool y)
25 {
26     assert((lhs <= rhs) == x);
27     assert((rhs <= lhs) == y);
28 }
29 
main()30 int main()
31 {
32     {
33     typedef std::string_view S;
34     test(S(""), S(""), true, true);
35     test(S(""), S("abcde"), true, false);
36     test(S(""), S("abcdefghij"), true, false);
37     test(S(""), S("abcdefghijklmnopqrst"), true, false);
38     test(S("abcde"), S(""), false, true);
39     test(S("abcde"), S("abcde"), true, true);
40     test(S("abcde"), S("abcdefghij"), true, false);
41     test(S("abcde"), S("abcdefghijklmnopqrst"), true, false);
42     test(S("abcdefghij"), S(""), false, true);
43     test(S("abcdefghij"), S("abcde"), false, true);
44     test(S("abcdefghij"), S("abcdefghij"), true, true);
45     test(S("abcdefghij"), S("abcdefghijklmnopqrst"), true, false);
46     test(S("abcdefghijklmnopqrst"), S(""), false, true);
47     test(S("abcdefghijklmnopqrst"), S("abcde"), false, true);
48     test(S("abcdefghijklmnopqrst"), S("abcdefghij"), false, true);
49     test(S("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), true, true);
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 <= sv1,  "" );
59     static_assert (  sv2 <= sv2,  "" );
60 
61     static_assert (  sv1 <= sv2,  "" );
62     static_assert (!(sv2 <= sv1), "" );
63     }
64 #endif
65 }
66