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