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 // we get this comparison "for free" because the string implicitly converts to the string_view 13 14 #include <string> 15 #include <cassert> 16 17 #include "min_allocator.h" 18 19 template <class S, class SV> 20 void 21 test(const S& lhs, SV rhs, bool x) 22 { 23 assert((lhs == rhs) == x); 24 } 25 26 int main() 27 { 28 { 29 typedef std::string S; 30 typedef std::string_view SV; 31 test(S(""), SV(""), true); 32 test(S(""), SV("abcde"), false); 33 test(S(""), SV("abcdefghij"), false); 34 test(S(""), SV("abcdefghijklmnopqrst"), false); 35 test(S("abcde"), SV(""), false); 36 test(S("abcde"), SV("abcde"), true); 37 test(S("abcde"), SV("abcdefghij"), false); 38 test(S("abcde"), SV("abcdefghijklmnopqrst"), false); 39 test(S("abcdefghij"), SV(""), false); 40 test(S("abcdefghij"), SV("abcde"), false); 41 test(S("abcdefghij"), SV("abcdefghij"), true); 42 test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false); 43 test(S("abcdefghijklmnopqrst"), SV(""), false); 44 test(S("abcdefghijklmnopqrst"), SV("abcde"), false); 45 test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false); 46 test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), true); 47 } 48 #if TEST_STD_VER >= 11 49 { 50 typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S; 51 typedef std::basic_string_view<char, std::char_traits<char>> SV; 52 test(S(""), SV(""), true); 53 test(S(""), SV("abcde"), false); 54 test(S(""), SV("abcdefghij"), false); 55 test(S(""), SV("abcdefghijklmnopqrst"), false); 56 test(S("abcde"), SV(""), false); 57 test(S("abcde"), SV("abcde"), true); 58 test(S("abcde"), SV("abcdefghij"), false); 59 test(S("abcde"), SV("abcdefghijklmnopqrst"), false); 60 test(S("abcdefghij"), SV(""), false); 61 test(S("abcdefghij"), SV("abcde"), false); 62 test(S("abcdefghij"), SV("abcdefghij"), true); 63 test(S("abcdefghij"), SV("abcdefghijklmnopqrst"), false); 64 test(S("abcdefghijklmnopqrst"), SV(""), false); 65 test(S("abcdefghijklmnopqrst"), SV("abcde"), false); 66 test(S("abcdefghijklmnopqrst"), SV("abcdefghij"), false); 67 test(S("abcdefghijklmnopqrst"), SV("abcdefghijklmnopqrst"), true); 68 } 69 #endif 70 } 71