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