1 // -*- C++ -*- 2 //===----------------------------------------------------------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 // UNSUPPORTED: c++98, c++03, c++11 12 // UNSUPPORTED: clang-3.3, clang-3.4, clang-3.5, clang-3.6, clang-3.7, clang-3.8, clang-3.9 13 // UNSUPPORTED: apple-clang-6, apple-clang-7, apple-clang-8 14 // Note: libc++ supports string_view before C++17, but literals were introduced in C++14 15 16 #include <string_view> 17 #include <cassert> 18 19 #include "test_macros.h" 20 21 int main() 22 { 23 using namespace std::literals::string_view_literals; 24 25 static_assert ( std::is_same<decltype( "Hi"sv), std::string_view>::value, "" ); 26 // This is changed by P0482 to return a std::u8string - re-enable when we implement that. 27 #if TEST_STD_VER <= 17 28 static_assert ( std::is_same<decltype( u8"Hi"sv), std::string_view>::value, "" ); 29 #endif 30 static_assert ( std::is_same<decltype( L"Hi"sv), std::wstring_view>::value, "" ); 31 static_assert ( std::is_same<decltype( u"Hi"sv), std::u16string_view>::value, "" ); 32 static_assert ( std::is_same<decltype( U"Hi"sv), std::u32string_view>::value, "" ); 33 34 std::string_view foo; 35 std::wstring_view Lfoo; 36 std::u16string_view ufoo; 37 std::u32string_view Ufoo; 38 39 foo = ""sv; assert( foo.size() == 0); 40 // This is changed by P0482 to return a std::u8string - re-enable when we implement that. 41 #if TEST_STD_VER <= 17 42 foo = u8""sv; assert( foo.size() == 0); 43 #endif 44 Lfoo = L""sv; assert(Lfoo.size() == 0); 45 ufoo = u""sv; assert(ufoo.size() == 0); 46 Ufoo = U""sv; assert(Ufoo.size() == 0); 47 48 foo = " "sv; assert( foo.size() == 1); 49 // This is changed by P0482 to return a std::u8string - re-enable when we implement that. 50 #if TEST_STD_VER <= 17 51 foo = u8" "sv; assert( foo.size() == 1); 52 #endif 53 Lfoo = L" "sv; assert(Lfoo.size() == 1); 54 ufoo = u" "sv; assert(ufoo.size() == 1); 55 Ufoo = U" "sv; assert(Ufoo.size() == 1); 56 57 foo = "ABC"sv; assert( foo == "ABC"); assert( foo == std::string_view ( "ABC")); 58 // This is changed by P0482 to return a std::u8string - re-enable when we implement that. 59 #if TEST_STD_VER <= 17 60 foo = u8"ABC"sv; assert( foo == u8"ABC"); assert( foo == std::string_view (u8"ABC")); 61 #endif 62 Lfoo = L"ABC"sv; assert(Lfoo == L"ABC"); assert(Lfoo == std::wstring_view ( L"ABC")); 63 ufoo = u"ABC"sv; assert(ufoo == u"ABC"); assert(ufoo == std::u16string_view( u"ABC")); 64 Ufoo = U"ABC"sv; assert(Ufoo == U"ABC"); assert(Ufoo == std::u32string_view( U"ABC")); 65 66 static_assert( "ABC"sv.size() == 3, ""); 67 // This is changed by P0482 to return a std::u8string - re-enable when we implement that. 68 #if TEST_STD_VER <= 17 69 static_assert(u8"ABC"sv.size() == 3, ""); 70 #endif 71 static_assert( L"ABC"sv.size() == 3, ""); 72 static_assert( u"ABC"sv.size() == 3, ""); 73 static_assert( U"ABC"sv.size() == 3, ""); 74 75 static_assert(noexcept( "ABC"sv), ""); 76 // This is changed by P0482 to return a std::u8string - re-enable when we implement that. 77 #if TEST_STD_VER <= 17 78 static_assert(noexcept(u8"ABC"sv), ""); 79 #endif 80 static_assert(noexcept( L"ABC"sv), ""); 81 static_assert(noexcept( u"ABC"sv), ""); 82 static_assert(noexcept( U"ABC"sv), ""); 83 } 84