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