1// Components for manipulating sequences of characters -*- C++ -*-
2
3// Copyright (C) 1997-2022 Free Software Foundation, Inc.
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// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file include/string
26 * This is a Standard C++ Library header.
27 */
28
29//
30// ISO C++ 14882: 21 Strings library
31//
32
33#ifndef _GLIBCXX_STRING
34#define _GLIBCXX_STRING 1
35
36#pragma GCC system_header
37
38#include <bits/c++config.h>
39#include <bits/stringfwd.h>
40#include <bits/char_traits.h> // NB: In turn includes stl_algobase.h
41#include <bits/allocator.h>
42#include <bits/cpp_type_traits.h>
43#include <bits/localefwd.h> // For operators >>, <<, and getline.
44#include <bits/ostream_insert.h>
45#include <bits/stl_iterator_base_types.h>
46#include <bits/stl_iterator_base_funcs.h>
47#include <bits/stl_iterator.h>
48#include <bits/stl_function.h> // For less
49#include <ext/numeric_traits.h>
50#include <bits/stl_algobase.h>
51#include <bits/refwrap.h>
52#include <bits/range_access.h>
53#include <bits/basic_string.h>
54#include <bits/basic_string.tcc>
55
56#if __cplusplus >= 201703L && _GLIBCXX_USE_CXX11_ABI
57namespace std _GLIBCXX_VISIBILITY(default)
58{
59_GLIBCXX_BEGIN_NAMESPACE_VERSION
60 namespace pmr {
61 template<typename _Tp> class polymorphic_allocator;
62 template<typename _CharT, typename _Traits = char_traits<_CharT>>
63 using basic_string = std::basic_string<_CharT, _Traits,
64 polymorphic_allocator<_CharT>>;
65 using string = basic_string<char>;
66#ifdef _GLIBCXX_USE_CHAR8_T
67 using u8string = basic_string<char8_t>;
68#endif
69 using u16string = basic_string<char16_t>;
70 using u32string = basic_string<char32_t>;
71 using wstring = basic_string<wchar_t>;
72 } // namespace pmr
73
74 template<typename _Str>
75 struct __hash_string_base
76 : public __hash_base<size_t, _Str>
77 {
78 size_t
79 operator()(const _Str& __s) const noexcept
80 { return hash<basic_string_view<typename _Str::value_type>>{}(__s); }
81 };
82
83 template<>
84 struct hash<pmr::string>
85 : public __hash_string_base<pmr::string>
86 { };
87#ifdef _GLIBCXX_USE_CHAR8_T
88 template<>
89 struct hash<pmr::u8string>
90 : public __hash_string_base<pmr::u8string>
91 { };
92#endif
93 template<>
94 struct hash<pmr::u16string>
95 : public __hash_string_base<pmr::u16string>
96 { };
97 template<>
98 struct hash<pmr::u32string>
99 : public __hash_string_base<pmr::u32string>
100 { };
101 template<>
102 struct hash<pmr::wstring>
103 : public __hash_string_base<pmr::wstring>
104 { };
105
106_GLIBCXX_END_NAMESPACE_VERSION
107} // namespace std
108#endif // C++17
109
110#if __cplusplus > 201703L
111namespace std _GLIBCXX_VISIBILITY(default)
112{
113_GLIBCXX_BEGIN_NAMESPACE_VERSION
114
115#define __cpp_lib_erase_if 202002L
116
117 template<typename _CharT, typename _Traits, typename _Alloc,
118 typename _Predicate>
119 _GLIBCXX20_CONSTEXPR
120 inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
121 erase_if(basic_string<_CharT, _Traits, _Alloc>& __cont, _Predicate __pred)
122 {
123 using namespace __gnu_cxx;
124 const auto __osz = __cont.size();
125 const auto __end = __cont.end();
126 auto __removed = std::__remove_if(__cont.begin(), __end,
127 __ops::__pred_iter(std::ref(__pred)));
128 __cont.erase(__removed, __end);
129 return __osz - __cont.size();
130 }
131
132 template<typename _CharT, typename _Traits, typename _Alloc, typename _Up>
133 _GLIBCXX20_CONSTEXPR
134 inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
135 erase(basic_string<_CharT, _Traits, _Alloc>& __cont, const _Up& __value)
136 {
137 using namespace __gnu_cxx;
138 const auto __osz = __cont.size();
139 const auto __end = __cont.end();
140 auto __removed = std::__remove_if(__cont.begin(), __end,
141 __ops::__iter_equals_val(__value));
142 __cont.erase(__removed, __end);
143 return __osz - __cont.size();
144 }
145_GLIBCXX_END_NAMESPACE_VERSION
146} // namespace std
147#endif // C++20
148
149#endif /* _GLIBCXX_STRING */
150