libstdc++
string
Go to the documentation of this file.
1// Components for manipulating sequences of characters -*- C++ -*-
2
3// Copyright (C) 1997-2025 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#ifdef _GLIBCXX_SYSHDR
37#pragma GCC system_header
38#endif
39
40#include <bits/requires_hosted.h> // containers
41
42#include <bits/c++config.h>
43#include <bits/stringfwd.h>
44#include <bits/char_traits.h>
45#include <bits/allocator.h>
47#include <bits/localefwd.h> // For operators >>, <<, and getline.
48#include <bits/ostream_insert.h>
50#include <bits/stl_iterator.h>
51#include <bits/stl_function.h> // For less
52#include <ext/numeric_traits.h>
53#include <bits/stl_algobase.h>
54#include <bits/refwrap.h>
55#include <bits/range_access.h>
56#include <bits/basic_string.h>
57#include <bits/basic_string.tcc>
58
59#define __glibcxx_want_algorithm_default_value_type
60#define __glibcxx_want_allocator_traits_is_always_equal
61#define __glibcxx_want_constexpr_char_traits
62#define __glibcxx_want_constexpr_string
63#define __glibcxx_want_erase_if
64#define __glibcxx_want_nonmember_container_access
65#define __glibcxx_want_string_resize_and_overwrite
66#define __glibcxx_want_string_udls
67#define __glibcxx_want_to_string
68#include <bits/version.h>
69
70#if __cplusplus >= 201703L && _GLIBCXX_USE_CXX11_ABI
72namespace std _GLIBCXX_VISIBILITY(default)
73{
74_GLIBCXX_BEGIN_NAMESPACE_VERSION
75 namespace pmr {
76 template<typename _CharT, typename _Traits = char_traits<_CharT>>
77 using basic_string = std::basic_string<_CharT, _Traits,
78 polymorphic_allocator<_CharT>>;
79 using string = basic_string<char>;
80#ifdef _GLIBCXX_USE_CHAR8_T
81 using u8string = basic_string<char8_t>;
82#endif
83 using u16string = basic_string<char16_t>;
84 using u32string = basic_string<char32_t>;
85 using wstring = basic_string<wchar_t>;
86 } // namespace pmr
87_GLIBCXX_END_NAMESPACE_VERSION
88} // namespace std
89#endif // C++17
90
91#ifdef __cpp_lib_erase_if // C++ >= 20 && HOSTED
92namespace std _GLIBCXX_VISIBILITY(default)
93{
94_GLIBCXX_BEGIN_NAMESPACE_VERSION
95
96 template<typename _CharT, typename _Traits, typename _Alloc,
97 typename _Predicate>
98 _GLIBCXX20_CONSTEXPR
99 inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
100 erase_if(basic_string<_CharT, _Traits, _Alloc>& __cont, _Predicate __pred)
101 {
102 using namespace __gnu_cxx;
103 const auto __osz = __cont.size();
104 const auto __end = __cont.end();
105 auto __removed = std::__remove_if(__cont.begin(), __end,
106 __ops::__pred_iter(std::ref(__pred)));
107 __cont.erase(__removed, __end);
108 return __osz - __cont.size();
109 }
110
111 template<typename _CharT, typename _Traits, typename _Alloc,
112 typename _Up _GLIBCXX26_DEF_VAL_T(_CharT)>
113 _GLIBCXX20_CONSTEXPR
114 inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
115 erase(basic_string<_CharT, _Traits, _Alloc>& __cont, const _Up& __value)
116 {
117 using namespace __gnu_cxx;
118 const auto __osz = __cont.size();
119 const auto __end = __cont.end();
120 auto __removed = std::__remove_if(__cont.begin(), __end,
121 __ops::__iter_equals_val(__value));
122 __cont.erase(__removed, __end);
123 return __osz - __cont.size();
124 }
125_GLIBCXX_END_NAMESPACE_VERSION
126} // namespace std
127#endif // __cpp_lib_erase_if
128
129#endif /* _GLIBCXX_STRING */
basic_string< char > string
A string of char.
Definition stringfwd.h:79
basic_string< char32_t > u32string
A string of char32_t.
Definition stringfwd.h:94
basic_string< char16_t > u16string
A string of char16_t.
Definition stringfwd.h:91
basic_string< wchar_t > wstring
A string of wchar_t.
Definition stringfwd.h:82
ISO C++ entities toplevel namespace is std.
GNU extensions for public use.
Managing sequences of characters and character-like objects.
Definition cow_string.h:109