1 // { dg-do run { target c++14 } } 2 3 // Copyright (C) 2013-2021 Free Software Foundation, Inc. 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 3, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // You should have received a copy of the GNU General Public License along 17 // with this library; see the file COPYING3. If not see 18 // <http://www.gnu.org/licenses/>. 19 20 #include <experimental/string_view> 21 #include <testsuite_hooks.h> 22 23 #ifdef _GLIBCXX_USE_CHAR8_T 24 using std::experimental::u8string_view; 25 #else 26 using u8string_view = std::experimental::string_view; 27 #endif 28 29 void test01()30test01() 31 { 32 using namespace std::experimental::literals::string_view_literals; 33 34 std::experimental::string_view planet = "Mercury"sv; 35 #ifdef _GLIBCXX_USE_WCHAR_T 36 std::experimental::wstring_view wplanet = L"Venus"sv; 37 #endif 38 u8string_view u8planet = u8"Mars"sv; 39 std::experimental::u16string_view u16planet = u"Jupiter"sv; 40 std::experimental::u32string_view u32planet = U"Saturn"sv; 41 42 VERIFY( planet == std::experimental::string_view("Mercury") ); 43 #ifdef _GLIBCXX_USE_WCHAR_T 44 VERIFY( wplanet == std::experimental::wstring_view(L"Venus") ); 45 #endif 46 VERIFY( u8planet == u8string_view(u8"Mars") ); 47 VERIFY( u16planet == std::experimental::u16string_view(u"Jupiter") ); 48 VERIFY( u32planet == std::experimental::u32string_view(U"Saturn") ); 49 } 50 51 void test02()52test02() 53 { 54 using namespace std::experimental::literals::string_view_literals; 55 56 std::experimental::string_view planet_cratered = "Mercury\0cratered"sv; 57 #ifdef _GLIBCXX_USE_WCHAR_T 58 std::experimental::wstring_view wplanet_cratered = L"Venus\0cratered"sv; 59 #endif 60 u8string_view u8planet_cratered = u8"Mars\0cratered"sv; 61 std::experimental::u16string_view u16planet_cratered = u"Jupiter\0cratered"sv; 62 std::experimental::u32string_view u32planet_cratered = U"Saturn\0cratered"sv; 63 64 VERIFY( planet_cratered == 65 std::experimental::string_view("Mercury\0cratered", 16) ); 66 #ifdef _GLIBCXX_USE_WCHAR_T 67 VERIFY( wplanet_cratered == 68 std::experimental::wstring_view(L"Venus\0cratered", 14) ); 69 #endif 70 VERIFY( u8planet_cratered == u8string_view(u8"Mars\0cratered", 13) ); 71 VERIFY( u16planet_cratered == 72 std::experimental::u16string_view(u"Jupiter\0cratered", 16) ); 73 VERIFY( u32planet_cratered == 74 std::experimental::u32string_view(U"Saturn\0cratered", 15) ); 75 } 76 77 int main()78main() 79 { 80 test01(); 81 test02(); 82 } 83