11debfc3dSmrg// Components for manipulating sequences of characters -*- C++ -*- 21debfc3dSmrg 3*8feb0f0bSmrg// Copyright (C) 1997-2020 Free Software Foundation, Inc. 41debfc3dSmrg// 51debfc3dSmrg// This file is part of the GNU ISO C++ Library. This library is free 61debfc3dSmrg// software; you can redistribute it and/or modify it under the 71debfc3dSmrg// terms of the GNU General Public License as published by the 81debfc3dSmrg// Free Software Foundation; either version 3, or (at your option) 91debfc3dSmrg// any later version. 101debfc3dSmrg 111debfc3dSmrg// This library is distributed in the hope that it will be useful, 121debfc3dSmrg// but WITHOUT ANY WARRANTY; without even the implied warranty of 131debfc3dSmrg// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 141debfc3dSmrg// GNU General Public License for more details. 151debfc3dSmrg 161debfc3dSmrg// Under Section 7 of GPL version 3, you are granted additional 171debfc3dSmrg// permissions described in the GCC Runtime Library Exception, version 181debfc3dSmrg// 3.1, as published by the Free Software Foundation. 191debfc3dSmrg 201debfc3dSmrg// You should have received a copy of the GNU General Public License and 211debfc3dSmrg// a copy of the GCC Runtime Library Exception along with this program; 221debfc3dSmrg// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 231debfc3dSmrg// <http://www.gnu.org/licenses/>. 241debfc3dSmrg 251debfc3dSmrg/** @file include/string 261debfc3dSmrg * This is a Standard C++ Library header. 271debfc3dSmrg */ 281debfc3dSmrg 291debfc3dSmrg// 301debfc3dSmrg// ISO C++ 14882: 21 Strings library 311debfc3dSmrg// 321debfc3dSmrg 331debfc3dSmrg#ifndef _GLIBCXX_STRING 341debfc3dSmrg#define _GLIBCXX_STRING 1 351debfc3dSmrg 361debfc3dSmrg#pragma GCC system_header 371debfc3dSmrg 381debfc3dSmrg#include <bits/c++config.h> 391debfc3dSmrg#include <bits/stringfwd.h> 401debfc3dSmrg#include <bits/char_traits.h> // NB: In turn includes stl_algobase.h 411debfc3dSmrg#include <bits/allocator.h> 421debfc3dSmrg#include <bits/cpp_type_traits.h> 431debfc3dSmrg#include <bits/localefwd.h> // For operators >>, <<, and getline. 441debfc3dSmrg#include <bits/ostream_insert.h> 451debfc3dSmrg#include <bits/stl_iterator_base_types.h> 461debfc3dSmrg#include <bits/stl_iterator_base_funcs.h> 471debfc3dSmrg#include <bits/stl_iterator.h> 481debfc3dSmrg#include <bits/stl_function.h> // For less 491debfc3dSmrg#include <ext/numeric_traits.h> 501debfc3dSmrg#include <bits/stl_algobase.h> 51c0a68be4Smrg#if __cplusplus > 201703L 52c0a68be4Smrg# include <bits/stl_algo.h> // For remove and remove_if 53c0a68be4Smrg#endif // C++20 541debfc3dSmrg#include <bits/range_access.h> 551debfc3dSmrg#include <bits/basic_string.h> 561debfc3dSmrg#include <bits/basic_string.tcc> 571debfc3dSmrg 58c0a68be4Smrg#if __cplusplus >= 201703L && _GLIBCXX_USE_CXX11_ABI 59c0a68be4Smrgnamespace std _GLIBCXX_VISIBILITY(default) 60c0a68be4Smrg{ 61c0a68be4Smrg_GLIBCXX_BEGIN_NAMESPACE_VERSION 62c0a68be4Smrg namespace pmr { 63c0a68be4Smrg template<typename _Tp> class polymorphic_allocator; 64c0a68be4Smrg template<typename _CharT, typename _Traits = char_traits<_CharT>> 65c0a68be4Smrg using basic_string = std::basic_string<_CharT, _Traits, 66c0a68be4Smrg polymorphic_allocator<_CharT>>; 67c0a68be4Smrg using string = basic_string<char>; 68c0a68be4Smrg#ifdef _GLIBCXX_USE_CHAR8_T 69c0a68be4Smrg using u8string = basic_string<char8_t>; 70c0a68be4Smrg#endif 71c0a68be4Smrg using u16string = basic_string<char16_t>; 72c0a68be4Smrg using u32string = basic_string<char32_t>; 73c0a68be4Smrg#ifdef _GLIBCXX_USE_WCHAR_T 74c0a68be4Smrg using wstring = basic_string<wchar_t>; 75c0a68be4Smrg#endif 76c0a68be4Smrg } // namespace pmr 77c0a68be4Smrg 78c0a68be4Smrg template<typename _Str> 79c0a68be4Smrg struct __hash_string_base 80c0a68be4Smrg : public __hash_base<size_t, _Str> 81c0a68be4Smrg { 82c0a68be4Smrg size_t 83c0a68be4Smrg operator()(const _Str& __s) const noexcept 84c0a68be4Smrg { return hash<basic_string_view<typename _Str::value_type>>{}(__s); } 85c0a68be4Smrg }; 86c0a68be4Smrg 87c0a68be4Smrg template<> 88c0a68be4Smrg struct hash<pmr::string> 89c0a68be4Smrg : public __hash_string_base<pmr::string> 90c0a68be4Smrg { }; 91c0a68be4Smrg#ifdef _GLIBCXX_USE_CHAR8_T 92c0a68be4Smrg template<> 93c0a68be4Smrg struct hash<pmr::u8string> 94c0a68be4Smrg : public __hash_string_base<pmr::u8string> 95c0a68be4Smrg { }; 96c0a68be4Smrg#endif 97c0a68be4Smrg template<> 98c0a68be4Smrg struct hash<pmr::u16string> 99c0a68be4Smrg : public __hash_string_base<pmr::u16string> 100c0a68be4Smrg { }; 101c0a68be4Smrg template<> 102c0a68be4Smrg struct hash<pmr::u32string> 103c0a68be4Smrg : public __hash_string_base<pmr::u32string> 104c0a68be4Smrg { }; 105c0a68be4Smrg#ifdef _GLIBCXX_USE_WCHAR_T 106c0a68be4Smrg template<> 107c0a68be4Smrg struct hash<pmr::wstring> 108c0a68be4Smrg : public __hash_string_base<pmr::wstring> 109c0a68be4Smrg { }; 110c0a68be4Smrg#endif 111c0a68be4Smrg 112c0a68be4Smrg_GLIBCXX_END_NAMESPACE_VERSION 113c0a68be4Smrg} // namespace std 114c0a68be4Smrg#endif // C++17 115c0a68be4Smrg 116c0a68be4Smrg#if __cplusplus > 201703L 117c0a68be4Smrgnamespace std _GLIBCXX_VISIBILITY(default) 118c0a68be4Smrg{ 119c0a68be4Smrg_GLIBCXX_BEGIN_NAMESPACE_VERSION 120c0a68be4Smrg 121*8feb0f0bSmrg#define __cpp_lib_erase_if 202002L 122c0a68be4Smrg 123c0a68be4Smrg template<typename _CharT, typename _Traits, typename _Alloc, 124c0a68be4Smrg typename _Predicate> 125c0a68be4Smrg inline typename basic_string<_CharT, _Traits, _Alloc>::size_type 126c0a68be4Smrg erase_if(basic_string<_CharT, _Traits, _Alloc>& __cont, _Predicate __pred) 127c0a68be4Smrg { 128c0a68be4Smrg const auto __osz = __cont.size(); 129c0a68be4Smrg __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred), 130c0a68be4Smrg __cont.end()); 131c0a68be4Smrg return __osz - __cont.size(); 132c0a68be4Smrg } 133c0a68be4Smrg 134c0a68be4Smrg template<typename _CharT, typename _Traits, typename _Alloc, typename _Up> 135c0a68be4Smrg inline typename basic_string<_CharT, _Traits, _Alloc>::size_type 136c0a68be4Smrg erase(basic_string<_CharT, _Traits, _Alloc>& __cont, const _Up& __value) 137c0a68be4Smrg { 138c0a68be4Smrg const auto __osz = __cont.size(); 139c0a68be4Smrg __cont.erase(std::remove(__cont.begin(), __cont.end(), __value), 140c0a68be4Smrg __cont.end()); 141c0a68be4Smrg return __osz - __cont.size(); 142c0a68be4Smrg } 143c0a68be4Smrg_GLIBCXX_END_NAMESPACE_VERSION 144c0a68be4Smrg} // namespace std 145c0a68be4Smrg#endif // C++20 146c0a68be4Smrg 1471debfc3dSmrg#endif /* _GLIBCXX_STRING */ 148