]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string_view/cons/wchar_t/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string_view / cons / wchar_t / 1.cc
CommitLineData
6458742a 1// { dg-do run { target c++17 } }
ca8f2cb1 2
83ffe9cd 3// Copyright (C) 2013-2023 Free Software Foundation, Inc.
ca8f2cb1
VV
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// basic_string_view constructors.
21
22#include <string_view>
42d3f743
AA
23#if __STDC_HOSTED__
24# include <string>
25#endif // HOSTED
ca8f2cb1
VV
26#include <cwchar>
27#include <testsuite_hooks.h>
28
29void
30test01()
31{
ca8f2cb1
VV
32 typedef std::wstring_view::size_type csize_type;
33
34 // basic_string_view()
35 const std::wstring_view str00{};
36 VERIFY( str00.length() == 0 );
37 VERIFY( str00.data() == nullptr );
38
39 // basic_string_view(const char*)
40 const wchar_t str_lit01[] = L"rodeo beach, marin";
41 const std::wstring_view str01{str_lit01};
42 VERIFY( str01.length() == 18 );
43 VERIFY( str01.data() == str_lit01 );
44 const std::wstring_view str02{L"baker beach, san francisco"};
45 VERIFY( str02.length() == 26 );
46
47 // basic_string_view(const string_view&)
48 std::wstring_view str04{str01};
49 VERIFY( str04.length() == str01.length() );
50 VERIFY( str04.data() == str01.data() );
51
52 // basic_string_view(const char* s)
53 csize_type len_lit01 = wcslen(str_lit01);
54 std::wstring_view str05{str_lit01, len_lit01};
55 VERIFY( str05.length() == len_lit01 );
56 VERIFY( str05.data() == str_lit01 );
57
42d3f743 58#if __STDC_HOSTED__
ca8f2cb1
VV
59 // basic_string_view(basic_string& s)
60 std::wstring istr07(10, L'z');
61 std::wstring_view str07{istr07};
62 VERIFY( str07.length() == 10 );
42d3f743 63#endif // HOSTED
ca8f2cb1
VV
64}
65
66int
67main()
68{
69 test01();
70
71 return 0;
72}