1 // { dg-options "-fchar8_t" }
2 // { dg-do run { target c++14 } }
4 // Copyright (C) 2013-2021 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 <experimental/string_view>
22 #include <testsuite_hooks.h>
27 using namespace std::experimental::literals::string_view_literals
;
29 std::experimental::string_view planet
= "Mercury"sv
;
30 std::experimental::wstring_view wplanet
= L
"Venus"sv
;
31 #ifdef _GLIBCXX_USE_CHAR8_T
32 std::experimental::u8string_view u8planet
= u8
"Mars"sv
;
34 std::experimental::string_view u8planet
= u8
"Mars"sv
;
36 std::experimental::u16string_view u16planet
= u
"Jupiter"sv
;
37 std::experimental::u32string_view u32planet
= U
"Saturn"sv
;
39 VERIFY( planet
== std::experimental::string_view("Mercury") );
40 VERIFY( wplanet
== std::experimental::wstring_view(L
"Venus") );
41 #ifdef _GLIBCXX_USE_CHAR8_T
42 VERIFY( u8planet
== std::experimental::u8string_view(u8
"Mars") );
44 VERIFY( u8planet
== std::experimental::string_view(u8
"Mars") );
46 VERIFY( u16planet
== std::experimental::u16string_view(u
"Jupiter") );
47 VERIFY( u32planet
== std::experimental::u32string_view(U
"Saturn") );
53 using namespace std::experimental::literals::string_view_literals
;
55 std::experimental::string_view planet_cratered
= "Mercury\0cratered"sv
;
56 std::experimental::wstring_view wplanet_cratered
= L
"Venus\0cratered"sv
;
57 #ifdef _GLIBCXX_USE_CHAR8_T
58 std::experimental::u8string_view u8planet_cratered
= u8
"Mars\0cratered"sv
;
60 std::experimental::string_view u8planet_cratered
= u8
"Mars\0cratered"sv
;
62 std::experimental::u16string_view u16planet_cratered
= u
"Jupiter\0cratered"sv
;
63 std::experimental::u32string_view u32planet_cratered
= U
"Saturn\0cratered"sv
;
65 VERIFY( planet_cratered
==
66 std::experimental::string_view("Mercury\0cratered", 16) );
67 VERIFY( wplanet_cratered
==
68 std::experimental::wstring_view(L
"Venus\0cratered", 14) );
69 #ifdef _GLIBCXX_USE_CHAR8_T
70 VERIFY( u8planet_cratered
==
71 std::experimental::u8string_view(u8
"Mars\0cratered", 13) );
73 VERIFY( u8planet_cratered
==
74 std::experimental::string_view(u8
"Mars\0cratered", 13) );
76 VERIFY( u16planet_cratered
==
77 std::experimental::u16string_view(u
"Jupiter\0cratered", 16) );
78 VERIFY( u32planet_cratered
==
79 std::experimental::u32string_view(U
"Saturn\0cratered", 15) );