string 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Components for manipulating sequences of characters -*- C++ -*-
  2. // Copyright (C) 1997-2023 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file include/string
  21. * This is a Standard C++ Library header.
  22. */
  23. //
  24. // ISO C++ 14882: 21 Strings library
  25. //
  26. #ifndef _GLIBCXX_STRING
  27. #define _GLIBCXX_STRING 1
  28. #pragma GCC system_header
  29. #include <bits/requires_hosted.h> // containers
  30. #include <bits/c++config.h>
  31. #include <bits/stringfwd.h>
  32. #include <bits/char_traits.h>
  33. #include <bits/allocator.h>
  34. #include <bits/cpp_type_traits.h>
  35. #include <bits/localefwd.h> // For operators >>, <<, and getline.
  36. #include <bits/ostream_insert.h>
  37. #include <bits/stl_iterator_base_funcs.h>
  38. #include <bits/stl_iterator.h>
  39. #include <bits/stl_function.h> // For less
  40. #include <ext/numeric_traits.h>
  41. #include <bits/stl_algobase.h>
  42. #include <bits/refwrap.h>
  43. #include <bits/range_access.h>
  44. #include <bits/basic_string.h>
  45. #include <bits/basic_string.tcc>
  46. #if __cplusplus >= 201703L && _GLIBCXX_USE_CXX11_ABI
  47. #include <bits/memory_resource.h>
  48. namespace std _GLIBCXX_VISIBILITY(default)
  49. {
  50. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  51. namespace pmr {
  52. template<typename _CharT, typename _Traits = char_traits<_CharT>>
  53. using basic_string = std::basic_string<_CharT, _Traits,
  54. polymorphic_allocator<_CharT>>;
  55. using string = basic_string<char>;
  56. #ifdef _GLIBCXX_USE_CHAR8_T
  57. using u8string = basic_string<char8_t>;
  58. #endif
  59. using u16string = basic_string<char16_t>;
  60. using u32string = basic_string<char32_t>;
  61. using wstring = basic_string<wchar_t>;
  62. } // namespace pmr
  63. _GLIBCXX_END_NAMESPACE_VERSION
  64. } // namespace std
  65. #endif // C++17
  66. #if __cplusplus > 201703L
  67. namespace std _GLIBCXX_VISIBILITY(default)
  68. {
  69. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  70. #define __cpp_lib_erase_if 202002L
  71. template<typename _CharT, typename _Traits, typename _Alloc,
  72. typename _Predicate>
  73. _GLIBCXX20_CONSTEXPR
  74. inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
  75. erase_if(basic_string<_CharT, _Traits, _Alloc>& __cont, _Predicate __pred)
  76. {
  77. using namespace __gnu_cxx;
  78. const auto __osz = __cont.size();
  79. const auto __end = __cont.end();
  80. auto __removed = std::__remove_if(__cont.begin(), __end,
  81. __ops::__pred_iter(std::ref(__pred)));
  82. __cont.erase(__removed, __end);
  83. return __osz - __cont.size();
  84. }
  85. template<typename _CharT, typename _Traits, typename _Alloc, typename _Up>
  86. _GLIBCXX20_CONSTEXPR
  87. inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
  88. erase(basic_string<_CharT, _Traits, _Alloc>& __cont, const _Up& __value)
  89. {
  90. using namespace __gnu_cxx;
  91. const auto __osz = __cont.size();
  92. const auto __end = __cont.end();
  93. auto __removed = std::__remove_if(__cont.begin(), __end,
  94. __ops::__iter_equals_val(__value));
  95. __cont.erase(__removed, __end);
  96. return __osz - __cont.size();
  97. }
  98. _GLIBCXX_END_NAMESPACE_VERSION
  99. } // namespace std
  100. #endif // C++20
  101. #endif /* _GLIBCXX_STRING */