libstdc++
string
Go to the documentation of this file.
00001 // Components for manipulating sequences of characters -*- C++ -*-
00002 
00003 // Copyright (C) 1997-2019 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file include/string
00026  *  This is a Standard C++ Library header.
00027  */
00028 
00029 //
00030 // ISO C++ 14882: 21  Strings library
00031 //
00032 
00033 #ifndef _GLIBCXX_STRING
00034 #define _GLIBCXX_STRING 1
00035 
00036 #pragma GCC system_header
00037 
00038 #include <bits/c++config.h>
00039 #include <bits/stringfwd.h>
00040 #include <bits/char_traits.h>  // NB: In turn includes stl_algobase.h
00041 #include <bits/allocator.h>
00042 #include <bits/cpp_type_traits.h>
00043 #include <bits/localefwd.h>    // For operators >>, <<, and getline.
00044 #include <bits/ostream_insert.h>
00045 #include <bits/stl_iterator_base_types.h>
00046 #include <bits/stl_iterator_base_funcs.h>
00047 #include <bits/stl_iterator.h>
00048 #include <bits/stl_function.h> // For less
00049 #include <ext/numeric_traits.h>
00050 #include <bits/stl_algobase.h>
00051 #if __cplusplus > 201703L
00052 #  include <bits/stl_algo.h> // For remove and remove_if
00053 #endif // C++20
00054 #include <bits/range_access.h>
00055 #include <bits/basic_string.h>
00056 #include <bits/basic_string.tcc>
00057 
00058 #if __cplusplus >= 201703L && _GLIBCXX_USE_CXX11_ABI
00059 namespace std _GLIBCXX_VISIBILITY(default)
00060 {
00061 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00062   namespace pmr {
00063     template<typename _Tp> class polymorphic_allocator;
00064     template<typename _CharT, typename _Traits = char_traits<_CharT>>
00065       using basic_string = std::basic_string<_CharT, _Traits,
00066                                              polymorphic_allocator<_CharT>>;
00067     using string    = basic_string<char>;
00068 #ifdef _GLIBCXX_USE_CHAR8_T
00069     using u8string  = basic_string<char8_t>;
00070 #endif
00071     using u16string = basic_string<char16_t>;
00072     using u32string = basic_string<char32_t>;
00073 #ifdef _GLIBCXX_USE_WCHAR_T
00074     using wstring   = basic_string<wchar_t>;
00075 #endif
00076   } // namespace pmr
00077 
00078   template<typename _Str>
00079     struct __hash_string_base
00080     : public __hash_base<size_t, _Str>
00081     {
00082       size_t
00083       operator()(const _Str& __s) const noexcept
00084       { return hash<basic_string_view<typename _Str::value_type>>{}(__s); }
00085     };
00086 
00087   template<>
00088     struct hash<pmr::string>
00089     : public __hash_string_base<pmr::string>
00090     { };
00091 #ifdef _GLIBCXX_USE_CHAR8_T
00092   template<>
00093     struct hash<pmr::u8string>
00094     : public __hash_string_base<pmr::u8string>
00095     { };
00096 #endif
00097   template<>
00098     struct hash<pmr::u16string>
00099     : public __hash_string_base<pmr::u16string>
00100     { };
00101   template<>
00102     struct hash<pmr::u32string>
00103     : public __hash_string_base<pmr::u32string>
00104     { };
00105 #ifdef _GLIBCXX_USE_WCHAR_T
00106   template<>
00107     struct hash<pmr::wstring>
00108     : public __hash_string_base<pmr::wstring>
00109     { };
00110 #endif
00111 
00112 _GLIBCXX_END_NAMESPACE_VERSION
00113 } // namespace std
00114 #endif // C++17
00115 
00116 #if __cplusplus > 201703L
00117 namespace std _GLIBCXX_VISIBILITY(default)
00118 {
00119 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00120 
00121 #define __cpp_lib_erase_if 201900L
00122 
00123   template<typename _CharT, typename _Traits, typename _Alloc,
00124            typename _Predicate>
00125     inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
00126     erase_if(basic_string<_CharT, _Traits, _Alloc>& __cont, _Predicate __pred)
00127     {
00128       const auto __osz = __cont.size();
00129       __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred),
00130                    __cont.end());
00131       return __osz - __cont.size();
00132     }
00133 
00134   template<typename _CharT, typename _Traits, typename _Alloc, typename _Up>
00135     inline typename basic_string<_CharT, _Traits, _Alloc>::size_type
00136     erase(basic_string<_CharT, _Traits, _Alloc>& __cont, const _Up& __value)
00137     {
00138       const auto __osz = __cont.size();
00139       __cont.erase(std::remove(__cont.begin(), __cont.end(), __value),
00140                    __cont.end());
00141       return __osz - __cont.size();
00142     }
00143 _GLIBCXX_END_NAMESPACE_VERSION
00144 } // namespace std
00145 #endif // C++20
00146 
00147 #endif /* _GLIBCXX_STRING */