string_view_string.pass.cpp (2479B)
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(SV lhs, const S& 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(SV(""), S(""), false); 32 test(SV(""), S("abcde"), true); 33 test(SV(""), S("abcdefghij"), true); 34 test(SV(""), S("abcdefghijklmnopqrst"), true); 35 test(SV("abcde"), S(""), true); 36 test(SV("abcde"), S("abcde"), false); 37 test(SV("abcde"), S("abcdefghij"), true); 38 test(SV("abcde"), S("abcdefghijklmnopqrst"), true); 39 test(SV("abcdefghij"), S(""), true); 40 test(SV("abcdefghij"), S("abcde"), true); 41 test(SV("abcdefghij"), S("abcdefghij"), false); 42 test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true); 43 test(SV("abcdefghijklmnopqrst"), S(""), true); 44 test(SV("abcdefghijklmnopqrst"), S("abcde"), true); 45 test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true); 46 test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false); 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(SV(""), S(""), false); 53 test(SV(""), S("abcde"), true); 54 test(SV(""), S("abcdefghij"), true); 55 test(SV(""), S("abcdefghijklmnopqrst"), true); 56 test(SV("abcde"), S(""), true); 57 test(SV("abcde"), S("abcde"), false); 58 test(SV("abcde"), S("abcdefghij"), true); 59 test(SV("abcde"), S("abcdefghijklmnopqrst"), true); 60 test(SV("abcdefghij"), S(""), true); 61 test(SV("abcdefghij"), S("abcde"), true); 62 test(SV("abcdefghij"), S("abcdefghij"), false); 63 test(SV("abcdefghij"), S("abcdefghijklmnopqrst"), true); 64 test(SV("abcdefghijklmnopqrst"), S(""), true); 65 test(SV("abcdefghijklmnopqrst"), S("abcde"), true); 66 test(SV("abcdefghijklmnopqrst"), S("abcdefghij"), true); 67 test(SV("abcdefghijklmnopqrst"), S("abcdefghijklmnopqrst"), false); 68 } 69 #endif 70 }