]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/std/string
libstdc++: Test for feature test macros more accurately
[thirdparty/gcc.git] / libstdc++-v3 / include / std / string
CommitLineData
54c1bf78 1// Components for manipulating sequences of characters -*- C++ -*-
de96ac46 2
83ffe9cd 3// Copyright (C) 1997-2023 Free Software Foundation, Inc.
de96ac46
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
de96ac46
BK
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
748086b7
JJ
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.
de96ac46 19
748086b7
JJ
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/>.
de96ac46 24
143c27b0
BK
25/** @file include/string
26 * This is a Standard C++ Library header.
27 */
28
54c1bf78
BK
29//
30// ISO C++ 14882: 21 Strings library
31//
32
1143680e
SE
33#ifndef _GLIBCXX_STRING
34#define _GLIBCXX_STRING 1
54c1bf78
BK
35
36#pragma GCC system_header
37
18f176d0
AA
38#include <bits/requires_hosted.h> // containers
39
54c1bf78
BK
40#include <bits/c++config.h>
41#include <bits/stringfwd.h>
8f180200 42#include <bits/char_traits.h>
f56fe8ff 43#include <bits/allocator.h>
c0736a9d 44#include <bits/cpp_type_traits.h>
11202768
PC
45#include <bits/localefwd.h> // For operators >>, <<, and getline.
46#include <bits/ostream_insert.h>
c2ba9709 47#include <bits/stl_iterator_base_funcs.h>
54c1bf78 48#include <bits/stl_iterator.h>
11202768 49#include <bits/stl_function.h> // For less
33ac58d5
JW
50#include <ext/numeric_traits.h>
51#include <bits/stl_algobase.h>
acf3a21c 52#include <bits/refwrap.h>
f67a9881 53#include <bits/range_access.h>
ee3ee948 54#include <bits/basic_string.h>
33ac58d5 55#include <bits/basic_string.tcc>
54c1bf78 56
083b7f28
AA
57#define __glibcxx_want_erase_if
58#include <bits/version.h>
59
1bc7a28f 60#if __cplusplus >= 201703L && _GLIBCXX_USE_CXX11_ABI
8ccdc7ce 61#include <bits/memory_resource.h>
1fc9d0b0
JW
62namespace std _GLIBCXX_VISIBILITY(default)
63{
64_GLIBCXX_BEGIN_NAMESPACE_VERSION
65 namespace pmr {
1fc9d0b0
JW
66 template<typename _CharT, typename _Traits = char_traits<_CharT>>
67 using basic_string = std::basic_string<_CharT, _Traits,
68 polymorphic_allocator<_CharT>>;
69 using string = basic_string<char>;
c124af93
TH
70#ifdef _GLIBCXX_USE_CHAR8_T
71 using u8string = basic_string<char8_t>;
72#endif
1fc9d0b0
JW
73 using u16string = basic_string<char16_t>;
74 using u32string = basic_string<char32_t>;
1fc9d0b0 75 using wstring = basic_string<wchar_t>;
1fc9d0b0
JW
76 } // namespace pmr
77_GLIBCXX_END_NAMESPACE_VERSION
78} // namespace std
79#endif // C++17
80
083b7f28 81#ifdef __cpp_lib_erase_if // C++ >= 20 && HOSTED
188588e4
ESR
82namespace std _GLIBCXX_VISIBILITY(default)
83{
84_GLIBCXX_BEGIN_NAMESPACE_VERSION
45a8d80f 85
188588e4
ESR
86 template<typename _CharT, typename _Traits, typename _Alloc,
87 typename _Predicate>
b96e2ff9 88 _GLIBCXX20_CONSTEXPR
0b44b4b8 89 inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
188588e4
ESR
90 erase_if(basic_string<_CharT, _Traits, _Alloc>& __cont, _Predicate __pred)
91 {
acf3a21c 92 using namespace __gnu_cxx;
0b44b4b8 93 const auto __osz = __cont.size();
56107848
JW
94 const auto __end = __cont.end();
95 auto __removed = std::__remove_if(__cont.begin(), __end,
96 __ops::__pred_iter(std::ref(__pred)));
97 __cont.erase(__removed, __end);
0b44b4b8 98 return __osz - __cont.size();
188588e4
ESR
99 }
100
101 template<typename _CharT, typename _Traits, typename _Alloc, typename _Up>
b96e2ff9 102 _GLIBCXX20_CONSTEXPR
0b44b4b8 103 inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
188588e4
ESR
104 erase(basic_string<_CharT, _Traits, _Alloc>& __cont, const _Up& __value)
105 {
acf3a21c 106 using namespace __gnu_cxx;
0b44b4b8 107 const auto __osz = __cont.size();
56107848
JW
108 const auto __end = __cont.end();
109 auto __removed = std::__remove_if(__cont.begin(), __end,
110 __ops::__iter_equals_val(__value));
111 __cont.erase(__removed, __end);
0b44b4b8 112 return __osz - __cont.size();
188588e4
ESR
113 }
114_GLIBCXX_END_NAMESPACE_VERSION
115} // namespace std
083b7f28 116#endif // __cpp_lib_erase_if
188588e4 117
1143680e 118#endif /* _GLIBCXX_STRING */