1 // { dg-options "-std=gnu++17" }
2 // { dg-do run { target c++17 } }
4 // Copyright (C) 2013-2020 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 #include <string_view>
22 #include <testsuite_hooks.h>
24 #ifdef _GLIBCXX_USE_CHAR8_T
25 using std::u8string_view
;
27 using u8string_view
= std::string_view
;
33 using namespace std::literals::string_view_literals
;
35 std::string_view planet
= "Mercury"sv
;
36 #ifdef _GLIBCXX_USE_WCHAR_T
37 std::wstring_view wplanet
= L
"Venus"sv
;
39 u8string_view u8planet
= u8
"Mars"sv
;
40 std::u16string_view u16planet
= u
"Jupiter"sv
;
41 std::u32string_view u32planet
= U
"Saturn"sv
;
43 VERIFY( planet
== std::string_view("Mercury") );
44 #ifdef _GLIBCXX_USE_WCHAR_T
45 VERIFY( wplanet
== std::wstring_view(L
"Venus") );
47 VERIFY( u8planet
== u8string_view(u8
"Mars") );
48 VERIFY( u16planet
== std::u16string_view(u
"Jupiter") );
49 VERIFY( u32planet
== std::u32string_view(U
"Saturn") );
55 using namespace std::literals::string_view_literals
;
57 std::string_view planet_cratered
= "Mercury\0cratered"sv
;
58 #ifdef _GLIBCXX_USE_WCHAR_T
59 std::wstring_view wplanet_cratered
= L
"Venus\0cratered"sv
;
61 u8string_view u8planet_cratered
= u8
"Mars\0cratered"sv
;
62 std::u16string_view u16planet_cratered
= u
"Jupiter\0cratered"sv
;
63 std::u32string_view u32planet_cratered
= U
"Saturn\0cratered"sv
;
65 VERIFY( planet_cratered
== std::string_view("Mercury\0cratered", 16) );
66 #ifdef _GLIBCXX_USE_WCHAR_T
67 VERIFY( wplanet_cratered
== std::wstring_view(L
"Venus\0cratered", 14) );
69 VERIFY( u8planet_cratered
== u8string_view(u8
"Mars\0cratered", 13) );
70 VERIFY( u16planet_cratered
== std::u16string_view(u
"Jupiter\0cratered", 16) );
71 VERIFY( u32planet_cratered
== std::u32string_view(U
"Saturn\0cratered", 15) );