14fee23f9Smrg// Components for manipulating sequences of characters -*- C++ -*- 24fee23f9Smrg 3*b1e83836Smrg// Copyright (C) 1997-2022 Free Software Foundation, Inc. 44fee23f9Smrg// 54fee23f9Smrg// This file is part of the GNU ISO C++ Library. This library is free 64fee23f9Smrg// software; you can redistribute it and/or modify it under the 74fee23f9Smrg// terms of the GNU General Public License as published by the 84fee23f9Smrg// Free Software Foundation; either version 3, or (at your option) 94fee23f9Smrg// any later version. 104fee23f9Smrg 114fee23f9Smrg// This library is distributed in the hope that it will be useful, 124fee23f9Smrg// but WITHOUT ANY WARRANTY; without even the implied warranty of 134fee23f9Smrg// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 144fee23f9Smrg// GNU General Public License for more details. 154fee23f9Smrg 164fee23f9Smrg// Under Section 7 of GPL version 3, you are granted additional 174fee23f9Smrg// permissions described in the GCC Runtime Library Exception, version 184fee23f9Smrg// 3.1, as published by the Free Software Foundation. 194fee23f9Smrg 204fee23f9Smrg// You should have received a copy of the GNU General Public License and 214fee23f9Smrg// a copy of the GCC Runtime Library Exception along with this program; 224fee23f9Smrg// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 234fee23f9Smrg// <http://www.gnu.org/licenses/>. 244fee23f9Smrg 254fee23f9Smrg/** @file include/string 264fee23f9Smrg * This is a Standard C++ Library header. 274fee23f9Smrg */ 284fee23f9Smrg 294fee23f9Smrg// 304fee23f9Smrg// ISO C++ 14882: 21 Strings library 314fee23f9Smrg// 324fee23f9Smrg 334fee23f9Smrg#ifndef _GLIBCXX_STRING 344fee23f9Smrg#define _GLIBCXX_STRING 1 354fee23f9Smrg 364fee23f9Smrg#pragma GCC system_header 374fee23f9Smrg 384fee23f9Smrg#include <bits/c++config.h> 394fee23f9Smrg#include <bits/stringfwd.h> 404fee23f9Smrg#include <bits/char_traits.h> // NB: In turn includes stl_algobase.h 414fee23f9Smrg#include <bits/allocator.h> 424fee23f9Smrg#include <bits/cpp_type_traits.h> 434fee23f9Smrg#include <bits/localefwd.h> // For operators >>, <<, and getline. 444fee23f9Smrg#include <bits/ostream_insert.h> 454fee23f9Smrg#include <bits/stl_iterator_base_types.h> 464fee23f9Smrg#include <bits/stl_iterator_base_funcs.h> 474fee23f9Smrg#include <bits/stl_iterator.h> 484fee23f9Smrg#include <bits/stl_function.h> // For less 494fee23f9Smrg#include <ext/numeric_traits.h> 504fee23f9Smrg#include <bits/stl_algobase.h> 51*b1e83836Smrg#include <bits/refwrap.h> 5248fb7bfaSmrg#include <bits/range_access.h> 534fee23f9Smrg#include <bits/basic_string.h> 544fee23f9Smrg#include <bits/basic_string.tcc> 554fee23f9Smrg 56181254a7Smrg#if __cplusplus >= 201703L && _GLIBCXX_USE_CXX11_ABI 57181254a7Smrgnamespace std _GLIBCXX_VISIBILITY(default) 58181254a7Smrg{ 59181254a7Smrg_GLIBCXX_BEGIN_NAMESPACE_VERSION 60181254a7Smrg namespace pmr { 61181254a7Smrg template<typename _Tp> class polymorphic_allocator; 62181254a7Smrg template<typename _CharT, typename _Traits = char_traits<_CharT>> 63181254a7Smrg using basic_string = std::basic_string<_CharT, _Traits, 64181254a7Smrg polymorphic_allocator<_CharT>>; 65181254a7Smrg using string = basic_string<char>; 66181254a7Smrg#ifdef _GLIBCXX_USE_CHAR8_T 67181254a7Smrg using u8string = basic_string<char8_t>; 68181254a7Smrg#endif 69181254a7Smrg using u16string = basic_string<char16_t>; 70181254a7Smrg using u32string = basic_string<char32_t>; 71181254a7Smrg using wstring = basic_string<wchar_t>; 72181254a7Smrg } // namespace pmr 73181254a7Smrg 74181254a7Smrg template<typename _Str> 75181254a7Smrg struct __hash_string_base 76181254a7Smrg : public __hash_base<size_t, _Str> 77181254a7Smrg { 78181254a7Smrg size_t 79181254a7Smrg operator()(const _Str& __s) const noexcept 80181254a7Smrg { return hash<basic_string_view<typename _Str::value_type>>{}(__s); } 81181254a7Smrg }; 82181254a7Smrg 83181254a7Smrg template<> 84181254a7Smrg struct hash<pmr::string> 85181254a7Smrg : public __hash_string_base<pmr::string> 86181254a7Smrg { }; 87181254a7Smrg#ifdef _GLIBCXX_USE_CHAR8_T 88181254a7Smrg template<> 89181254a7Smrg struct hash<pmr::u8string> 90181254a7Smrg : public __hash_string_base<pmr::u8string> 91181254a7Smrg { }; 92181254a7Smrg#endif 93181254a7Smrg template<> 94181254a7Smrg struct hash<pmr::u16string> 95181254a7Smrg : public __hash_string_base<pmr::u16string> 96181254a7Smrg { }; 97181254a7Smrg template<> 98181254a7Smrg struct hash<pmr::u32string> 99181254a7Smrg : public __hash_string_base<pmr::u32string> 100181254a7Smrg { }; 101181254a7Smrg template<> 102181254a7Smrg struct hash<pmr::wstring> 103181254a7Smrg : public __hash_string_base<pmr::wstring> 104181254a7Smrg { }; 105181254a7Smrg 106181254a7Smrg_GLIBCXX_END_NAMESPACE_VERSION 107181254a7Smrg} // namespace std 108181254a7Smrg#endif // C++17 109181254a7Smrg 110181254a7Smrg#if __cplusplus > 201703L 111181254a7Smrgnamespace std _GLIBCXX_VISIBILITY(default) 112181254a7Smrg{ 113181254a7Smrg_GLIBCXX_BEGIN_NAMESPACE_VERSION 114181254a7Smrg 115fb8a8121Smrg#define __cpp_lib_erase_if 202002L 116181254a7Smrg 117181254a7Smrg template<typename _CharT, typename _Traits, typename _Alloc, 118181254a7Smrg typename _Predicate> 119*b1e83836Smrg _GLIBCXX20_CONSTEXPR 120181254a7Smrg inline typename basic_string<_CharT, _Traits, _Alloc>::size_type 121181254a7Smrg erase_if(basic_string<_CharT, _Traits, _Alloc>& __cont, _Predicate __pred) 122181254a7Smrg { 123*b1e83836Smrg using namespace __gnu_cxx; 124181254a7Smrg const auto __osz = __cont.size(); 125*b1e83836Smrg const auto __end = __cont.end(); 126*b1e83836Smrg auto __removed = std::__remove_if(__cont.begin(), __end, 127*b1e83836Smrg __ops::__pred_iter(std::ref(__pred))); 128*b1e83836Smrg __cont.erase(__removed, __end); 129181254a7Smrg return __osz - __cont.size(); 130181254a7Smrg } 131181254a7Smrg 132181254a7Smrg template<typename _CharT, typename _Traits, typename _Alloc, typename _Up> 133*b1e83836Smrg _GLIBCXX20_CONSTEXPR 134181254a7Smrg inline typename basic_string<_CharT, _Traits, _Alloc>::size_type 135181254a7Smrg erase(basic_string<_CharT, _Traits, _Alloc>& __cont, const _Up& __value) 136181254a7Smrg { 137*b1e83836Smrg using namespace __gnu_cxx; 138181254a7Smrg const auto __osz = __cont.size(); 139*b1e83836Smrg const auto __end = __cont.end(); 140*b1e83836Smrg auto __removed = std::__remove_if(__cont.begin(), __end, 141*b1e83836Smrg __ops::__iter_equals_val(__value)); 142*b1e83836Smrg __cont.erase(__removed, __end); 143181254a7Smrg return __osz - __cont.size(); 144181254a7Smrg } 145181254a7Smrg_GLIBCXX_END_NAMESPACE_VERSION 146181254a7Smrg} // namespace std 147181254a7Smrg#endif // C++20 148181254a7Smrg 1494fee23f9Smrg#endif /* _GLIBCXX_STRING */ 150