summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/21_strings/basic_string/hash/debug.cc
blob: 706da53db81111f5a379059db07ee372b99d1dca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (C) 2021-2023 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// { dg-do run { target c++17 } }

#include <debug/string>
#include <memory_resource>
#include <testsuite_hooks.h>

// C++17 24.3.5 [basic.string.hash]
// If S is one of these string types, SV is the corresponding string view type,
// and s is an object of type S, then hash<S>()(s) == hash<SV>()(SV(s)).

template<typename S>
  bool
  test(const S& s)
  {
    using std::hash;
    using SV = std::basic_string_view<typename S::value_type>;
    return hash<S>()(s) == hash<SV>()(SV(s));
  }

void
test01()
{
  VERIFY( test(__gnu_debug::string("a narrow string")) );
#if _GLIBCXX_USE_CHAR8_T
  VERIFY( test(__gnu_debug::u8string(u8"a narrow string")) );
#endif
  VERIFY( test(__gnu_debug::u16string(u"a utf-16 string")) );
  VERIFY( test(__gnu_debug::u32string(U"a utf-32 string")) );
  VERIFY( test(__gnu_debug::wstring(L"a wide string")) );
}

#if _GLIBCXX_USE_CHAR8_T
void
test02()
{
  using std::hash;
  __gnu_debug::string native("a string, a string, my stringdom for a string");
  __gnu_debug::u8string utf8(u8"a string, a string, my stringdom for a string");
  VERIFY( hash<__gnu_debug::string>()(native) == hash<__gnu_debug::u8string>()(utf8) );
}
#endif

int
main()
{
  test01();
#if _GLIBCXX_USE_CHAR8_T
  test02();
#endif
}