libstdc++
string
Go to the documentation of this file.
1 // Components for manipulating sequences of characters -*- C++ -*-
2 
3 // Copyright (C) 1997-2026 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 #define __glibcxx_exc_in_string 1
44 #include <bits/stringfwd.h>
45 #include <bits/char_traits.h>
46 #include <bits/allocator.h>
47 #include <bits/cpp_type_traits.h>
48 #include <bits/localefwd.h> // For operators >>, <<, and getline.
49 #include <bits/ostream_insert.h>
51 #include <bits/stl_iterator.h>
52 #include <bits/stl_function.h> // For less
53 #include <ext/numeric_traits.h>
54 #include <bits/stdexcept_throw.h>
55 #include <bits/stl_algobase.h>
56 #include <bits/range_access.h>
57 #include <bits/erase_if.h>
58 #include <bits/basic_string.h>
59 #include <bits/basic_string.tcc>
60 #if (_GLIBCXX_HOSTED && __cpp_exceptions && __cplusplus > 202302L \
61  && __cpp_constexpr_exceptions >= 202411L)
62 #include <bits/stdexcept_except.h>
63 #undef __glibcxx_exc_in_string
64 #include <bits/stdexcept_throw.h>
65 #else
66 #undef __glibcxx_exc_in_string
67 #endif
68 
69 #define __glibcxx_want_algorithm_default_value_type
70 #define __glibcxx_want_allocator_traits_is_always_equal
71 #define __glibcxx_want_constexpr_char_traits
72 #define __glibcxx_want_constexpr_string
73 #define __glibcxx_want_containers_ranges
74 #define __glibcxx_want_erase_if
75 #define __glibcxx_want_nonmember_container_access
76 #define __glibcxx_want_string_resize_and_overwrite
77 #define __glibcxx_want_string_subview
78 #define __glibcxx_want_string_udls
79 #define __glibcxx_want_to_string
80 #include <bits/version.h>
81 
82 #if __cplusplus >= 201703L && _GLIBCXX_USE_CXX11_ABI
83 #include <bits/memory_resource.h>
84 namespace std _GLIBCXX_VISIBILITY(default)
85 {
86 _GLIBCXX_BEGIN_NAMESPACE_VERSION
87  namespace pmr {
88  template<typename _CharT, typename _Traits = char_traits<_CharT>>
89  using basic_string = std::basic_string<_CharT, _Traits,
90  polymorphic_allocator<_CharT>>;
91  using string = basic_string<char>;
92 #ifdef _GLIBCXX_USE_CHAR8_T
93  using u8string = basic_string<char8_t>;
94 #endif
95  using u16string = basic_string<char16_t>;
96  using u32string = basic_string<char32_t>;
97  using wstring = basic_string<wchar_t>;
98  } // namespace pmr
99 _GLIBCXX_END_NAMESPACE_VERSION
100 } // namespace std
101 #endif // C++17
102 
103 #ifdef __cpp_lib_erase_if // C++ >= 20 && HOSTED
104 namespace std _GLIBCXX_VISIBILITY(default)
105 {
106 _GLIBCXX_BEGIN_NAMESPACE_VERSION
107 
108  template<typename _CharT, typename _Traits, typename _Alloc,
109  typename _Predicate>
110  constexpr typename basic_string<_CharT, _Traits, _Alloc>::size_type
111  erase_if(basic_string<_CharT, _Traits, _Alloc>& __cont, _Predicate __pred)
112  { return __detail::__erase_if(__cont, __cont, std::move(__pred)); }
113 
114  template<typename _CharT, typename _Traits, typename _Alloc,
115  typename _Up _GLIBCXX26_DEF_VAL_T(_CharT)>
116  constexpr typename basic_string<_CharT, _Traits, _Alloc>::size_type
117  erase(basic_string<_CharT, _Traits, _Alloc>& __cont, const _Up& __value)
118  { return std::erase_if(__cont, __gnu_cxx::__ops::__equal_to(__value)); }
119 
120 _GLIBCXX_END_NAMESPACE_VERSION
121 } // namespace std
122 #endif // __cpp_lib_erase_if
123 
124 #endif /* _GLIBCXX_STRING */
stdexcept_throw.h
requires_hosted.h
ostream_insert.h
stringfwd.h
localefwd.h
stl_function.h
char_traits.h
std::move
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:138
cpp_type_traits.h
stdexcept_except.h
stl_iterator.h
erase_if.h
std::u16string
basic_string< char16_t > u16string
A string of char16_t.
Definition: stringfwd.h:91
numeric_traits.h
std
ISO C++ entities toplevel namespace is std.
std::wstring
basic_string< wchar_t > wstring
A string of wchar_t.
Definition: stringfwd.h:82
stl_iterator_base_funcs.h
c++config.h
range_access.h
stl_algobase.h
basic_string.h
memory_resource.h
std::basic_string
Managing sequences of characters and character-like objects.
Definition: cow_string.h:108
std::u32string
basic_string< char32_t > u32string
A string of char32_t.
Definition: stringfwd.h:94
allocator.h
version.h
basic_string.tcc