]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/basic_string/hash/debug.cc
libstdc++: Remove unnecessary uses of _GLIBCXX_USE_WCHAR_T in testsuite [PR98725]
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / hash / debug.cc
CommitLineData
50bb46e4
FD
1// Copyright (C) 2021 Free Software Foundation, Inc.
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-do run { target c++17 } }
19
20#include <debug/string>
21#include <memory_resource>
22#include <testsuite_hooks.h>
23
24// C++17 24.3.5 [basic.string.hash]
25// If S is one of these string types, SV is the corresponding string view type,
26// and s is an object of type S, then hash<S>()(s) == hash<SV>()(SV(s)).
27
28template<typename S>
29 bool
30 test(const S& s)
31 {
32 using std::hash;
33 using SV = std::basic_string_view<typename S::value_type>;
34 return hash<S>()(s) == hash<SV>()(SV(s));
35 }
36
37void
38test01()
39{
40 VERIFY( test(__gnu_debug::string("a narrow string")) );
41#if _GLIBCXX_USE_CHAR8_T
42 VERIFY( test(__gnu_debug::u8string(u8"a narrow string")) );
43#endif
44 VERIFY( test(__gnu_debug::u16string(u"a utf-16 string")) );
45 VERIFY( test(__gnu_debug::u32string(U"a utf-32 string")) );
50bb46e4 46 VERIFY( test(__gnu_debug::wstring(L"a wide string")) );
50bb46e4
FD
47}
48
49#if _GLIBCXX_USE_CHAR8_T
50void
51test02()
52{
53 using std::hash;
54 __gnu_debug::string native("a string, a string, my stringdom for a string");
55 __gnu_debug::u8string utf8(u8"a string, a string, my stringdom for a string");
56 VERIFY( hash<__gnu_debug::string>()(native) == hash<__gnu_debug::u8string>()(utf8) );
57}
58#endif
59
60int
61main()
62{
63 test01();
64#if _GLIBCXX_USE_CHAR8_T
65 test02();
66#endif
67}