libstdc++
|
00001 // Components for manipulating sequences of characters -*- C++ -*- 00002 00003 // Copyright (C) 1997-2017 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 bits/basic_string.h 00026 * This is an internal header file, included by other library headers. 00027 * Do not attempt to use it directly. @headername{string} 00028 */ 00029 00030 // 00031 // ISO C++ 14882: 21 Strings library 00032 // 00033 00034 #ifndef _BASIC_STRING_H 00035 #define _BASIC_STRING_H 1 00036 00037 #pragma GCC system_header 00038 00039 #include <ext/atomicity.h> 00040 #include <ext/alloc_traits.h> 00041 #include <debug/debug.h> 00042 00043 #if __cplusplus >= 201103L 00044 #include <initializer_list> 00045 #endif 00046 00047 #if __cplusplus > 201402L 00048 # include <string_view> 00049 #endif 00050 00051 00052 namespace std _GLIBCXX_VISIBILITY(default) 00053 { 00054 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00055 00056 #if _GLIBCXX_USE_CXX11_ABI 00057 _GLIBCXX_BEGIN_NAMESPACE_CXX11 00058 /** 00059 * @class basic_string basic_string.h <string> 00060 * @brief Managing sequences of characters and character-like objects. 00061 * 00062 * @ingroup strings 00063 * @ingroup sequences 00064 * 00065 * @tparam _CharT Type of character 00066 * @tparam _Traits Traits for character type, defaults to 00067 * char_traits<_CharT>. 00068 * @tparam _Alloc Allocator type, defaults to allocator<_CharT>. 00069 * 00070 * Meets the requirements of a <a href="tables.html#65">container</a>, a 00071 * <a href="tables.html#66">reversible container</a>, and a 00072 * <a href="tables.html#67">sequence</a>. Of the 00073 * <a href="tables.html#68">optional sequence requirements</a>, only 00074 * @c push_back, @c at, and @c %array access are supported. 00075 */ 00076 template<typename _CharT, typename _Traits, typename _Alloc> 00077 class basic_string 00078 { 00079 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template 00080 rebind<_CharT>::other _Char_alloc_type; 00081 typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits; 00082 00083 // Types: 00084 public: 00085 typedef _Traits traits_type; 00086 typedef typename _Traits::char_type value_type; 00087 typedef _Char_alloc_type allocator_type; 00088 typedef typename _Alloc_traits::size_type size_type; 00089 typedef typename _Alloc_traits::difference_type difference_type; 00090 typedef typename _Alloc_traits::reference reference; 00091 typedef typename _Alloc_traits::const_reference const_reference; 00092 typedef typename _Alloc_traits::pointer pointer; 00093 typedef typename _Alloc_traits::const_pointer const_pointer; 00094 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; 00095 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> 00096 const_iterator; 00097 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00098 typedef std::reverse_iterator<iterator> reverse_iterator; 00099 00100 /// Value returned by various member functions when they fail. 00101 static const size_type npos = static_cast<size_type>(-1); 00102 00103 private: 00104 // type used for positions in insert, erase etc. 00105 #if __cplusplus < 201103L 00106 typedef iterator __const_iterator; 00107 #else 00108 typedef const_iterator __const_iterator; 00109 #endif 00110 00111 #if __cplusplus > 201402L 00112 // A helper type for avoiding boiler-plate. 00113 typedef basic_string_view<_CharT, _Traits> __sv_type; 00114 00115 template<typename _Tp, typename _Res> 00116 using _If_sv = enable_if_t< 00117 __and_<is_convertible<const _Tp&, __sv_type>, 00118 __not_<is_convertible<const _Tp&, const _CharT*>>>::value, 00119 _Res>; 00120 #endif 00121 00122 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html 00123 struct _Alloc_hider : allocator_type // TODO check __is_final 00124 { 00125 #if __cplusplus < 201103L 00126 _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc()) 00127 : allocator_type(__a), _M_p(__dat) { } 00128 #else 00129 _Alloc_hider(pointer __dat, const _Alloc& __a) 00130 : allocator_type(__a), _M_p(__dat) { } 00131 00132 _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc()) 00133 : allocator_type(std::move(__a)), _M_p(__dat) { } 00134 #endif 00135 00136 pointer _M_p; // The actual data. 00137 }; 00138 00139 _Alloc_hider _M_dataplus; 00140 size_type _M_string_length; 00141 00142 enum { _S_local_capacity = 15 / sizeof(_CharT) }; 00143 00144 union 00145 { 00146 _CharT _M_local_buf[_S_local_capacity + 1]; 00147 size_type _M_allocated_capacity; 00148 }; 00149 00150 void 00151 _M_data(pointer __p) 00152 { _M_dataplus._M_p = __p; } 00153 00154 void 00155 _M_length(size_type __length) 00156 { _M_string_length = __length; } 00157 00158 pointer 00159 _M_data() const 00160 { return _M_dataplus._M_p; } 00161 00162 pointer 00163 _M_local_data() 00164 { 00165 #if __cplusplus >= 201103L 00166 return std::pointer_traits<pointer>::pointer_to(*_M_local_buf); 00167 #else 00168 return pointer(_M_local_buf); 00169 #endif 00170 } 00171 00172 const_pointer 00173 _M_local_data() const 00174 { 00175 #if __cplusplus >= 201103L 00176 return std::pointer_traits<const_pointer>::pointer_to(*_M_local_buf); 00177 #else 00178 return const_pointer(_M_local_buf); 00179 #endif 00180 } 00181 00182 void 00183 _M_capacity(size_type __capacity) 00184 { _M_allocated_capacity = __capacity; } 00185 00186 void 00187 _M_set_length(size_type __n) 00188 { 00189 _M_length(__n); 00190 traits_type::assign(_M_data()[__n], _CharT()); 00191 } 00192 00193 bool 00194 _M_is_local() const 00195 { return _M_data() == _M_local_data(); } 00196 00197 // Create & Destroy 00198 pointer 00199 _M_create(size_type&, size_type); 00200 00201 void 00202 _M_dispose() 00203 { 00204 if (!_M_is_local()) 00205 _M_destroy(_M_allocated_capacity); 00206 } 00207 00208 void 00209 _M_destroy(size_type __size) throw() 00210 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); } 00211 00212 // _M_construct_aux is used to implement the 21.3.1 para 15 which 00213 // requires special behaviour if _InIterator is an integral type 00214 template<typename _InIterator> 00215 void 00216 _M_construct_aux(_InIterator __beg, _InIterator __end, 00217 std::__false_type) 00218 { 00219 typedef typename iterator_traits<_InIterator>::iterator_category _Tag; 00220 _M_construct(__beg, __end, _Tag()); 00221 } 00222 00223 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00224 // 438. Ambiguity in the "do the right thing" clause 00225 template<typename _Integer> 00226 void 00227 _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type) 00228 { _M_construct_aux_2(static_cast<size_type>(__beg), __end); } 00229 00230 void 00231 _M_construct_aux_2(size_type __req, _CharT __c) 00232 { _M_construct(__req, __c); } 00233 00234 template<typename _InIterator> 00235 void 00236 _M_construct(_InIterator __beg, _InIterator __end) 00237 { 00238 typedef typename std::__is_integer<_InIterator>::__type _Integral; 00239 _M_construct_aux(__beg, __end, _Integral()); 00240 } 00241 00242 // For Input Iterators, used in istreambuf_iterators, etc. 00243 template<typename _InIterator> 00244 void 00245 _M_construct(_InIterator __beg, _InIterator __end, 00246 std::input_iterator_tag); 00247 00248 // For forward_iterators up to random_access_iterators, used for 00249 // string::iterator, _CharT*, etc. 00250 template<typename _FwdIterator> 00251 void 00252 _M_construct(_FwdIterator __beg, _FwdIterator __end, 00253 std::forward_iterator_tag); 00254 00255 void 00256 _M_construct(size_type __req, _CharT __c); 00257 00258 allocator_type& 00259 _M_get_allocator() 00260 { return _M_dataplus; } 00261 00262 const allocator_type& 00263 _M_get_allocator() const 00264 { return _M_dataplus; } 00265 00266 private: 00267 00268 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST 00269 // The explicit instantiations in misc-inst.cc require this due to 00270 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64063 00271 template<typename _Tp, bool _Requires = 00272 !__are_same<_Tp, _CharT*>::__value 00273 && !__are_same<_Tp, const _CharT*>::__value 00274 && !__are_same<_Tp, iterator>::__value 00275 && !__are_same<_Tp, const_iterator>::__value> 00276 struct __enable_if_not_native_iterator 00277 { typedef basic_string& __type; }; 00278 template<typename _Tp> 00279 struct __enable_if_not_native_iterator<_Tp, false> { }; 00280 #endif 00281 00282 size_type 00283 _M_check(size_type __pos, const char* __s) const 00284 { 00285 if (__pos > this->size()) 00286 __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " 00287 "this->size() (which is %zu)"), 00288 __s, __pos, this->size()); 00289 return __pos; 00290 } 00291 00292 void 00293 _M_check_length(size_type __n1, size_type __n2, const char* __s) const 00294 { 00295 if (this->max_size() - (this->size() - __n1) < __n2) 00296 __throw_length_error(__N(__s)); 00297 } 00298 00299 00300 // NB: _M_limit doesn't check for a bad __pos value. 00301 size_type 00302 _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT 00303 { 00304 const bool __testoff = __off < this->size() - __pos; 00305 return __testoff ? __off : this->size() - __pos; 00306 } 00307 00308 // True if _Rep and source do not overlap. 00309 bool 00310 _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT 00311 { 00312 return (less<const _CharT*>()(__s, _M_data()) 00313 || less<const _CharT*>()(_M_data() + this->size(), __s)); 00314 } 00315 00316 // When __n = 1 way faster than the general multichar 00317 // traits_type::copy/move/assign. 00318 static void 00319 _S_copy(_CharT* __d, const _CharT* __s, size_type __n) 00320 { 00321 if (__n == 1) 00322 traits_type::assign(*__d, *__s); 00323 else 00324 traits_type::copy(__d, __s, __n); 00325 } 00326 00327 static void 00328 _S_move(_CharT* __d, const _CharT* __s, size_type __n) 00329 { 00330 if (__n == 1) 00331 traits_type::assign(*__d, *__s); 00332 else 00333 traits_type::move(__d, __s, __n); 00334 } 00335 00336 static void 00337 _S_assign(_CharT* __d, size_type __n, _CharT __c) 00338 { 00339 if (__n == 1) 00340 traits_type::assign(*__d, __c); 00341 else 00342 traits_type::assign(__d, __n, __c); 00343 } 00344 00345 // _S_copy_chars is a separate template to permit specialization 00346 // to optimize for the common case of pointers as iterators. 00347 template<class _Iterator> 00348 static void 00349 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) 00350 { 00351 for (; __k1 != __k2; ++__k1, (void)++__p) 00352 traits_type::assign(*__p, *__k1); // These types are off. 00353 } 00354 00355 static void 00356 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT 00357 { _S_copy_chars(__p, __k1.base(), __k2.base()); } 00358 00359 static void 00360 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) 00361 _GLIBCXX_NOEXCEPT 00362 { _S_copy_chars(__p, __k1.base(), __k2.base()); } 00363 00364 static void 00365 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT 00366 { _S_copy(__p, __k1, __k2 - __k1); } 00367 00368 static void 00369 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) 00370 _GLIBCXX_NOEXCEPT 00371 { _S_copy(__p, __k1, __k2 - __k1); } 00372 00373 static int 00374 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT 00375 { 00376 const difference_type __d = difference_type(__n1 - __n2); 00377 00378 if (__d > __gnu_cxx::__numeric_traits<int>::__max) 00379 return __gnu_cxx::__numeric_traits<int>::__max; 00380 else if (__d < __gnu_cxx::__numeric_traits<int>::__min) 00381 return __gnu_cxx::__numeric_traits<int>::__min; 00382 else 00383 return int(__d); 00384 } 00385 00386 void 00387 _M_assign(const basic_string&); 00388 00389 void 00390 _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, 00391 size_type __len2); 00392 00393 void 00394 _M_erase(size_type __pos, size_type __n); 00395 00396 public: 00397 // Construct/copy/destroy: 00398 // NB: We overload ctors in some cases instead of using default 00399 // arguments, per 17.4.4.4 para. 2 item 2. 00400 00401 /** 00402 * @brief Default constructor creates an empty string. 00403 */ 00404 basic_string() 00405 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value) 00406 : _M_dataplus(_M_local_data()) 00407 { _M_set_length(0); } 00408 00409 /** 00410 * @brief Construct an empty string using allocator @a a. 00411 */ 00412 explicit 00413 basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT 00414 : _M_dataplus(_M_local_data(), __a) 00415 { _M_set_length(0); } 00416 00417 /** 00418 * @brief Construct string with copy of value of @a __str. 00419 * @param __str Source string. 00420 */ 00421 basic_string(const basic_string& __str) 00422 : _M_dataplus(_M_local_data(), 00423 _Alloc_traits::_S_select_on_copy(__str._M_get_allocator())) 00424 { _M_construct(__str._M_data(), __str._M_data() + __str.length()); } 00425 00426 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00427 // 2583. no way to supply an allocator for basic_string(str, pos) 00428 /** 00429 * @brief Construct string as copy of a substring. 00430 * @param __str Source string. 00431 * @param __pos Index of first character to copy from. 00432 * @param __a Allocator to use. 00433 */ 00434 basic_string(const basic_string& __str, size_type __pos, 00435 const _Alloc& __a = _Alloc()) 00436 : _M_dataplus(_M_local_data(), __a) 00437 { 00438 const _CharT* __start = __str._M_data() 00439 + __str._M_check(__pos, "basic_string::basic_string"); 00440 _M_construct(__start, __start + __str._M_limit(__pos, npos)); 00441 } 00442 00443 /** 00444 * @brief Construct string as copy of a substring. 00445 * @param __str Source string. 00446 * @param __pos Index of first character to copy from. 00447 * @param __n Number of characters to copy. 00448 */ 00449 basic_string(const basic_string& __str, size_type __pos, 00450 size_type __n) 00451 : _M_dataplus(_M_local_data()) 00452 { 00453 const _CharT* __start = __str._M_data() 00454 + __str._M_check(__pos, "basic_string::basic_string"); 00455 _M_construct(__start, __start + __str._M_limit(__pos, __n)); 00456 } 00457 00458 /** 00459 * @brief Construct string as copy of a substring. 00460 * @param __str Source string. 00461 * @param __pos Index of first character to copy from. 00462 * @param __n Number of characters to copy. 00463 * @param __a Allocator to use. 00464 */ 00465 basic_string(const basic_string& __str, size_type __pos, 00466 size_type __n, const _Alloc& __a) 00467 : _M_dataplus(_M_local_data(), __a) 00468 { 00469 const _CharT* __start 00470 = __str._M_data() + __str._M_check(__pos, "string::string"); 00471 _M_construct(__start, __start + __str._M_limit(__pos, __n)); 00472 } 00473 00474 /** 00475 * @brief Construct string initialized by a character %array. 00476 * @param __s Source character %array. 00477 * @param __n Number of characters to copy. 00478 * @param __a Allocator to use (default is default allocator). 00479 * 00480 * NB: @a __s must have at least @a __n characters, '\\0' 00481 * has no special meaning. 00482 */ 00483 basic_string(const _CharT* __s, size_type __n, 00484 const _Alloc& __a = _Alloc()) 00485 : _M_dataplus(_M_local_data(), __a) 00486 { _M_construct(__s, __s + __n); } 00487 00488 /** 00489 * @brief Construct string as copy of a C string. 00490 * @param __s Source C string. 00491 * @param __a Allocator to use (default is default allocator). 00492 */ 00493 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) 00494 : _M_dataplus(_M_local_data(), __a) 00495 { _M_construct(__s, __s ? __s + traits_type::length(__s) : __s+npos); } 00496 00497 /** 00498 * @brief Construct string as multiple characters. 00499 * @param __n Number of characters. 00500 * @param __c Character to use. 00501 * @param __a Allocator to use (default is default allocator). 00502 */ 00503 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) 00504 : _M_dataplus(_M_local_data(), __a) 00505 { _M_construct(__n, __c); } 00506 00507 #if __cplusplus >= 201103L 00508 /** 00509 * @brief Move construct string. 00510 * @param __str Source string. 00511 * 00512 * The newly-created string contains the exact contents of @a __str. 00513 * @a __str is a valid, but unspecified string. 00514 **/ 00515 basic_string(basic_string&& __str) noexcept 00516 : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator())) 00517 { 00518 if (__str._M_is_local()) 00519 { 00520 traits_type::copy(_M_local_buf, __str._M_local_buf, 00521 _S_local_capacity + 1); 00522 } 00523 else 00524 { 00525 _M_data(__str._M_data()); 00526 _M_capacity(__str._M_allocated_capacity); 00527 } 00528 00529 // Must use _M_length() here not _M_set_length() because 00530 // basic_stringbuf relies on writing into unallocated capacity so 00531 // we mess up the contents if we put a '\0' in the string. 00532 _M_length(__str.length()); 00533 __str._M_data(__str._M_local_data()); 00534 __str._M_set_length(0); 00535 } 00536 00537 /** 00538 * @brief Construct string from an initializer %list. 00539 * @param __l std::initializer_list of characters. 00540 * @param __a Allocator to use (default is default allocator). 00541 */ 00542 basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()) 00543 : _M_dataplus(_M_local_data(), __a) 00544 { _M_construct(__l.begin(), __l.end()); } 00545 00546 basic_string(const basic_string& __str, const _Alloc& __a) 00547 : _M_dataplus(_M_local_data(), __a) 00548 { _M_construct(__str.begin(), __str.end()); } 00549 00550 basic_string(basic_string&& __str, const _Alloc& __a) 00551 noexcept(_Alloc_traits::_S_always_equal()) 00552 : _M_dataplus(_M_local_data(), __a) 00553 { 00554 if (__str._M_is_local()) 00555 { 00556 traits_type::copy(_M_local_buf, __str._M_local_buf, 00557 _S_local_capacity + 1); 00558 _M_length(__str.length()); 00559 __str._M_set_length(0); 00560 } 00561 else if (_Alloc_traits::_S_always_equal() 00562 || __str.get_allocator() == __a) 00563 { 00564 _M_data(__str._M_data()); 00565 _M_length(__str.length()); 00566 _M_capacity(__str._M_allocated_capacity); 00567 __str._M_data(__str._M_local_buf); 00568 __str._M_set_length(0); 00569 } 00570 else 00571 _M_construct(__str.begin(), __str.end()); 00572 } 00573 00574 #endif // C++11 00575 00576 /** 00577 * @brief Construct string as copy of a range. 00578 * @param __beg Start of range. 00579 * @param __end End of range. 00580 * @param __a Allocator to use (default is default allocator). 00581 */ 00582 #if __cplusplus >= 201103L 00583 template<typename _InputIterator, 00584 typename = std::_RequireInputIter<_InputIterator>> 00585 #else 00586 template<typename _InputIterator> 00587 #endif 00588 basic_string(_InputIterator __beg, _InputIterator __end, 00589 const _Alloc& __a = _Alloc()) 00590 : _M_dataplus(_M_local_data(), __a) 00591 { _M_construct(__beg, __end); } 00592 00593 #if __cplusplus > 201402L 00594 /** 00595 * @brief Construct string from a substring of a string_view. 00596 * @param __t Source string view. 00597 * @param __pos The index of the first character to copy from __t. 00598 * @param __n The number of characters to copy from __t. 00599 * @param __a Allocator to use. 00600 */ 00601 template<typename _Tp, typename = _If_sv<_Tp, void>> 00602 basic_string(const _Tp& __t, size_type __pos, size_type __n, 00603 const _Alloc& __a = _Alloc()) 00604 : basic_string(__sv_type(__t).substr(__pos, __n), __a) { } 00605 00606 /** 00607 * @brief Construct string from a string_view. 00608 * @param __sv Source string view. 00609 * @param __a Allocator to use (default is default allocator). 00610 */ 00611 explicit 00612 basic_string(__sv_type __sv, const _Alloc& __a = _Alloc()) 00613 : basic_string(__sv.data(), __sv.size(), __a) { } 00614 #endif // C++17 00615 00616 /** 00617 * @brief Destroy the string instance. 00618 */ 00619 ~basic_string() 00620 { _M_dispose(); } 00621 00622 /** 00623 * @brief Assign the value of @a str to this string. 00624 * @param __str Source string. 00625 */ 00626 basic_string& 00627 operator=(const basic_string& __str) 00628 { 00629 #if __cplusplus >= 201103L 00630 if (_Alloc_traits::_S_propagate_on_copy_assign()) 00631 { 00632 if (!_Alloc_traits::_S_always_equal() && !_M_is_local() 00633 && _M_get_allocator() != __str._M_get_allocator()) 00634 { 00635 // Propagating allocator cannot free existing storage so must 00636 // deallocate it before replacing current allocator. 00637 if (__str.size() <= _S_local_capacity) 00638 { 00639 _M_destroy(_M_allocated_capacity); 00640 _M_data(_M_local_data()); 00641 _M_set_length(0); 00642 } 00643 else 00644 { 00645 const auto __len = __str.size(); 00646 auto __alloc = __str._M_get_allocator(); 00647 // If this allocation throws there are no effects: 00648 auto __ptr = _Alloc_traits::allocate(__alloc, __len + 1); 00649 _M_destroy(_M_allocated_capacity); 00650 _M_data(__ptr); 00651 _M_capacity(__len); 00652 _M_set_length(__len); 00653 } 00654 } 00655 std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator()); 00656 } 00657 #endif 00658 return this->assign(__str); 00659 } 00660 00661 /** 00662 * @brief Copy contents of @a s into this string. 00663 * @param __s Source null-terminated string. 00664 */ 00665 basic_string& 00666 operator=(const _CharT* __s) 00667 { return this->assign(__s); } 00668 00669 /** 00670 * @brief Set value to string of length 1. 00671 * @param __c Source character. 00672 * 00673 * Assigning to a character makes this string length 1 and 00674 * (*this)[0] == @a c. 00675 */ 00676 basic_string& 00677 operator=(_CharT __c) 00678 { 00679 this->assign(1, __c); 00680 return *this; 00681 } 00682 00683 #if __cplusplus >= 201103L 00684 /** 00685 * @brief Move assign the value of @a str to this string. 00686 * @param __str Source string. 00687 * 00688 * The contents of @a str are moved into this string (without copying). 00689 * @a str is a valid, but unspecified string. 00690 **/ 00691 // PR 58265, this should be noexcept. 00692 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00693 // 2063. Contradictory requirements for string move assignment 00694 basic_string& 00695 operator=(basic_string&& __str) 00696 noexcept(_Alloc_traits::_S_nothrow_move()) 00697 { 00698 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign() 00699 && !_Alloc_traits::_S_always_equal() 00700 && _M_get_allocator() != __str._M_get_allocator()) 00701 { 00702 // Destroy existing storage before replacing allocator. 00703 _M_destroy(_M_allocated_capacity); 00704 _M_data(_M_local_data()); 00705 _M_set_length(0); 00706 } 00707 // Replace allocator if POCMA is true. 00708 std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator()); 00709 00710 if (!__str._M_is_local() 00711 && (_Alloc_traits::_S_propagate_on_move_assign() 00712 || _Alloc_traits::_S_always_equal())) 00713 { 00714 pointer __data = nullptr; 00715 size_type __capacity; 00716 if (!_M_is_local()) 00717 { 00718 if (_Alloc_traits::_S_always_equal()) 00719 { 00720 __data = _M_data(); 00721 __capacity = _M_allocated_capacity; 00722 } 00723 else 00724 _M_destroy(_M_allocated_capacity); 00725 } 00726 00727 _M_data(__str._M_data()); 00728 _M_length(__str.length()); 00729 _M_capacity(__str._M_allocated_capacity); 00730 if (__data) 00731 { 00732 __str._M_data(__data); 00733 __str._M_capacity(__capacity); 00734 } 00735 else 00736 __str._M_data(__str._M_local_buf); 00737 } 00738 else 00739 assign(__str); 00740 __str.clear(); 00741 return *this; 00742 } 00743 00744 /** 00745 * @brief Set value to string constructed from initializer %list. 00746 * @param __l std::initializer_list. 00747 */ 00748 basic_string& 00749 operator=(initializer_list<_CharT> __l) 00750 { 00751 this->assign(__l.begin(), __l.size()); 00752 return *this; 00753 } 00754 #endif // C++11 00755 00756 #if __cplusplus > 201402L 00757 /** 00758 * @brief Set value to string constructed from a string_view. 00759 * @param __sv A string_view. 00760 */ 00761 template<typename _Tp> 00762 _If_sv<_Tp, basic_string&> 00763 operator=(_Tp __sv) 00764 { return this->assign(__sv); } 00765 00766 /** 00767 * @brief Convert to a string_view. 00768 * @return A string_view. 00769 */ 00770 operator __sv_type() const noexcept 00771 { return __sv_type(data(), size()); } 00772 #endif // C++17 00773 00774 // Iterators: 00775 /** 00776 * Returns a read/write iterator that points to the first character in 00777 * the %string. 00778 */ 00779 iterator 00780 begin() _GLIBCXX_NOEXCEPT 00781 { return iterator(_M_data()); } 00782 00783 /** 00784 * Returns a read-only (constant) iterator that points to the first 00785 * character in the %string. 00786 */ 00787 const_iterator 00788 begin() const _GLIBCXX_NOEXCEPT 00789 { return const_iterator(_M_data()); } 00790 00791 /** 00792 * Returns a read/write iterator that points one past the last 00793 * character in the %string. 00794 */ 00795 iterator 00796 end() _GLIBCXX_NOEXCEPT 00797 { return iterator(_M_data() + this->size()); } 00798 00799 /** 00800 * Returns a read-only (constant) iterator that points one past the 00801 * last character in the %string. 00802 */ 00803 const_iterator 00804 end() const _GLIBCXX_NOEXCEPT 00805 { return const_iterator(_M_data() + this->size()); } 00806 00807 /** 00808 * Returns a read/write reverse iterator that points to the last 00809 * character in the %string. Iteration is done in reverse element 00810 * order. 00811 */ 00812 reverse_iterator 00813 rbegin() _GLIBCXX_NOEXCEPT 00814 { return reverse_iterator(this->end()); } 00815 00816 /** 00817 * Returns a read-only (constant) reverse iterator that points 00818 * to the last character in the %string. Iteration is done in 00819 * reverse element order. 00820 */ 00821 const_reverse_iterator 00822 rbegin() const _GLIBCXX_NOEXCEPT 00823 { return const_reverse_iterator(this->end()); } 00824 00825 /** 00826 * Returns a read/write reverse iterator that points to one before the 00827 * first character in the %string. Iteration is done in reverse 00828 * element order. 00829 */ 00830 reverse_iterator 00831 rend() _GLIBCXX_NOEXCEPT 00832 { return reverse_iterator(this->begin()); } 00833 00834 /** 00835 * Returns a read-only (constant) reverse iterator that points 00836 * to one before the first character in the %string. Iteration 00837 * is done in reverse element order. 00838 */ 00839 const_reverse_iterator 00840 rend() const _GLIBCXX_NOEXCEPT 00841 { return const_reverse_iterator(this->begin()); } 00842 00843 #if __cplusplus >= 201103L 00844 /** 00845 * Returns a read-only (constant) iterator that points to the first 00846 * character in the %string. 00847 */ 00848 const_iterator 00849 cbegin() const noexcept 00850 { return const_iterator(this->_M_data()); } 00851 00852 /** 00853 * Returns a read-only (constant) iterator that points one past the 00854 * last character in the %string. 00855 */ 00856 const_iterator 00857 cend() const noexcept 00858 { return const_iterator(this->_M_data() + this->size()); } 00859 00860 /** 00861 * Returns a read-only (constant) reverse iterator that points 00862 * to the last character in the %string. Iteration is done in 00863 * reverse element order. 00864 */ 00865 const_reverse_iterator 00866 crbegin() const noexcept 00867 { return const_reverse_iterator(this->end()); } 00868 00869 /** 00870 * Returns a read-only (constant) reverse iterator that points 00871 * to one before the first character in the %string. Iteration 00872 * is done in reverse element order. 00873 */ 00874 const_reverse_iterator 00875 crend() const noexcept 00876 { return const_reverse_iterator(this->begin()); } 00877 #endif 00878 00879 public: 00880 // Capacity: 00881 /// Returns the number of characters in the string, not including any 00882 /// null-termination. 00883 size_type 00884 size() const _GLIBCXX_NOEXCEPT 00885 { return _M_string_length; } 00886 00887 /// Returns the number of characters in the string, not including any 00888 /// null-termination. 00889 size_type 00890 length() const _GLIBCXX_NOEXCEPT 00891 { return _M_string_length; } 00892 00893 /// Returns the size() of the largest possible %string. 00894 size_type 00895 max_size() const _GLIBCXX_NOEXCEPT 00896 { return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; } 00897 00898 /** 00899 * @brief Resizes the %string to the specified number of characters. 00900 * @param __n Number of characters the %string should contain. 00901 * @param __c Character to fill any new elements. 00902 * 00903 * This function will %resize the %string to the specified 00904 * number of characters. If the number is smaller than the 00905 * %string's current size the %string is truncated, otherwise 00906 * the %string is extended and new elements are %set to @a __c. 00907 */ 00908 void 00909 resize(size_type __n, _CharT __c); 00910 00911 /** 00912 * @brief Resizes the %string to the specified number of characters. 00913 * @param __n Number of characters the %string should contain. 00914 * 00915 * This function will resize the %string to the specified length. If 00916 * the new size is smaller than the %string's current size the %string 00917 * is truncated, otherwise the %string is extended and new characters 00918 * are default-constructed. For basic types such as char, this means 00919 * setting them to 0. 00920 */ 00921 void 00922 resize(size_type __n) 00923 { this->resize(__n, _CharT()); } 00924 00925 #if __cplusplus >= 201103L 00926 /// A non-binding request to reduce capacity() to size(). 00927 void 00928 shrink_to_fit() noexcept 00929 { 00930 #if __cpp_exceptions 00931 if (capacity() > size()) 00932 { 00933 try 00934 { reserve(0); } 00935 catch(...) 00936 { } 00937 } 00938 #endif 00939 } 00940 #endif 00941 00942 /** 00943 * Returns the total number of characters that the %string can hold 00944 * before needing to allocate more memory. 00945 */ 00946 size_type 00947 capacity() const _GLIBCXX_NOEXCEPT 00948 { 00949 return _M_is_local() ? size_type(_S_local_capacity) 00950 : _M_allocated_capacity; 00951 } 00952 00953 /** 00954 * @brief Attempt to preallocate enough memory for specified number of 00955 * characters. 00956 * @param __res_arg Number of characters required. 00957 * @throw std::length_error If @a __res_arg exceeds @c max_size(). 00958 * 00959 * This function attempts to reserve enough memory for the 00960 * %string to hold the specified number of characters. If the 00961 * number requested is more than max_size(), length_error is 00962 * thrown. 00963 * 00964 * The advantage of this function is that if optimal code is a 00965 * necessity and the user can determine the string length that will be 00966 * required, the user can reserve the memory in %advance, and thus 00967 * prevent a possible reallocation of memory and copying of %string 00968 * data. 00969 */ 00970 void 00971 reserve(size_type __res_arg = 0); 00972 00973 /** 00974 * Erases the string, making it empty. 00975 */ 00976 void 00977 clear() _GLIBCXX_NOEXCEPT 00978 { _M_set_length(0); } 00979 00980 /** 00981 * Returns true if the %string is empty. Equivalent to 00982 * <code>*this == ""</code>. 00983 */ 00984 bool 00985 empty() const _GLIBCXX_NOEXCEPT 00986 { return this->size() == 0; } 00987 00988 // Element access: 00989 /** 00990 * @brief Subscript access to the data contained in the %string. 00991 * @param __pos The index of the character to access. 00992 * @return Read-only (constant) reference to the character. 00993 * 00994 * This operator allows for easy, array-style, data access. 00995 * Note that data access with this operator is unchecked and 00996 * out_of_range lookups are not defined. (For checked lookups 00997 * see at().) 00998 */ 00999 const_reference 01000 operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT 01001 { 01002 __glibcxx_assert(__pos <= size()); 01003 return _M_data()[__pos]; 01004 } 01005 01006 /** 01007 * @brief Subscript access to the data contained in the %string. 01008 * @param __pos The index of the character to access. 01009 * @return Read/write reference to the character. 01010 * 01011 * This operator allows for easy, array-style, data access. 01012 * Note that data access with this operator is unchecked and 01013 * out_of_range lookups are not defined. (For checked lookups 01014 * see at().) 01015 */ 01016 reference 01017 operator[](size_type __pos) 01018 { 01019 // Allow pos == size() both in C++98 mode, as v3 extension, 01020 // and in C++11 mode. 01021 __glibcxx_assert(__pos <= size()); 01022 // In pedantic mode be strict in C++98 mode. 01023 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size()); 01024 return _M_data()[__pos]; 01025 } 01026 01027 /** 01028 * @brief Provides access to the data contained in the %string. 01029 * @param __n The index of the character to access. 01030 * @return Read-only (const) reference to the character. 01031 * @throw std::out_of_range If @a n is an invalid index. 01032 * 01033 * This function provides for safer data access. The parameter is 01034 * first checked that it is in the range of the string. The function 01035 * throws out_of_range if the check fails. 01036 */ 01037 const_reference 01038 at(size_type __n) const 01039 { 01040 if (__n >= this->size()) 01041 __throw_out_of_range_fmt(__N("basic_string::at: __n " 01042 "(which is %zu) >= this->size() " 01043 "(which is %zu)"), 01044 __n, this->size()); 01045 return _M_data()[__n]; 01046 } 01047 01048 /** 01049 * @brief Provides access to the data contained in the %string. 01050 * @param __n The index of the character to access. 01051 * @return Read/write reference to the character. 01052 * @throw std::out_of_range If @a n is an invalid index. 01053 * 01054 * This function provides for safer data access. The parameter is 01055 * first checked that it is in the range of the string. The function 01056 * throws out_of_range if the check fails. 01057 */ 01058 reference 01059 at(size_type __n) 01060 { 01061 if (__n >= size()) 01062 __throw_out_of_range_fmt(__N("basic_string::at: __n " 01063 "(which is %zu) >= this->size() " 01064 "(which is %zu)"), 01065 __n, this->size()); 01066 return _M_data()[__n]; 01067 } 01068 01069 #if __cplusplus >= 201103L 01070 /** 01071 * Returns a read/write reference to the data at the first 01072 * element of the %string. 01073 */ 01074 reference 01075 front() noexcept 01076 { 01077 __glibcxx_assert(!empty()); 01078 return operator[](0); 01079 } 01080 01081 /** 01082 * Returns a read-only (constant) reference to the data at the first 01083 * element of the %string. 01084 */ 01085 const_reference 01086 front() const noexcept 01087 { 01088 __glibcxx_assert(!empty()); 01089 return operator[](0); 01090 } 01091 01092 /** 01093 * Returns a read/write reference to the data at the last 01094 * element of the %string. 01095 */ 01096 reference 01097 back() noexcept 01098 { 01099 __glibcxx_assert(!empty()); 01100 return operator[](this->size() - 1); 01101 } 01102 01103 /** 01104 * Returns a read-only (constant) reference to the data at the 01105 * last element of the %string. 01106 */ 01107 const_reference 01108 back() const noexcept 01109 { 01110 __glibcxx_assert(!empty()); 01111 return operator[](this->size() - 1); 01112 } 01113 #endif 01114 01115 // Modifiers: 01116 /** 01117 * @brief Append a string to this string. 01118 * @param __str The string to append. 01119 * @return Reference to this string. 01120 */ 01121 basic_string& 01122 operator+=(const basic_string& __str) 01123 { return this->append(__str); } 01124 01125 /** 01126 * @brief Append a C string. 01127 * @param __s The C string to append. 01128 * @return Reference to this string. 01129 */ 01130 basic_string& 01131 operator+=(const _CharT* __s) 01132 { return this->append(__s); } 01133 01134 /** 01135 * @brief Append a character. 01136 * @param __c The character to append. 01137 * @return Reference to this string. 01138 */ 01139 basic_string& 01140 operator+=(_CharT __c) 01141 { 01142 this->push_back(__c); 01143 return *this; 01144 } 01145 01146 #if __cplusplus >= 201103L 01147 /** 01148 * @brief Append an initializer_list of characters. 01149 * @param __l The initializer_list of characters to be appended. 01150 * @return Reference to this string. 01151 */ 01152 basic_string& 01153 operator+=(initializer_list<_CharT> __l) 01154 { return this->append(__l.begin(), __l.size()); } 01155 #endif // C++11 01156 01157 #if __cplusplus > 201402L 01158 /** 01159 * @brief Append a string_view. 01160 * @param __sv The string_view to be appended. 01161 * @return Reference to this string. 01162 */ 01163 basic_string& 01164 operator+=(__sv_type __sv) 01165 { return this->append(__sv); } 01166 #endif // C++17 01167 01168 /** 01169 * @brief Append a string to this string. 01170 * @param __str The string to append. 01171 * @return Reference to this string. 01172 */ 01173 basic_string& 01174 append(const basic_string& __str) 01175 { return _M_append(__str._M_data(), __str.size()); } 01176 01177 /** 01178 * @brief Append a substring. 01179 * @param __str The string to append. 01180 * @param __pos Index of the first character of str to append. 01181 * @param __n The number of characters to append. 01182 * @return Reference to this string. 01183 * @throw std::out_of_range if @a __pos is not a valid index. 01184 * 01185 * This function appends @a __n characters from @a __str 01186 * starting at @a __pos to this string. If @a __n is is larger 01187 * than the number of available characters in @a __str, the 01188 * remainder of @a __str is appended. 01189 */ 01190 basic_string& 01191 append(const basic_string& __str, size_type __pos, size_type __n) 01192 { return _M_append(__str._M_data() 01193 + __str._M_check(__pos, "basic_string::append"), 01194 __str._M_limit(__pos, __n)); } 01195 01196 /** 01197 * @brief Append a C substring. 01198 * @param __s The C string to append. 01199 * @param __n The number of characters to append. 01200 * @return Reference to this string. 01201 */ 01202 basic_string& 01203 append(const _CharT* __s, size_type __n) 01204 { 01205 __glibcxx_requires_string_len(__s, __n); 01206 _M_check_length(size_type(0), __n, "basic_string::append"); 01207 return _M_append(__s, __n); 01208 } 01209 01210 /** 01211 * @brief Append a C string. 01212 * @param __s The C string to append. 01213 * @return Reference to this string. 01214 */ 01215 basic_string& 01216 append(const _CharT* __s) 01217 { 01218 __glibcxx_requires_string(__s); 01219 const size_type __n = traits_type::length(__s); 01220 _M_check_length(size_type(0), __n, "basic_string::append"); 01221 return _M_append(__s, __n); 01222 } 01223 01224 /** 01225 * @brief Append multiple characters. 01226 * @param __n The number of characters to append. 01227 * @param __c The character to use. 01228 * @return Reference to this string. 01229 * 01230 * Appends __n copies of __c to this string. 01231 */ 01232 basic_string& 01233 append(size_type __n, _CharT __c) 01234 { return _M_replace_aux(this->size(), size_type(0), __n, __c); } 01235 01236 #if __cplusplus >= 201103L 01237 /** 01238 * @brief Append an initializer_list of characters. 01239 * @param __l The initializer_list of characters to append. 01240 * @return Reference to this string. 01241 */ 01242 basic_string& 01243 append(initializer_list<_CharT> __l) 01244 { return this->append(__l.begin(), __l.size()); } 01245 #endif // C++11 01246 01247 /** 01248 * @brief Append a range of characters. 01249 * @param __first Iterator referencing the first character to append. 01250 * @param __last Iterator marking the end of the range. 01251 * @return Reference to this string. 01252 * 01253 * Appends characters in the range [__first,__last) to this string. 01254 */ 01255 #if __cplusplus >= 201103L 01256 template<class _InputIterator, 01257 typename = std::_RequireInputIter<_InputIterator>> 01258 #else 01259 template<class _InputIterator> 01260 #endif 01261 basic_string& 01262 append(_InputIterator __first, _InputIterator __last) 01263 { return this->replace(end(), end(), __first, __last); } 01264 01265 #if __cplusplus > 201402L 01266 /** 01267 * @brief Append a string_view. 01268 * @param __sv The string_view to be appended. 01269 * @return Reference to this string. 01270 */ 01271 basic_string& 01272 append(__sv_type __sv) 01273 { return this->append(__sv.data(), __sv.size()); } 01274 01275 /** 01276 * @brief Append a range of characters from a string_view. 01277 * @param __sv The string_view to be appended from. 01278 * @param __pos The position in the string_view to append from. 01279 * @param __n The number of characters to append from the string_view. 01280 * @return Reference to this string. 01281 */ 01282 template <typename _Tp> 01283 _If_sv<_Tp, basic_string&> 01284 append(const _Tp& __svt, size_type __pos, size_type __n = npos) 01285 { 01286 __sv_type __sv = __svt; 01287 return _M_append(__sv.data() 01288 + __sv._M_check(__pos, "basic_string::append"), 01289 __sv._M_limit(__pos, __n)); 01290 } 01291 #endif // C++17 01292 01293 /** 01294 * @brief Append a single character. 01295 * @param __c Character to append. 01296 */ 01297 void 01298 push_back(_CharT __c) 01299 { 01300 const size_type __size = this->size(); 01301 if (__size + 1 > this->capacity()) 01302 this->_M_mutate(__size, size_type(0), 0, size_type(1)); 01303 traits_type::assign(this->_M_data()[__size], __c); 01304 this->_M_set_length(__size + 1); 01305 } 01306 01307 /** 01308 * @brief Set value to contents of another string. 01309 * @param __str Source string to use. 01310 * @return Reference to this string. 01311 */ 01312 basic_string& 01313 assign(const basic_string& __str) 01314 { 01315 this->_M_assign(__str); 01316 return *this; 01317 } 01318 01319 #if __cplusplus >= 201103L 01320 /** 01321 * @brief Set value to contents of another string. 01322 * @param __str Source string to use. 01323 * @return Reference to this string. 01324 * 01325 * This function sets this string to the exact contents of @a __str. 01326 * @a __str is a valid, but unspecified string. 01327 */ 01328 basic_string& 01329 assign(basic_string&& __str) 01330 noexcept(_Alloc_traits::_S_nothrow_move()) 01331 { 01332 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01333 // 2063. Contradictory requirements for string move assignment 01334 return *this = std::move(__str); 01335 } 01336 #endif // C++11 01337 01338 /** 01339 * @brief Set value to a substring of a string. 01340 * @param __str The string to use. 01341 * @param __pos Index of the first character of str. 01342 * @param __n Number of characters to use. 01343 * @return Reference to this string. 01344 * @throw std::out_of_range if @a pos is not a valid index. 01345 * 01346 * This function sets this string to the substring of @a __str 01347 * consisting of @a __n characters at @a __pos. If @a __n is 01348 * is larger than the number of available characters in @a 01349 * __str, the remainder of @a __str is used. 01350 */ 01351 basic_string& 01352 assign(const basic_string& __str, size_type __pos, size_type __n) 01353 { return _M_replace(size_type(0), this->size(), __str._M_data() 01354 + __str._M_check(__pos, "basic_string::assign"), 01355 __str._M_limit(__pos, __n)); } 01356 01357 /** 01358 * @brief Set value to a C substring. 01359 * @param __s The C string to use. 01360 * @param __n Number of characters to use. 01361 * @return Reference to this string. 01362 * 01363 * This function sets the value of this string to the first @a __n 01364 * characters of @a __s. If @a __n is is larger than the number of 01365 * available characters in @a __s, the remainder of @a __s is used. 01366 */ 01367 basic_string& 01368 assign(const _CharT* __s, size_type __n) 01369 { 01370 __glibcxx_requires_string_len(__s, __n); 01371 return _M_replace(size_type(0), this->size(), __s, __n); 01372 } 01373 01374 /** 01375 * @brief Set value to contents of a C string. 01376 * @param __s The C string to use. 01377 * @return Reference to this string. 01378 * 01379 * This function sets the value of this string to the value of @a __s. 01380 * The data is copied, so there is no dependence on @a __s once the 01381 * function returns. 01382 */ 01383 basic_string& 01384 assign(const _CharT* __s) 01385 { 01386 __glibcxx_requires_string(__s); 01387 return _M_replace(size_type(0), this->size(), __s, 01388 traits_type::length(__s)); 01389 } 01390 01391 /** 01392 * @brief Set value to multiple characters. 01393 * @param __n Length of the resulting string. 01394 * @param __c The character to use. 01395 * @return Reference to this string. 01396 * 01397 * This function sets the value of this string to @a __n copies of 01398 * character @a __c. 01399 */ 01400 basic_string& 01401 assign(size_type __n, _CharT __c) 01402 { return _M_replace_aux(size_type(0), this->size(), __n, __c); } 01403 01404 /** 01405 * @brief Set value to a range of characters. 01406 * @param __first Iterator referencing the first character to append. 01407 * @param __last Iterator marking the end of the range. 01408 * @return Reference to this string. 01409 * 01410 * Sets value of string to characters in the range [__first,__last). 01411 */ 01412 #if __cplusplus >= 201103L 01413 template<class _InputIterator, 01414 typename = std::_RequireInputIter<_InputIterator>> 01415 #else 01416 template<class _InputIterator> 01417 #endif 01418 basic_string& 01419 assign(_InputIterator __first, _InputIterator __last) 01420 { return this->replace(begin(), end(), __first, __last); } 01421 01422 #if __cplusplus >= 201103L 01423 /** 01424 * @brief Set value to an initializer_list of characters. 01425 * @param __l The initializer_list of characters to assign. 01426 * @return Reference to this string. 01427 */ 01428 basic_string& 01429 assign(initializer_list<_CharT> __l) 01430 { return this->assign(__l.begin(), __l.size()); } 01431 #endif // C++11 01432 01433 #if __cplusplus > 201402L 01434 /** 01435 * @brief Set value from a string_view. 01436 * @param __sv The source string_view. 01437 * @return Reference to this string. 01438 */ 01439 basic_string& 01440 assign(__sv_type __sv) 01441 { return this->assign(__sv.data(), __sv.size()); } 01442 01443 /** 01444 * @brief Set value from a range of characters in a string_view. 01445 * @param __sv The source string_view. 01446 * @param __pos The position in the string_view to assign from. 01447 * @param __n The number of characters to assign. 01448 * @return Reference to this string. 01449 */ 01450 template <typename _Tp> 01451 _If_sv<_Tp, basic_string&> 01452 assign(const _Tp& __svt, size_type __pos, size_type __n = npos) 01453 { 01454 __sv_type __sv = __svt; 01455 return _M_replace(size_type(0), this->size(), __sv.data() 01456 + __sv._M_check(__pos, "basic_string::assign"), 01457 __sv._M_limit(__pos, __n)); 01458 } 01459 #endif // C++17 01460 01461 #if __cplusplus >= 201103L 01462 /** 01463 * @brief Insert multiple characters. 01464 * @param __p Const_iterator referencing location in string to 01465 * insert at. 01466 * @param __n Number of characters to insert 01467 * @param __c The character to insert. 01468 * @return Iterator referencing the first inserted char. 01469 * @throw std::length_error If new length exceeds @c max_size(). 01470 * 01471 * Inserts @a __n copies of character @a __c starting at the 01472 * position referenced by iterator @a __p. If adding 01473 * characters causes the length to exceed max_size(), 01474 * length_error is thrown. The value of the string doesn't 01475 * change if an error is thrown. 01476 */ 01477 iterator 01478 insert(const_iterator __p, size_type __n, _CharT __c) 01479 { 01480 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); 01481 const size_type __pos = __p - begin(); 01482 this->replace(__p, __p, __n, __c); 01483 return iterator(this->_M_data() + __pos); 01484 } 01485 #else 01486 /** 01487 * @brief Insert multiple characters. 01488 * @param __p Iterator referencing location in string to insert at. 01489 * @param __n Number of characters to insert 01490 * @param __c The character to insert. 01491 * @throw std::length_error If new length exceeds @c max_size(). 01492 * 01493 * Inserts @a __n copies of character @a __c starting at the 01494 * position referenced by iterator @a __p. If adding 01495 * characters causes the length to exceed max_size(), 01496 * length_error is thrown. The value of the string doesn't 01497 * change if an error is thrown. 01498 */ 01499 void 01500 insert(iterator __p, size_type __n, _CharT __c) 01501 { this->replace(__p, __p, __n, __c); } 01502 #endif 01503 01504 #if __cplusplus >= 201103L 01505 /** 01506 * @brief Insert a range of characters. 01507 * @param __p Const_iterator referencing location in string to 01508 * insert at. 01509 * @param __beg Start of range. 01510 * @param __end End of range. 01511 * @return Iterator referencing the first inserted char. 01512 * @throw std::length_error If new length exceeds @c max_size(). 01513 * 01514 * Inserts characters in range [beg,end). If adding characters 01515 * causes the length to exceed max_size(), length_error is 01516 * thrown. The value of the string doesn't change if an error 01517 * is thrown. 01518 */ 01519 template<class _InputIterator, 01520 typename = std::_RequireInputIter<_InputIterator>> 01521 iterator 01522 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end) 01523 { 01524 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); 01525 const size_type __pos = __p - begin(); 01526 this->replace(__p, __p, __beg, __end); 01527 return iterator(this->_M_data() + __pos); 01528 } 01529 #else 01530 /** 01531 * @brief Insert a range of characters. 01532 * @param __p Iterator referencing location in string to insert at. 01533 * @param __beg Start of range. 01534 * @param __end End of range. 01535 * @throw std::length_error If new length exceeds @c max_size(). 01536 * 01537 * Inserts characters in range [__beg,__end). If adding 01538 * characters causes the length to exceed max_size(), 01539 * length_error is thrown. The value of the string doesn't 01540 * change if an error is thrown. 01541 */ 01542 template<class _InputIterator> 01543 void 01544 insert(iterator __p, _InputIterator __beg, _InputIterator __end) 01545 { this->replace(__p, __p, __beg, __end); } 01546 #endif 01547 01548 #if __cplusplus >= 201103L 01549 /** 01550 * @brief Insert an initializer_list of characters. 01551 * @param __p Iterator referencing location in string to insert at. 01552 * @param __l The initializer_list of characters to insert. 01553 * @throw std::length_error If new length exceeds @c max_size(). 01554 */ 01555 void 01556 insert(iterator __p, initializer_list<_CharT> __l) 01557 { 01558 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); 01559 this->insert(__p - begin(), __l.begin(), __l.size()); 01560 } 01561 #endif // C++11 01562 01563 /** 01564 * @brief Insert value of a string. 01565 * @param __pos1 Iterator referencing location in string to insert at. 01566 * @param __str The string to insert. 01567 * @return Reference to this string. 01568 * @throw std::length_error If new length exceeds @c max_size(). 01569 * 01570 * Inserts value of @a __str starting at @a __pos1. If adding 01571 * characters causes the length to exceed max_size(), 01572 * length_error is thrown. The value of the string doesn't 01573 * change if an error is thrown. 01574 */ 01575 basic_string& 01576 insert(size_type __pos1, const basic_string& __str) 01577 { return this->replace(__pos1, size_type(0), 01578 __str._M_data(), __str.size()); } 01579 01580 /** 01581 * @brief Insert a substring. 01582 * @param __pos1 Iterator referencing location in string to insert at. 01583 * @param __str The string to insert. 01584 * @param __pos2 Start of characters in str to insert. 01585 * @param __n Number of characters to insert. 01586 * @return Reference to this string. 01587 * @throw std::length_error If new length exceeds @c max_size(). 01588 * @throw std::out_of_range If @a pos1 > size() or 01589 * @a __pos2 > @a str.size(). 01590 * 01591 * Starting at @a pos1, insert @a __n character of @a __str 01592 * beginning with @a __pos2. If adding characters causes the 01593 * length to exceed max_size(), length_error is thrown. If @a 01594 * __pos1 is beyond the end of this string or @a __pos2 is 01595 * beyond the end of @a __str, out_of_range is thrown. The 01596 * value of the string doesn't change if an error is thrown. 01597 */ 01598 basic_string& 01599 insert(size_type __pos1, const basic_string& __str, 01600 size_type __pos2, size_type __n) 01601 { return this->replace(__pos1, size_type(0), __str._M_data() 01602 + __str._M_check(__pos2, "basic_string::insert"), 01603 __str._M_limit(__pos2, __n)); } 01604 01605 /** 01606 * @brief Insert a C substring. 01607 * @param __pos Iterator referencing location in string to insert at. 01608 * @param __s The C string to insert. 01609 * @param __n The number of characters to insert. 01610 * @return Reference to this string. 01611 * @throw std::length_error If new length exceeds @c max_size(). 01612 * @throw std::out_of_range If @a __pos is beyond the end of this 01613 * string. 01614 * 01615 * Inserts the first @a __n characters of @a __s starting at @a 01616 * __pos. If adding characters causes the length to exceed 01617 * max_size(), length_error is thrown. If @a __pos is beyond 01618 * end(), out_of_range is thrown. The value of the string 01619 * doesn't change if an error is thrown. 01620 */ 01621 basic_string& 01622 insert(size_type __pos, const _CharT* __s, size_type __n) 01623 { return this->replace(__pos, size_type(0), __s, __n); } 01624 01625 /** 01626 * @brief Insert a C string. 01627 * @param __pos Iterator referencing location in string to insert at. 01628 * @param __s The C string to insert. 01629 * @return Reference to this string. 01630 * @throw std::length_error If new length exceeds @c max_size(). 01631 * @throw std::out_of_range If @a pos is beyond the end of this 01632 * string. 01633 * 01634 * Inserts the first @a n characters of @a __s starting at @a __pos. If 01635 * adding characters causes the length to exceed max_size(), 01636 * length_error is thrown. If @a __pos is beyond end(), out_of_range is 01637 * thrown. The value of the string doesn't change if an error is 01638 * thrown. 01639 */ 01640 basic_string& 01641 insert(size_type __pos, const _CharT* __s) 01642 { 01643 __glibcxx_requires_string(__s); 01644 return this->replace(__pos, size_type(0), __s, 01645 traits_type::length(__s)); 01646 } 01647 01648 /** 01649 * @brief Insert multiple characters. 01650 * @param __pos Index in string to insert at. 01651 * @param __n Number of characters to insert 01652 * @param __c The character to insert. 01653 * @return Reference to this string. 01654 * @throw std::length_error If new length exceeds @c max_size(). 01655 * @throw std::out_of_range If @a __pos is beyond the end of this 01656 * string. 01657 * 01658 * Inserts @a __n copies of character @a __c starting at index 01659 * @a __pos. If adding characters causes the length to exceed 01660 * max_size(), length_error is thrown. If @a __pos > length(), 01661 * out_of_range is thrown. The value of the string doesn't 01662 * change if an error is thrown. 01663 */ 01664 basic_string& 01665 insert(size_type __pos, size_type __n, _CharT __c) 01666 { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), 01667 size_type(0), __n, __c); } 01668 01669 /** 01670 * @brief Insert one character. 01671 * @param __p Iterator referencing position in string to insert at. 01672 * @param __c The character to insert. 01673 * @return Iterator referencing newly inserted char. 01674 * @throw std::length_error If new length exceeds @c max_size(). 01675 * 01676 * Inserts character @a __c at position referenced by @a __p. 01677 * If adding character causes the length to exceed max_size(), 01678 * length_error is thrown. If @a __p is beyond end of string, 01679 * out_of_range is thrown. The value of the string doesn't 01680 * change if an error is thrown. 01681 */ 01682 iterator 01683 insert(__const_iterator __p, _CharT __c) 01684 { 01685 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); 01686 const size_type __pos = __p - begin(); 01687 _M_replace_aux(__pos, size_type(0), size_type(1), __c); 01688 return iterator(_M_data() + __pos); 01689 } 01690 01691 #if __cplusplus > 201402L 01692 /** 01693 * @brief Insert a string_view. 01694 * @param __pos Iterator referencing position in string to insert at. 01695 * @param __sv The string_view to insert. 01696 * @return Reference to this string. 01697 */ 01698 basic_string& 01699 insert(size_type __pos, __sv_type __sv) 01700 { return this->insert(__pos, __sv.data(), __sv.size()); } 01701 01702 /** 01703 * @brief Insert a string_view. 01704 * @param __pos Iterator referencing position in string to insert at. 01705 * @param __sv The string_view to insert from. 01706 * @param __pos Iterator referencing position in string_view to insert 01707 * from. 01708 * @param __n The number of characters to insert. 01709 * @return Reference to this string. 01710 */ 01711 template <typename _Tp> 01712 _If_sv<_Tp, basic_string&> 01713 insert(size_type __pos1, const _Tp& __svt, 01714 size_type __pos2, size_type __n = npos) 01715 { 01716 __sv_type __sv = __svt; 01717 return this->replace(__pos1, size_type(0), __sv.data() 01718 + __sv._M_check(__pos2, "basic_string::insert"), 01719 __sv._M_limit(__pos2, __n)); 01720 } 01721 #endif // C++17 01722 01723 /** 01724 * @brief Remove characters. 01725 * @param __pos Index of first character to remove (default 0). 01726 * @param __n Number of characters to remove (default remainder). 01727 * @return Reference to this string. 01728 * @throw std::out_of_range If @a pos is beyond the end of this 01729 * string. 01730 * 01731 * Removes @a __n characters from this string starting at @a 01732 * __pos. The length of the string is reduced by @a __n. If 01733 * there are < @a __n characters to remove, the remainder of 01734 * the string is truncated. If @a __p is beyond end of string, 01735 * out_of_range is thrown. The value of the string doesn't 01736 * change if an error is thrown. 01737 */ 01738 basic_string& 01739 erase(size_type __pos = 0, size_type __n = npos) 01740 { 01741 _M_check(__pos, "basic_string::erase"); 01742 if (__n == npos) 01743 this->_M_set_length(__pos); 01744 else if (__n != 0) 01745 this->_M_erase(__pos, _M_limit(__pos, __n)); 01746 return *this; 01747 } 01748 01749 /** 01750 * @brief Remove one character. 01751 * @param __position Iterator referencing the character to remove. 01752 * @return iterator referencing same location after removal. 01753 * 01754 * Removes the character at @a __position from this string. The value 01755 * of the string doesn't change if an error is thrown. 01756 */ 01757 iterator 01758 erase(__const_iterator __position) 01759 { 01760 _GLIBCXX_DEBUG_PEDASSERT(__position >= begin() 01761 && __position < end()); 01762 const size_type __pos = __position - begin(); 01763 this->_M_erase(__pos, size_type(1)); 01764 return iterator(_M_data() + __pos); 01765 } 01766 01767 /** 01768 * @brief Remove a range of characters. 01769 * @param __first Iterator referencing the first character to remove. 01770 * @param __last Iterator referencing the end of the range. 01771 * @return Iterator referencing location of first after removal. 01772 * 01773 * Removes the characters in the range [first,last) from this string. 01774 * The value of the string doesn't change if an error is thrown. 01775 */ 01776 iterator 01777 erase(__const_iterator __first, __const_iterator __last) 01778 { 01779 _GLIBCXX_DEBUG_PEDASSERT(__first >= begin() && __first <= __last 01780 && __last <= end()); 01781 const size_type __pos = __first - begin(); 01782 if (__last == end()) 01783 this->_M_set_length(__pos); 01784 else 01785 this->_M_erase(__pos, __last - __first); 01786 return iterator(this->_M_data() + __pos); 01787 } 01788 01789 #if __cplusplus >= 201103L 01790 /** 01791 * @brief Remove the last character. 01792 * 01793 * The string must be non-empty. 01794 */ 01795 void 01796 pop_back() noexcept 01797 { 01798 __glibcxx_assert(!empty()); 01799 _M_erase(size() - 1, 1); 01800 } 01801 #endif // C++11 01802 01803 /** 01804 * @brief Replace characters with value from another string. 01805 * @param __pos Index of first character to replace. 01806 * @param __n Number of characters to be replaced. 01807 * @param __str String to insert. 01808 * @return Reference to this string. 01809 * @throw std::out_of_range If @a pos is beyond the end of this 01810 * string. 01811 * @throw std::length_error If new length exceeds @c max_size(). 01812 * 01813 * Removes the characters in the range [__pos,__pos+__n) from 01814 * this string. In place, the value of @a __str is inserted. 01815 * If @a __pos is beyond end of string, out_of_range is thrown. 01816 * If the length of the result exceeds max_size(), length_error 01817 * is thrown. The value of the string doesn't change if an 01818 * error is thrown. 01819 */ 01820 basic_string& 01821 replace(size_type __pos, size_type __n, const basic_string& __str) 01822 { return this->replace(__pos, __n, __str._M_data(), __str.size()); } 01823 01824 /** 01825 * @brief Replace characters with value from another string. 01826 * @param __pos1 Index of first character to replace. 01827 * @param __n1 Number of characters to be replaced. 01828 * @param __str String to insert. 01829 * @param __pos2 Index of first character of str to use. 01830 * @param __n2 Number of characters from str to use. 01831 * @return Reference to this string. 01832 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > 01833 * __str.size(). 01834 * @throw std::length_error If new length exceeds @c max_size(). 01835 * 01836 * Removes the characters in the range [__pos1,__pos1 + n) from this 01837 * string. In place, the value of @a __str is inserted. If @a __pos is 01838 * beyond end of string, out_of_range is thrown. If the length of the 01839 * result exceeds max_size(), length_error is thrown. The value of the 01840 * string doesn't change if an error is thrown. 01841 */ 01842 basic_string& 01843 replace(size_type __pos1, size_type __n1, const basic_string& __str, 01844 size_type __pos2, size_type __n2) 01845 { return this->replace(__pos1, __n1, __str._M_data() 01846 + __str._M_check(__pos2, "basic_string::replace"), 01847 __str._M_limit(__pos2, __n2)); } 01848 01849 /** 01850 * @brief Replace characters with value of a C substring. 01851 * @param __pos Index of first character to replace. 01852 * @param __n1 Number of characters to be replaced. 01853 * @param __s C string to insert. 01854 * @param __n2 Number of characters from @a s to use. 01855 * @return Reference to this string. 01856 * @throw std::out_of_range If @a pos1 > size(). 01857 * @throw std::length_error If new length exceeds @c max_size(). 01858 * 01859 * Removes the characters in the range [__pos,__pos + __n1) 01860 * from this string. In place, the first @a __n2 characters of 01861 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If 01862 * @a __pos is beyond end of string, out_of_range is thrown. If 01863 * the length of result exceeds max_size(), length_error is 01864 * thrown. The value of the string doesn't change if an error 01865 * is thrown. 01866 */ 01867 basic_string& 01868 replace(size_type __pos, size_type __n1, const _CharT* __s, 01869 size_type __n2) 01870 { 01871 __glibcxx_requires_string_len(__s, __n2); 01872 return _M_replace(_M_check(__pos, "basic_string::replace"), 01873 _M_limit(__pos, __n1), __s, __n2); 01874 } 01875 01876 /** 01877 * @brief Replace characters with value of a C string. 01878 * @param __pos Index of first character to replace. 01879 * @param __n1 Number of characters to be replaced. 01880 * @param __s C string to insert. 01881 * @return Reference to this string. 01882 * @throw std::out_of_range If @a pos > size(). 01883 * @throw std::length_error If new length exceeds @c max_size(). 01884 * 01885 * Removes the characters in the range [__pos,__pos + __n1) 01886 * from this string. In place, the characters of @a __s are 01887 * inserted. If @a __pos is beyond end of string, out_of_range 01888 * is thrown. If the length of result exceeds max_size(), 01889 * length_error is thrown. The value of the string doesn't 01890 * change if an error is thrown. 01891 */ 01892 basic_string& 01893 replace(size_type __pos, size_type __n1, const _CharT* __s) 01894 { 01895 __glibcxx_requires_string(__s); 01896 return this->replace(__pos, __n1, __s, traits_type::length(__s)); 01897 } 01898 01899 /** 01900 * @brief Replace characters with multiple characters. 01901 * @param __pos Index of first character to replace. 01902 * @param __n1 Number of characters to be replaced. 01903 * @param __n2 Number of characters to insert. 01904 * @param __c Character to insert. 01905 * @return Reference to this string. 01906 * @throw std::out_of_range If @a __pos > size(). 01907 * @throw std::length_error If new length exceeds @c max_size(). 01908 * 01909 * Removes the characters in the range [pos,pos + n1) from this 01910 * string. In place, @a __n2 copies of @a __c are inserted. 01911 * If @a __pos is beyond end of string, out_of_range is thrown. 01912 * If the length of result exceeds max_size(), length_error is 01913 * thrown. The value of the string doesn't change if an error 01914 * is thrown. 01915 */ 01916 basic_string& 01917 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) 01918 { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), 01919 _M_limit(__pos, __n1), __n2, __c); } 01920 01921 /** 01922 * @brief Replace range of characters with string. 01923 * @param __i1 Iterator referencing start of range to replace. 01924 * @param __i2 Iterator referencing end of range to replace. 01925 * @param __str String value to insert. 01926 * @return Reference to this string. 01927 * @throw std::length_error If new length exceeds @c max_size(). 01928 * 01929 * Removes the characters in the range [__i1,__i2). In place, 01930 * the value of @a __str is inserted. If the length of result 01931 * exceeds max_size(), length_error is thrown. The value of 01932 * the string doesn't change if an error is thrown. 01933 */ 01934 basic_string& 01935 replace(__const_iterator __i1, __const_iterator __i2, 01936 const basic_string& __str) 01937 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } 01938 01939 /** 01940 * @brief Replace range of characters with C substring. 01941 * @param __i1 Iterator referencing start of range to replace. 01942 * @param __i2 Iterator referencing end of range to replace. 01943 * @param __s C string value to insert. 01944 * @param __n Number of characters from s to insert. 01945 * @return Reference to this string. 01946 * @throw std::length_error If new length exceeds @c max_size(). 01947 * 01948 * Removes the characters in the range [__i1,__i2). In place, 01949 * the first @a __n characters of @a __s are inserted. If the 01950 * length of result exceeds max_size(), length_error is thrown. 01951 * The value of the string doesn't change if an error is 01952 * thrown. 01953 */ 01954 basic_string& 01955 replace(__const_iterator __i1, __const_iterator __i2, 01956 const _CharT* __s, size_type __n) 01957 { 01958 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 01959 && __i2 <= end()); 01960 return this->replace(__i1 - begin(), __i2 - __i1, __s, __n); 01961 } 01962 01963 /** 01964 * @brief Replace range of characters with C string. 01965 * @param __i1 Iterator referencing start of range to replace. 01966 * @param __i2 Iterator referencing end of range to replace. 01967 * @param __s C string value to insert. 01968 * @return Reference to this string. 01969 * @throw std::length_error If new length exceeds @c max_size(). 01970 * 01971 * Removes the characters in the range [__i1,__i2). In place, 01972 * the characters of @a __s are inserted. If the length of 01973 * result exceeds max_size(), length_error is thrown. The 01974 * value of the string doesn't change if an error is thrown. 01975 */ 01976 basic_string& 01977 replace(__const_iterator __i1, __const_iterator __i2, const _CharT* __s) 01978 { 01979 __glibcxx_requires_string(__s); 01980 return this->replace(__i1, __i2, __s, traits_type::length(__s)); 01981 } 01982 01983 /** 01984 * @brief Replace range of characters with multiple characters 01985 * @param __i1 Iterator referencing start of range to replace. 01986 * @param __i2 Iterator referencing end of range to replace. 01987 * @param __n Number of characters to insert. 01988 * @param __c Character to insert. 01989 * @return Reference to this string. 01990 * @throw std::length_error If new length exceeds @c max_size(). 01991 * 01992 * Removes the characters in the range [__i1,__i2). In place, 01993 * @a __n copies of @a __c are inserted. If the length of 01994 * result exceeds max_size(), length_error is thrown. The 01995 * value of the string doesn't change if an error is thrown. 01996 */ 01997 basic_string& 01998 replace(__const_iterator __i1, __const_iterator __i2, size_type __n, 01999 _CharT __c) 02000 { 02001 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 02002 && __i2 <= end()); 02003 return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __c); 02004 } 02005 02006 /** 02007 * @brief Replace range of characters with range. 02008 * @param __i1 Iterator referencing start of range to replace. 02009 * @param __i2 Iterator referencing end of range to replace. 02010 * @param __k1 Iterator referencing start of range to insert. 02011 * @param __k2 Iterator referencing end of range to insert. 02012 * @return Reference to this string. 02013 * @throw std::length_error If new length exceeds @c max_size(). 02014 * 02015 * Removes the characters in the range [__i1,__i2). In place, 02016 * characters in the range [__k1,__k2) are inserted. If the 02017 * length of result exceeds max_size(), length_error is thrown. 02018 * The value of the string doesn't change if an error is 02019 * thrown. 02020 */ 02021 #if __cplusplus >= 201103L 02022 template<class _InputIterator, 02023 typename = std::_RequireInputIter<_InputIterator>> 02024 basic_string& 02025 replace(const_iterator __i1, const_iterator __i2, 02026 _InputIterator __k1, _InputIterator __k2) 02027 { 02028 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 02029 && __i2 <= end()); 02030 __glibcxx_requires_valid_range(__k1, __k2); 02031 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, 02032 std::__false_type()); 02033 } 02034 #else 02035 template<class _InputIterator> 02036 #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST 02037 typename __enable_if_not_native_iterator<_InputIterator>::__type 02038 #else 02039 basic_string& 02040 #endif 02041 replace(iterator __i1, iterator __i2, 02042 _InputIterator __k1, _InputIterator __k2) 02043 { 02044 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 02045 && __i2 <= end()); 02046 __glibcxx_requires_valid_range(__k1, __k2); 02047 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 02048 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); 02049 } 02050 #endif 02051 02052 // Specializations for the common case of pointer and iterator: 02053 // useful to avoid the overhead of temporary buffering in _M_replace. 02054 basic_string& 02055 replace(__const_iterator __i1, __const_iterator __i2, 02056 _CharT* __k1, _CharT* __k2) 02057 { 02058 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 02059 && __i2 <= end()); 02060 __glibcxx_requires_valid_range(__k1, __k2); 02061 return this->replace(__i1 - begin(), __i2 - __i1, 02062 __k1, __k2 - __k1); 02063 } 02064 02065 basic_string& 02066 replace(__const_iterator __i1, __const_iterator __i2, 02067 const _CharT* __k1, const _CharT* __k2) 02068 { 02069 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 02070 && __i2 <= end()); 02071 __glibcxx_requires_valid_range(__k1, __k2); 02072 return this->replace(__i1 - begin(), __i2 - __i1, 02073 __k1, __k2 - __k1); 02074 } 02075 02076 basic_string& 02077 replace(__const_iterator __i1, __const_iterator __i2, 02078 iterator __k1, iterator __k2) 02079 { 02080 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 02081 && __i2 <= end()); 02082 __glibcxx_requires_valid_range(__k1, __k2); 02083 return this->replace(__i1 - begin(), __i2 - __i1, 02084 __k1.base(), __k2 - __k1); 02085 } 02086 02087 basic_string& 02088 replace(__const_iterator __i1, __const_iterator __i2, 02089 const_iterator __k1, const_iterator __k2) 02090 { 02091 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 02092 && __i2 <= end()); 02093 __glibcxx_requires_valid_range(__k1, __k2); 02094 return this->replace(__i1 - begin(), __i2 - __i1, 02095 __k1.base(), __k2 - __k1); 02096 } 02097 02098 #if __cplusplus >= 201103L 02099 /** 02100 * @brief Replace range of characters with initializer_list. 02101 * @param __i1 Iterator referencing start of range to replace. 02102 * @param __i2 Iterator referencing end of range to replace. 02103 * @param __l The initializer_list of characters to insert. 02104 * @return Reference to this string. 02105 * @throw std::length_error If new length exceeds @c max_size(). 02106 * 02107 * Removes the characters in the range [__i1,__i2). In place, 02108 * characters in the range [__k1,__k2) are inserted. If the 02109 * length of result exceeds max_size(), length_error is thrown. 02110 * The value of the string doesn't change if an error is 02111 * thrown. 02112 */ 02113 basic_string& replace(const_iterator __i1, const_iterator __i2, 02114 initializer_list<_CharT> __l) 02115 { return this->replace(__i1, __i2, __l.begin(), __l.size()); } 02116 #endif // C++11 02117 02118 #if __cplusplus > 201402L 02119 /** 02120 * @brief Replace range of characters with string_view. 02121 * @param __pos The position to replace at. 02122 * @param __n The number of characters to replace. 02123 * @param __sv The string_view to insert. 02124 * @return Reference to this string. 02125 */ 02126 basic_string& 02127 replace(size_type __pos, size_type __n, __sv_type __sv) 02128 { return this->replace(__pos, __n, __sv.data(), __sv.size()); } 02129 02130 /** 02131 * @brief Replace range of characters with string_view. 02132 * @param __pos1 The position to replace at. 02133 * @param __n1 The number of characters to replace. 02134 * @param __sv The string_view to insert from. 02135 * @param __pos2 The position in the string_view to insert from. 02136 * @param __n2 The number of characters to insert. 02137 * @return Reference to this string. 02138 */ 02139 template <typename _Tp> 02140 _If_sv<_Tp, basic_string&> 02141 replace(size_type __pos1, size_type __n1, const _Tp& __svt, 02142 size_type __pos2, size_type __n2 = npos) 02143 { 02144 __sv_type __sv = __svt; 02145 return this->replace(__pos1, __n1, __sv.data() 02146 + __sv._M_check(__pos2, "basic_string::replace"), 02147 __sv._M_limit(__pos2, __n2)); 02148 } 02149 02150 /** 02151 * @brief Replace range of characters with string_view. 02152 * @param __i1 An iterator referencing the start position 02153 to replace at. 02154 * @param __i2 An iterator referencing the end position 02155 for the replace. 02156 * @param __sv The string_view to insert from. 02157 * @return Reference to this string. 02158 */ 02159 basic_string& 02160 replace(const_iterator __i1, const_iterator __i2, __sv_type __sv) 02161 { return this->replace(__i1 - begin(), __i2 - __i1, __sv); } 02162 #endif // C++17 02163 02164 private: 02165 template<class _Integer> 02166 basic_string& 02167 _M_replace_dispatch(const_iterator __i1, const_iterator __i2, 02168 _Integer __n, _Integer __val, __true_type) 02169 { return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __val); } 02170 02171 template<class _InputIterator> 02172 basic_string& 02173 _M_replace_dispatch(const_iterator __i1, const_iterator __i2, 02174 _InputIterator __k1, _InputIterator __k2, 02175 __false_type); 02176 02177 basic_string& 02178 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, 02179 _CharT __c); 02180 02181 basic_string& 02182 _M_replace(size_type __pos, size_type __len1, const _CharT* __s, 02183 const size_type __len2); 02184 02185 basic_string& 02186 _M_append(const _CharT* __s, size_type __n); 02187 02188 public: 02189 02190 /** 02191 * @brief Copy substring into C string. 02192 * @param __s C string to copy value into. 02193 * @param __n Number of characters to copy. 02194 * @param __pos Index of first character to copy. 02195 * @return Number of characters actually copied 02196 * @throw std::out_of_range If __pos > size(). 02197 * 02198 * Copies up to @a __n characters starting at @a __pos into the 02199 * C string @a __s. If @a __pos is %greater than size(), 02200 * out_of_range is thrown. 02201 */ 02202 size_type 02203 copy(_CharT* __s, size_type __n, size_type __pos = 0) const; 02204 02205 /** 02206 * @brief Swap contents with another string. 02207 * @param __s String to swap with. 02208 * 02209 * Exchanges the contents of this string with that of @a __s in constant 02210 * time. 02211 */ 02212 void 02213 swap(basic_string& __s) _GLIBCXX_NOEXCEPT; 02214 02215 // String operations: 02216 /** 02217 * @brief Return const pointer to null-terminated contents. 02218 * 02219 * This is a handle to internal data. Do not modify or dire things may 02220 * happen. 02221 */ 02222 const _CharT* 02223 c_str() const _GLIBCXX_NOEXCEPT 02224 { return _M_data(); } 02225 02226 /** 02227 * @brief Return const pointer to contents. 02228 * 02229 * This is a pointer to internal data. It is undefined to modify 02230 * the contents through the returned pointer. To get a pointer that 02231 * allows modifying the contents use @c &str[0] instead, 02232 * (or in C++17 the non-const @c str.data() overload). 02233 */ 02234 const _CharT* 02235 data() const _GLIBCXX_NOEXCEPT 02236 { return _M_data(); } 02237 02238 #if __cplusplus > 201402L 02239 /** 02240 * @brief Return non-const pointer to contents. 02241 * 02242 * This is a pointer to the character sequence held by the string. 02243 * Modifying the characters in the sequence is allowed. 02244 */ 02245 _CharT* 02246 data() noexcept 02247 { return _M_data(); } 02248 #endif 02249 02250 /** 02251 * @brief Return copy of allocator used to construct this string. 02252 */ 02253 allocator_type 02254 get_allocator() const _GLIBCXX_NOEXCEPT 02255 { return _M_get_allocator(); } 02256 02257 /** 02258 * @brief Find position of a C substring. 02259 * @param __s C string to locate. 02260 * @param __pos Index of character to search from. 02261 * @param __n Number of characters from @a s to search for. 02262 * @return Index of start of first occurrence. 02263 * 02264 * Starting from @a __pos, searches forward for the first @a 02265 * __n characters in @a __s within this string. If found, 02266 * returns the index where it begins. If not found, returns 02267 * npos. 02268 */ 02269 size_type 02270 find(const _CharT* __s, size_type __pos, size_type __n) const 02271 _GLIBCXX_NOEXCEPT; 02272 02273 /** 02274 * @brief Find position of a string. 02275 * @param __str String to locate. 02276 * @param __pos Index of character to search from (default 0). 02277 * @return Index of start of first occurrence. 02278 * 02279 * Starting from @a __pos, searches forward for value of @a __str within 02280 * this string. If found, returns the index where it begins. If not 02281 * found, returns npos. 02282 */ 02283 size_type 02284 find(const basic_string& __str, size_type __pos = 0) const 02285 _GLIBCXX_NOEXCEPT 02286 { return this->find(__str.data(), __pos, __str.size()); } 02287 02288 #if __cplusplus > 201402L 02289 /** 02290 * @brief Find position of a string_view. 02291 * @param __sv The string_view to locate. 02292 * @param __pos Index of character to search from (default 0). 02293 * @return Index of start of first occurrence. 02294 */ 02295 size_type 02296 find(__sv_type __sv, size_type __pos = 0) const noexcept 02297 { return this->find(__sv.data(), __pos, __sv.size()); } 02298 #endif // C++17 02299 02300 /** 02301 * @brief Find position of a C string. 02302 * @param __s C string to locate. 02303 * @param __pos Index of character to search from (default 0). 02304 * @return Index of start of first occurrence. 02305 * 02306 * Starting from @a __pos, searches forward for the value of @a 02307 * __s within this string. If found, returns the index where 02308 * it begins. If not found, returns npos. 02309 */ 02310 size_type 02311 find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 02312 { 02313 __glibcxx_requires_string(__s); 02314 return this->find(__s, __pos, traits_type::length(__s)); 02315 } 02316 02317 /** 02318 * @brief Find position of a character. 02319 * @param __c Character to locate. 02320 * @param __pos Index of character to search from (default 0). 02321 * @return Index of first occurrence. 02322 * 02323 * Starting from @a __pos, searches forward for @a __c within 02324 * this string. If found, returns the index where it was 02325 * found. If not found, returns npos. 02326 */ 02327 size_type 02328 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; 02329 02330 /** 02331 * @brief Find last position of a string. 02332 * @param __str String to locate. 02333 * @param __pos Index of character to search back from (default end). 02334 * @return Index of start of last occurrence. 02335 * 02336 * Starting from @a __pos, searches backward for value of @a 02337 * __str within this string. If found, returns the index where 02338 * it begins. If not found, returns npos. 02339 */ 02340 size_type 02341 rfind(const basic_string& __str, size_type __pos = npos) const 02342 _GLIBCXX_NOEXCEPT 02343 { return this->rfind(__str.data(), __pos, __str.size()); } 02344 02345 #if __cplusplus > 201402L 02346 /** 02347 * @brief Find last position of a string_view. 02348 * @param __sv The string_view to locate. 02349 * @param __pos Index of character to search back from (default end). 02350 * @return Index of start of last occurrence. 02351 */ 02352 size_type 02353 rfind(__sv_type __sv, size_type __pos = npos) const noexcept 02354 { return this->rfind(__sv.data(), __pos, __sv.size()); } 02355 #endif // C++17 02356 02357 /** 02358 * @brief Find last position of a C substring. 02359 * @param __s C string to locate. 02360 * @param __pos Index of character to search back from. 02361 * @param __n Number of characters from s to search for. 02362 * @return Index of start of last occurrence. 02363 * 02364 * Starting from @a __pos, searches backward for the first @a 02365 * __n characters in @a __s within this string. If found, 02366 * returns the index where it begins. If not found, returns 02367 * npos. 02368 */ 02369 size_type 02370 rfind(const _CharT* __s, size_type __pos, size_type __n) const 02371 _GLIBCXX_NOEXCEPT; 02372 02373 /** 02374 * @brief Find last position of a C string. 02375 * @param __s C string to locate. 02376 * @param __pos Index of character to start search at (default end). 02377 * @return Index of start of last occurrence. 02378 * 02379 * Starting from @a __pos, searches backward for the value of 02380 * @a __s within this string. If found, returns the index 02381 * where it begins. If not found, returns npos. 02382 */ 02383 size_type 02384 rfind(const _CharT* __s, size_type __pos = npos) const 02385 { 02386 __glibcxx_requires_string(__s); 02387 return this->rfind(__s, __pos, traits_type::length(__s)); 02388 } 02389 02390 /** 02391 * @brief Find last position of a character. 02392 * @param __c Character to locate. 02393 * @param __pos Index of character to search back from (default end). 02394 * @return Index of last occurrence. 02395 * 02396 * Starting from @a __pos, searches backward for @a __c within 02397 * this string. If found, returns the index where it was 02398 * found. If not found, returns npos. 02399 */ 02400 size_type 02401 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; 02402 02403 /** 02404 * @brief Find position of a character of string. 02405 * @param __str String containing characters to locate. 02406 * @param __pos Index of character to search from (default 0). 02407 * @return Index of first occurrence. 02408 * 02409 * Starting from @a __pos, searches forward for one of the 02410 * characters of @a __str within this string. If found, 02411 * returns the index where it was found. If not found, returns 02412 * npos. 02413 */ 02414 size_type 02415 find_first_of(const basic_string& __str, size_type __pos = 0) const 02416 _GLIBCXX_NOEXCEPT 02417 { return this->find_first_of(__str.data(), __pos, __str.size()); } 02418 02419 #if __cplusplus > 201402L 02420 /** 02421 * @brief Find position of a character of a string_view. 02422 * @param __sv A string_view containing characters to locate. 02423 * @param __pos Index of character to search from (default 0). 02424 * @return Index of first occurrence. 02425 */ 02426 size_type 02427 find_first_of(__sv_type __sv, size_type __pos = 0) const noexcept 02428 { return this->find_first_of(__sv.data(), __pos, __sv.size()); } 02429 #endif // C++17 02430 02431 /** 02432 * @brief Find position of a character of C substring. 02433 * @param __s String containing characters to locate. 02434 * @param __pos Index of character to search from. 02435 * @param __n Number of characters from s to search for. 02436 * @return Index of first occurrence. 02437 * 02438 * Starting from @a __pos, searches forward for one of the 02439 * first @a __n characters of @a __s within this string. If 02440 * found, returns the index where it was found. If not found, 02441 * returns npos. 02442 */ 02443 size_type 02444 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const 02445 _GLIBCXX_NOEXCEPT; 02446 02447 /** 02448 * @brief Find position of a character of C string. 02449 * @param __s String containing characters to locate. 02450 * @param __pos Index of character to search from (default 0). 02451 * @return Index of first occurrence. 02452 * 02453 * Starting from @a __pos, searches forward for one of the 02454 * characters of @a __s within this string. If found, returns 02455 * the index where it was found. If not found, returns npos. 02456 */ 02457 size_type 02458 find_first_of(const _CharT* __s, size_type __pos = 0) const 02459 _GLIBCXX_NOEXCEPT 02460 { 02461 __glibcxx_requires_string(__s); 02462 return this->find_first_of(__s, __pos, traits_type::length(__s)); 02463 } 02464 02465 /** 02466 * @brief Find position of a character. 02467 * @param __c Character to locate. 02468 * @param __pos Index of character to search from (default 0). 02469 * @return Index of first occurrence. 02470 * 02471 * Starting from @a __pos, searches forward for the character 02472 * @a __c within this string. If found, returns the index 02473 * where it was found. If not found, returns npos. 02474 * 02475 * Note: equivalent to find(__c, __pos). 02476 */ 02477 size_type 02478 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 02479 { return this->find(__c, __pos); } 02480 02481 /** 02482 * @brief Find last position of a character of string. 02483 * @param __str String containing characters to locate. 02484 * @param __pos Index of character to search back from (default end). 02485 * @return Index of last occurrence. 02486 * 02487 * Starting from @a __pos, searches backward for one of the 02488 * characters of @a __str within this string. If found, 02489 * returns the index where it was found. If not found, returns 02490 * npos. 02491 */ 02492 size_type 02493 find_last_of(const basic_string& __str, size_type __pos = npos) const 02494 _GLIBCXX_NOEXCEPT 02495 { return this->find_last_of(__str.data(), __pos, __str.size()); } 02496 02497 #if __cplusplus > 201402L 02498 /** 02499 * @brief Find last position of a character of string. 02500 * @param __sv A string_view containing characters to locate. 02501 * @param __pos Index of character to search back from (default end). 02502 * @return Index of last occurrence. 02503 */ 02504 size_type 02505 find_last_of(__sv_type __sv, size_type __pos = npos) const noexcept 02506 { return this->find_last_of(__sv.data(), __pos, __sv.size()); } 02507 #endif // C++17 02508 02509 /** 02510 * @brief Find last position of a character of C substring. 02511 * @param __s C string containing characters to locate. 02512 * @param __pos Index of character to search back from. 02513 * @param __n Number of characters from s to search for. 02514 * @return Index of last occurrence. 02515 * 02516 * Starting from @a __pos, searches backward for one of the 02517 * first @a __n characters of @a __s within this string. If 02518 * found, returns the index where it was found. If not found, 02519 * returns npos. 02520 */ 02521 size_type 02522 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const 02523 _GLIBCXX_NOEXCEPT; 02524 02525 /** 02526 * @brief Find last position of a character of C string. 02527 * @param __s C string containing characters to locate. 02528 * @param __pos Index of character to search back from (default end). 02529 * @return Index of last occurrence. 02530 * 02531 * Starting from @a __pos, searches backward for one of the 02532 * characters of @a __s within this string. If found, returns 02533 * the index where it was found. If not found, returns npos. 02534 */ 02535 size_type 02536 find_last_of(const _CharT* __s, size_type __pos = npos) const 02537 _GLIBCXX_NOEXCEPT 02538 { 02539 __glibcxx_requires_string(__s); 02540 return this->find_last_of(__s, __pos, traits_type::length(__s)); 02541 } 02542 02543 /** 02544 * @brief Find last position of a character. 02545 * @param __c Character to locate. 02546 * @param __pos Index of character to search back from (default end). 02547 * @return Index of last occurrence. 02548 * 02549 * Starting from @a __pos, searches backward for @a __c within 02550 * this string. If found, returns the index where it was 02551 * found. If not found, returns npos. 02552 * 02553 * Note: equivalent to rfind(__c, __pos). 02554 */ 02555 size_type 02556 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT 02557 { return this->rfind(__c, __pos); } 02558 02559 /** 02560 * @brief Find position of a character not in string. 02561 * @param __str String containing characters to avoid. 02562 * @param __pos Index of character to search from (default 0). 02563 * @return Index of first occurrence. 02564 * 02565 * Starting from @a __pos, searches forward for a character not contained 02566 * in @a __str within this string. If found, returns the index where it 02567 * was found. If not found, returns npos. 02568 */ 02569 size_type 02570 find_first_not_of(const basic_string& __str, size_type __pos = 0) const 02571 _GLIBCXX_NOEXCEPT 02572 { return this->find_first_not_of(__str.data(), __pos, __str.size()); } 02573 02574 #if __cplusplus > 201402L 02575 /** 02576 * @brief Find position of a character not in a string_view. 02577 * @param __sv A string_view containing characters to avoid. 02578 * @param __pos Index of character to search from (default 0). 02579 * @return Index of first occurrence. 02580 */ 02581 size_type 02582 find_first_not_of(__sv_type __sv, size_type __pos = 0) const noexcept 02583 { return this->find_first_not_of(__sv.data(), __pos, __sv.size()); } 02584 #endif // C++17 02585 02586 /** 02587 * @brief Find position of a character not in C substring. 02588 * @param __s C string containing characters to avoid. 02589 * @param __pos Index of character to search from. 02590 * @param __n Number of characters from __s to consider. 02591 * @return Index of first occurrence. 02592 * 02593 * Starting from @a __pos, searches forward for a character not 02594 * contained in the first @a __n characters of @a __s within 02595 * this string. If found, returns the index where it was 02596 * found. If not found, returns npos. 02597 */ 02598 size_type 02599 find_first_not_of(const _CharT* __s, size_type __pos, 02600 size_type __n) const _GLIBCXX_NOEXCEPT; 02601 02602 /** 02603 * @brief Find position of a character not in C string. 02604 * @param __s C string containing characters to avoid. 02605 * @param __pos Index of character to search from (default 0). 02606 * @return Index of first occurrence. 02607 * 02608 * Starting from @a __pos, searches forward for a character not 02609 * contained in @a __s within this string. If found, returns 02610 * the index where it was found. If not found, returns npos. 02611 */ 02612 size_type 02613 find_first_not_of(const _CharT* __s, size_type __pos = 0) const 02614 _GLIBCXX_NOEXCEPT 02615 { 02616 __glibcxx_requires_string(__s); 02617 return this->find_first_not_of(__s, __pos, traits_type::length(__s)); 02618 } 02619 02620 /** 02621 * @brief Find position of a different character. 02622 * @param __c Character to avoid. 02623 * @param __pos Index of character to search from (default 0). 02624 * @return Index of first occurrence. 02625 * 02626 * Starting from @a __pos, searches forward for a character 02627 * other than @a __c within this string. If found, returns the 02628 * index where it was found. If not found, returns npos. 02629 */ 02630 size_type 02631 find_first_not_of(_CharT __c, size_type __pos = 0) const 02632 _GLIBCXX_NOEXCEPT; 02633 02634 /** 02635 * @brief Find last position of a character not in string. 02636 * @param __str String containing characters to avoid. 02637 * @param __pos Index of character to search back from (default end). 02638 * @return Index of last occurrence. 02639 * 02640 * Starting from @a __pos, searches backward for a character 02641 * not contained in @a __str within this string. If found, 02642 * returns the index where it was found. If not found, returns 02643 * npos. 02644 */ 02645 size_type 02646 find_last_not_of(const basic_string& __str, size_type __pos = npos) const 02647 _GLIBCXX_NOEXCEPT 02648 { return this->find_last_not_of(__str.data(), __pos, __str.size()); } 02649 02650 #if __cplusplus > 201402L 02651 /** 02652 * @brief Find last position of a character not in a string_view. 02653 * @param __sv A string_view containing characters to avoid. 02654 * @param __pos Index of character to search back from (default end). 02655 * @return Index of last occurrence. 02656 */ 02657 size_type 02658 find_last_not_of(__sv_type __sv, size_type __pos = npos) const noexcept 02659 { return this->find_last_not_of(__sv.data(), __pos, __sv.size()); } 02660 #endif // C++17 02661 02662 /** 02663 * @brief Find last position of a character not in C substring. 02664 * @param __s C string containing characters to avoid. 02665 * @param __pos Index of character to search back from. 02666 * @param __n Number of characters from s to consider. 02667 * @return Index of last occurrence. 02668 * 02669 * Starting from @a __pos, searches backward for a character not 02670 * contained in the first @a __n characters of @a __s within this string. 02671 * If found, returns the index where it was found. If not found, 02672 * returns npos. 02673 */ 02674 size_type 02675 find_last_not_of(const _CharT* __s, size_type __pos, 02676 size_type __n) const _GLIBCXX_NOEXCEPT; 02677 /** 02678 * @brief Find last position of a character not in C string. 02679 * @param __s C string containing characters to avoid. 02680 * @param __pos Index of character to search back from (default end). 02681 * @return Index of last occurrence. 02682 * 02683 * Starting from @a __pos, searches backward for a character 02684 * not contained in @a __s within this string. If found, 02685 * returns the index where it was found. If not found, returns 02686 * npos. 02687 */ 02688 size_type 02689 find_last_not_of(const _CharT* __s, size_type __pos = npos) const 02690 _GLIBCXX_NOEXCEPT 02691 { 02692 __glibcxx_requires_string(__s); 02693 return this->find_last_not_of(__s, __pos, traits_type::length(__s)); 02694 } 02695 02696 /** 02697 * @brief Find last position of a different character. 02698 * @param __c Character to avoid. 02699 * @param __pos Index of character to search back from (default end). 02700 * @return Index of last occurrence. 02701 * 02702 * Starting from @a __pos, searches backward for a character other than 02703 * @a __c within this string. If found, returns the index where it was 02704 * found. If not found, returns npos. 02705 */ 02706 size_type 02707 find_last_not_of(_CharT __c, size_type __pos = npos) const 02708 _GLIBCXX_NOEXCEPT; 02709 02710 /** 02711 * @brief Get a substring. 02712 * @param __pos Index of first character (default 0). 02713 * @param __n Number of characters in substring (default remainder). 02714 * @return The new string. 02715 * @throw std::out_of_range If __pos > size(). 02716 * 02717 * Construct and return a new string using the @a __n 02718 * characters starting at @a __pos. If the string is too 02719 * short, use the remainder of the characters. If @a __pos is 02720 * beyond the end of the string, out_of_range is thrown. 02721 */ 02722 basic_string 02723 substr(size_type __pos = 0, size_type __n = npos) const 02724 { return basic_string(*this, 02725 _M_check(__pos, "basic_string::substr"), __n); } 02726 02727 /** 02728 * @brief Compare to a string. 02729 * @param __str String to compare against. 02730 * @return Integer < 0, 0, or > 0. 02731 * 02732 * Returns an integer < 0 if this string is ordered before @a 02733 * __str, 0 if their values are equivalent, or > 0 if this 02734 * string is ordered after @a __str. Determines the effective 02735 * length rlen of the strings to compare as the smallest of 02736 * size() and str.size(). The function then compares the two 02737 * strings by calling traits::compare(data(), str.data(),rlen). 02738 * If the result of the comparison is nonzero returns it, 02739 * otherwise the shorter one is ordered first. 02740 */ 02741 int 02742 compare(const basic_string& __str) const 02743 { 02744 const size_type __size = this->size(); 02745 const size_type __osize = __str.size(); 02746 const size_type __len = std::min(__size, __osize); 02747 02748 int __r = traits_type::compare(_M_data(), __str.data(), __len); 02749 if (!__r) 02750 __r = _S_compare(__size, __osize); 02751 return __r; 02752 } 02753 02754 #if __cplusplus > 201402L 02755 /** 02756 * @brief Compare to a string_view. 02757 * @param __sv A string_view to compare against. 02758 * @return Integer < 0, 0, or > 0. 02759 */ 02760 int 02761 compare(__sv_type __sv) const 02762 { 02763 const size_type __size = this->size(); 02764 const size_type __osize = __sv.size(); 02765 const size_type __len = std::min(__size, __osize); 02766 02767 int __r = traits_type::compare(_M_data(), __sv.data(), __len); 02768 if (!__r) 02769 __r = _S_compare(__size, __osize); 02770 return __r; 02771 } 02772 02773 /** 02774 * @brief Compare to a string_view. 02775 * @param __pos A position in the string to start comparing from. 02776 * @param __n The number of characters to compare. 02777 * @param __sv A string_view to compare against. 02778 * @return Integer < 0, 0, or > 0. 02779 */ 02780 int 02781 compare(size_type __pos, size_type __n, __sv_type __sv) const 02782 { return __sv_type(*this).substr(__pos, __n).compare(__sv); } 02783 02784 /** 02785 * @brief Compare to a string_view. 02786 * @param __pos1 A position in the string to start comparing from. 02787 * @param __n1 The number of characters to compare. 02788 * @param __sv A string_view to compare against. 02789 * @param __pos2 A position in the string_view to start comparing from. 02790 * @param __n2 The number of characters to compare. 02791 * @return Integer < 0, 0, or > 0. 02792 */ 02793 template <typename _Tp> 02794 _If_sv<_Tp, int> 02795 compare(size_type __pos1, size_type __n1, const _Tp& __svt, 02796 size_type __pos2, size_type __n2 = npos) const 02797 { 02798 __sv_type __sv = __svt; 02799 return __sv_type(*this) 02800 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); 02801 } 02802 #endif // C++17 02803 02804 /** 02805 * @brief Compare substring to a string. 02806 * @param __pos Index of first character of substring. 02807 * @param __n Number of characters in substring. 02808 * @param __str String to compare against. 02809 * @return Integer < 0, 0, or > 0. 02810 * 02811 * Form the substring of this string from the @a __n characters 02812 * starting at @a __pos. Returns an integer < 0 if the 02813 * substring is ordered before @a __str, 0 if their values are 02814 * equivalent, or > 0 if the substring is ordered after @a 02815 * __str. Determines the effective length rlen of the strings 02816 * to compare as the smallest of the length of the substring 02817 * and @a __str.size(). The function then compares the two 02818 * strings by calling 02819 * traits::compare(substring.data(),str.data(),rlen). If the 02820 * result of the comparison is nonzero returns it, otherwise 02821 * the shorter one is ordered first. 02822 */ 02823 int 02824 compare(size_type __pos, size_type __n, const basic_string& __str) const; 02825 02826 /** 02827 * @brief Compare substring to a substring. 02828 * @param __pos1 Index of first character of substring. 02829 * @param __n1 Number of characters in substring. 02830 * @param __str String to compare against. 02831 * @param __pos2 Index of first character of substring of str. 02832 * @param __n2 Number of characters in substring of str. 02833 * @return Integer < 0, 0, or > 0. 02834 * 02835 * Form the substring of this string from the @a __n1 02836 * characters starting at @a __pos1. Form the substring of @a 02837 * __str from the @a __n2 characters starting at @a __pos2. 02838 * Returns an integer < 0 if this substring is ordered before 02839 * the substring of @a __str, 0 if their values are equivalent, 02840 * or > 0 if this substring is ordered after the substring of 02841 * @a __str. Determines the effective length rlen of the 02842 * strings to compare as the smallest of the lengths of the 02843 * substrings. The function then compares the two strings by 02844 * calling 02845 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). 02846 * If the result of the comparison is nonzero returns it, 02847 * otherwise the shorter one is ordered first. 02848 */ 02849 int 02850 compare(size_type __pos1, size_type __n1, const basic_string& __str, 02851 size_type __pos2, size_type __n2) const; 02852 02853 /** 02854 * @brief Compare to a C string. 02855 * @param __s C string to compare against. 02856 * @return Integer < 0, 0, or > 0. 02857 * 02858 * Returns an integer < 0 if this string is ordered before @a __s, 0 if 02859 * their values are equivalent, or > 0 if this string is ordered after 02860 * @a __s. Determines the effective length rlen of the strings to 02861 * compare as the smallest of size() and the length of a string 02862 * constructed from @a __s. The function then compares the two strings 02863 * by calling traits::compare(data(),s,rlen). If the result of the 02864 * comparison is nonzero returns it, otherwise the shorter one is 02865 * ordered first. 02866 */ 02867 int 02868 compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT; 02869 02870 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02871 // 5 String::compare specification questionable 02872 /** 02873 * @brief Compare substring to a C string. 02874 * @param __pos Index of first character of substring. 02875 * @param __n1 Number of characters in substring. 02876 * @param __s C string to compare against. 02877 * @return Integer < 0, 0, or > 0. 02878 * 02879 * Form the substring of this string from the @a __n1 02880 * characters starting at @a pos. Returns an integer < 0 if 02881 * the substring is ordered before @a __s, 0 if their values 02882 * are equivalent, or > 0 if the substring is ordered after @a 02883 * __s. Determines the effective length rlen of the strings to 02884 * compare as the smallest of the length of the substring and 02885 * the length of a string constructed from @a __s. The 02886 * function then compares the two string by calling 02887 * traits::compare(substring.data(),__s,rlen). If the result of 02888 * the comparison is nonzero returns it, otherwise the shorter 02889 * one is ordered first. 02890 */ 02891 int 02892 compare(size_type __pos, size_type __n1, const _CharT* __s) const; 02893 02894 /** 02895 * @brief Compare substring against a character %array. 02896 * @param __pos Index of first character of substring. 02897 * @param __n1 Number of characters in substring. 02898 * @param __s character %array to compare against. 02899 * @param __n2 Number of characters of s. 02900 * @return Integer < 0, 0, or > 0. 02901 * 02902 * Form the substring of this string from the @a __n1 02903 * characters starting at @a __pos. Form a string from the 02904 * first @a __n2 characters of @a __s. Returns an integer < 0 02905 * if this substring is ordered before the string from @a __s, 02906 * 0 if their values are equivalent, or > 0 if this substring 02907 * is ordered after the string from @a __s. Determines the 02908 * effective length rlen of the strings to compare as the 02909 * smallest of the length of the substring and @a __n2. The 02910 * function then compares the two strings by calling 02911 * traits::compare(substring.data(),s,rlen). If the result of 02912 * the comparison is nonzero returns it, otherwise the shorter 02913 * one is ordered first. 02914 * 02915 * NB: s must have at least n2 characters, '\\0' has 02916 * no special meaning. 02917 */ 02918 int 02919 compare(size_type __pos, size_type __n1, const _CharT* __s, 02920 size_type __n2) const; 02921 }; 02922 _GLIBCXX_END_NAMESPACE_CXX11 02923 #else // !_GLIBCXX_USE_CXX11_ABI 02924 // Reference-counted COW string implentation 02925 02926 /** 02927 * @class basic_string basic_string.h <string> 02928 * @brief Managing sequences of characters and character-like objects. 02929 * 02930 * @ingroup strings 02931 * @ingroup sequences 02932 * 02933 * @tparam _CharT Type of character 02934 * @tparam _Traits Traits for character type, defaults to 02935 * char_traits<_CharT>. 02936 * @tparam _Alloc Allocator type, defaults to allocator<_CharT>. 02937 * 02938 * Meets the requirements of a <a href="tables.html#65">container</a>, a 02939 * <a href="tables.html#66">reversible container</a>, and a 02940 * <a href="tables.html#67">sequence</a>. Of the 02941 * <a href="tables.html#68">optional sequence requirements</a>, only 02942 * @c push_back, @c at, and @c %array access are supported. 02943 * 02944 * @doctodo 02945 * 02946 * 02947 * Documentation? What's that? 02948 * Nathan Myers <ncm@cantrip.org>. 02949 * 02950 * A string looks like this: 02951 * 02952 * @code 02953 * [_Rep] 02954 * _M_length 02955 * [basic_string<char_type>] _M_capacity 02956 * _M_dataplus _M_refcount 02957 * _M_p ----------------> unnamed array of char_type 02958 * @endcode 02959 * 02960 * Where the _M_p points to the first character in the string, and 02961 * you cast it to a pointer-to-_Rep and subtract 1 to get a 02962 * pointer to the header. 02963 * 02964 * This approach has the enormous advantage that a string object 02965 * requires only one allocation. All the ugliness is confined 02966 * within a single %pair of inline functions, which each compile to 02967 * a single @a add instruction: _Rep::_M_data(), and 02968 * string::_M_rep(); and the allocation function which gets a 02969 * block of raw bytes and with room enough and constructs a _Rep 02970 * object at the front. 02971 * 02972 * The reason you want _M_data pointing to the character %array and 02973 * not the _Rep is so that the debugger can see the string 02974 * contents. (Probably we should add a non-inline member to get 02975 * the _Rep for the debugger to use, so users can check the actual 02976 * string length.) 02977 * 02978 * Note that the _Rep object is a POD so that you can have a 02979 * static <em>empty string</em> _Rep object already @a constructed before 02980 * static constructors have run. The reference-count encoding is 02981 * chosen so that a 0 indicates one reference, so you never try to 02982 * destroy the empty-string _Rep object. 02983 * 02984 * All but the last paragraph is considered pretty conventional 02985 * for a C++ string implementation. 02986 */ 02987 // 21.3 Template class basic_string 02988 template<typename _CharT, typename _Traits, typename _Alloc> 02989 class basic_string 02990 { 02991 typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; 02992 02993 // Types: 02994 public: 02995 typedef _Traits traits_type; 02996 typedef typename _Traits::char_type value_type; 02997 typedef _Alloc allocator_type; 02998 typedef typename _CharT_alloc_type::size_type size_type; 02999 typedef typename _CharT_alloc_type::difference_type difference_type; 03000 typedef typename _CharT_alloc_type::reference reference; 03001 typedef typename _CharT_alloc_type::const_reference const_reference; 03002 typedef typename _CharT_alloc_type::pointer pointer; 03003 typedef typename _CharT_alloc_type::const_pointer const_pointer; 03004 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; 03005 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> 03006 const_iterator; 03007 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 03008 typedef std::reverse_iterator<iterator> reverse_iterator; 03009 03010 private: 03011 // _Rep: string representation 03012 // Invariants: 03013 // 1. String really contains _M_length + 1 characters: due to 21.3.4 03014 // must be kept null-terminated. 03015 // 2. _M_capacity >= _M_length 03016 // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT). 03017 // 3. _M_refcount has three states: 03018 // -1: leaked, one reference, no ref-copies allowed, non-const. 03019 // 0: one reference, non-const. 03020 // n>0: n + 1 references, operations require a lock, const. 03021 // 4. All fields==0 is an empty string, given the extra storage 03022 // beyond-the-end for a null terminator; thus, the shared 03023 // empty string representation needs no constructor. 03024 03025 struct _Rep_base 03026 { 03027 size_type _M_length; 03028 size_type _M_capacity; 03029 _Atomic_word _M_refcount; 03030 }; 03031 03032 struct _Rep : _Rep_base 03033 { 03034 // Types: 03035 typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc; 03036 03037 // (Public) Data members: 03038 03039 // The maximum number of individual char_type elements of an 03040 // individual string is determined by _S_max_size. This is the 03041 // value that will be returned by max_size(). (Whereas npos 03042 // is the maximum number of bytes the allocator can allocate.) 03043 // If one was to divvy up the theoretical largest size string, 03044 // with a terminating character and m _CharT elements, it'd 03045 // look like this: 03046 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT) 03047 // Solving for m: 03048 // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1 03049 // In addition, this implementation quarters this amount. 03050 static const size_type _S_max_size; 03051 static const _CharT _S_terminal; 03052 03053 // The following storage is init'd to 0 by the linker, resulting 03054 // (carefully) in an empty string with one reference. 03055 static size_type _S_empty_rep_storage[]; 03056 03057 static _Rep& 03058 _S_empty_rep() _GLIBCXX_NOEXCEPT 03059 { 03060 // NB: Mild hack to avoid strict-aliasing warnings. Note that 03061 // _S_empty_rep_storage is never modified and the punning should 03062 // be reasonably safe in this case. 03063 void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage); 03064 return *reinterpret_cast<_Rep*>(__p); 03065 } 03066 03067 bool 03068 _M_is_leaked() const _GLIBCXX_NOEXCEPT 03069 { 03070 #if defined(__GTHREADS) 03071 // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose, 03072 // so we need to use an atomic load. However, _M_is_leaked 03073 // predicate does not change concurrently (i.e. the string is either 03074 // leaked or not), so a relaxed load is enough. 03075 return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0; 03076 #else 03077 return this->_M_refcount < 0; 03078 #endif 03079 } 03080 03081 bool 03082 _M_is_shared() const _GLIBCXX_NOEXCEPT 03083 { 03084 #if defined(__GTHREADS) 03085 // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose, 03086 // so we need to use an atomic load. Another thread can drop last 03087 // but one reference concurrently with this check, so we need this 03088 // load to be acquire to synchronize with release fetch_and_add in 03089 // _M_dispose. 03090 return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0; 03091 #else 03092 return this->_M_refcount > 0; 03093 #endif 03094 } 03095 03096 void 03097 _M_set_leaked() _GLIBCXX_NOEXCEPT 03098 { this->_M_refcount = -1; } 03099 03100 void 03101 _M_set_sharable() _GLIBCXX_NOEXCEPT 03102 { this->_M_refcount = 0; } 03103 03104 void 03105 _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT 03106 { 03107 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 03108 if (__builtin_expect(this != &_S_empty_rep(), false)) 03109 #endif 03110 { 03111 this->_M_set_sharable(); // One reference. 03112 this->_M_length = __n; 03113 traits_type::assign(this->_M_refdata()[__n], _S_terminal); 03114 // grrr. (per 21.3.4) 03115 // You cannot leave those LWG people alone for a second. 03116 } 03117 } 03118 03119 _CharT* 03120 _M_refdata() throw() 03121 { return reinterpret_cast<_CharT*>(this + 1); } 03122 03123 _CharT* 03124 _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2) 03125 { 03126 return (!_M_is_leaked() && __alloc1 == __alloc2) 03127 ? _M_refcopy() : _M_clone(__alloc1); 03128 } 03129 03130 // Create & Destroy 03131 static _Rep* 03132 _S_create(size_type, size_type, const _Alloc&); 03133 03134 void 03135 _M_dispose(const _Alloc& __a) _GLIBCXX_NOEXCEPT 03136 { 03137 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 03138 if (__builtin_expect(this != &_S_empty_rep(), false)) 03139 #endif 03140 { 03141 // Be race-detector-friendly. For more info see bits/c++config. 03142 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount); 03143 // Decrement of _M_refcount is acq_rel, because: 03144 // - all but last decrements need to release to synchronize with 03145 // the last decrement that will delete the object. 03146 // - the last decrement needs to acquire to synchronize with 03147 // all the previous decrements. 03148 // - last but one decrement needs to release to synchronize with 03149 // the acquire load in _M_is_shared that will conclude that 03150 // the object is not shared anymore. 03151 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, 03152 -1) <= 0) 03153 { 03154 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount); 03155 _M_destroy(__a); 03156 } 03157 } 03158 } // XXX MT 03159 03160 void 03161 _M_destroy(const _Alloc&) throw(); 03162 03163 _CharT* 03164 _M_refcopy() throw() 03165 { 03166 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 03167 if (__builtin_expect(this != &_S_empty_rep(), false)) 03168 #endif 03169 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1); 03170 return _M_refdata(); 03171 } // XXX MT 03172 03173 _CharT* 03174 _M_clone(const _Alloc&, size_type __res = 0); 03175 }; 03176 03177 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html 03178 struct _Alloc_hider : _Alloc 03179 { 03180 _Alloc_hider(_CharT* __dat, const _Alloc& __a) _GLIBCXX_NOEXCEPT 03181 : _Alloc(__a), _M_p(__dat) { } 03182 03183 _CharT* _M_p; // The actual data. 03184 }; 03185 03186 public: 03187 // Data Members (public): 03188 // NB: This is an unsigned type, and thus represents the maximum 03189 // size that the allocator can hold. 03190 /// Value returned by various member functions when they fail. 03191 static const size_type npos = static_cast<size_type>(-1); 03192 03193 private: 03194 // Data Members (private): 03195 mutable _Alloc_hider _M_dataplus; 03196 03197 _CharT* 03198 _M_data() const _GLIBCXX_NOEXCEPT 03199 { return _M_dataplus._M_p; } 03200 03201 _CharT* 03202 _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT 03203 { return (_M_dataplus._M_p = __p); } 03204 03205 _Rep* 03206 _M_rep() const _GLIBCXX_NOEXCEPT 03207 { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); } 03208 03209 // For the internal use we have functions similar to `begin'/`end' 03210 // but they do not call _M_leak. 03211 iterator 03212 _M_ibegin() const _GLIBCXX_NOEXCEPT 03213 { return iterator(_M_data()); } 03214 03215 iterator 03216 _M_iend() const _GLIBCXX_NOEXCEPT 03217 { return iterator(_M_data() + this->size()); } 03218 03219 void 03220 _M_leak() // for use in begin() & non-const op[] 03221 { 03222 if (!_M_rep()->_M_is_leaked()) 03223 _M_leak_hard(); 03224 } 03225 03226 size_type 03227 _M_check(size_type __pos, const char* __s) const 03228 { 03229 if (__pos > this->size()) 03230 __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " 03231 "this->size() (which is %zu)"), 03232 __s, __pos, this->size()); 03233 return __pos; 03234 } 03235 03236 void 03237 _M_check_length(size_type __n1, size_type __n2, const char* __s) const 03238 { 03239 if (this->max_size() - (this->size() - __n1) < __n2) 03240 __throw_length_error(__N(__s)); 03241 } 03242 03243 // NB: _M_limit doesn't check for a bad __pos value. 03244 size_type 03245 _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT 03246 { 03247 const bool __testoff = __off < this->size() - __pos; 03248 return __testoff ? __off : this->size() - __pos; 03249 } 03250 03251 // True if _Rep and source do not overlap. 03252 bool 03253 _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT 03254 { 03255 return (less<const _CharT*>()(__s, _M_data()) 03256 || less<const _CharT*>()(_M_data() + this->size(), __s)); 03257 } 03258 03259 // When __n = 1 way faster than the general multichar 03260 // traits_type::copy/move/assign. 03261 static void 03262 _M_copy(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT 03263 { 03264 if (__n == 1) 03265 traits_type::assign(*__d, *__s); 03266 else 03267 traits_type::copy(__d, __s, __n); 03268 } 03269 03270 static void 03271 _M_move(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT 03272 { 03273 if (__n == 1) 03274 traits_type::assign(*__d, *__s); 03275 else 03276 traits_type::move(__d, __s, __n); 03277 } 03278 03279 static void 03280 _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT 03281 { 03282 if (__n == 1) 03283 traits_type::assign(*__d, __c); 03284 else 03285 traits_type::assign(__d, __n, __c); 03286 } 03287 03288 // _S_copy_chars is a separate template to permit specialization 03289 // to optimize for the common case of pointers as iterators. 03290 template<class _Iterator> 03291 static void 03292 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) 03293 { 03294 for (; __k1 != __k2; ++__k1, (void)++__p) 03295 traits_type::assign(*__p, *__k1); // These types are off. 03296 } 03297 03298 static void 03299 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT 03300 { _S_copy_chars(__p, __k1.base(), __k2.base()); } 03301 03302 static void 03303 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) 03304 _GLIBCXX_NOEXCEPT 03305 { _S_copy_chars(__p, __k1.base(), __k2.base()); } 03306 03307 static void 03308 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT 03309 { _M_copy(__p, __k1, __k2 - __k1); } 03310 03311 static void 03312 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) 03313 _GLIBCXX_NOEXCEPT 03314 { _M_copy(__p, __k1, __k2 - __k1); } 03315 03316 static int 03317 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT 03318 { 03319 const difference_type __d = difference_type(__n1 - __n2); 03320 03321 if (__d > __gnu_cxx::__numeric_traits<int>::__max) 03322 return __gnu_cxx::__numeric_traits<int>::__max; 03323 else if (__d < __gnu_cxx::__numeric_traits<int>::__min) 03324 return __gnu_cxx::__numeric_traits<int>::__min; 03325 else 03326 return int(__d); 03327 } 03328 03329 void 03330 _M_mutate(size_type __pos, size_type __len1, size_type __len2); 03331 03332 void 03333 _M_leak_hard(); 03334 03335 static _Rep& 03336 _S_empty_rep() _GLIBCXX_NOEXCEPT 03337 { return _Rep::_S_empty_rep(); } 03338 03339 #if __cplusplus > 201402L 03340 // A helper type for avoiding boiler-plate. 03341 typedef basic_string_view<_CharT, _Traits> __sv_type; 03342 03343 template<typename _Tp, typename _Res> 03344 using _If_sv = enable_if_t< 03345 __and_<is_convertible<const _Tp&, __sv_type>, 03346 __not_<is_convertible<const _Tp&, const _CharT*>>>::value, 03347 _Res>; 03348 #endif 03349 03350 public: 03351 // Construct/copy/destroy: 03352 // NB: We overload ctors in some cases instead of using default 03353 // arguments, per 17.4.4.4 para. 2 item 2. 03354 03355 /** 03356 * @brief Default constructor creates an empty string. 03357 */ 03358 basic_string() 03359 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 03360 : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { } 03361 #else 03362 : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ } 03363 #endif 03364 03365 /** 03366 * @brief Construct an empty string using allocator @a a. 03367 */ 03368 explicit 03369 basic_string(const _Alloc& __a); 03370 03371 // NB: per LWG issue 42, semantics different from IS: 03372 /** 03373 * @brief Construct string with copy of value of @a str. 03374 * @param __str Source string. 03375 */ 03376 basic_string(const basic_string& __str); 03377 03378 // _GLIBCXX_RESOLVE_LIB_DEFECTS 03379 // 2583. no way to supply an allocator for basic_string(str, pos) 03380 /** 03381 * @brief Construct string as copy of a substring. 03382 * @param __str Source string. 03383 * @param __pos Index of first character to copy from. 03384 * @param __a Allocator to use. 03385 */ 03386 basic_string(const basic_string& __str, size_type __pos, 03387 const _Alloc& __a = _Alloc()); 03388 03389 /** 03390 * @brief Construct string as copy of a substring. 03391 * @param __str Source string. 03392 * @param __pos Index of first character to copy from. 03393 * @param __n Number of characters to copy. 03394 */ 03395 basic_string(const basic_string& __str, size_type __pos, 03396 size_type __n); 03397 /** 03398 * @brief Construct string as copy of a substring. 03399 * @param __str Source string. 03400 * @param __pos Index of first character to copy from. 03401 * @param __n Number of characters to copy. 03402 * @param __a Allocator to use. 03403 */ 03404 basic_string(const basic_string& __str, size_type __pos, 03405 size_type __n, const _Alloc& __a); 03406 03407 /** 03408 * @brief Construct string initialized by a character %array. 03409 * @param __s Source character %array. 03410 * @param __n Number of characters to copy. 03411 * @param __a Allocator to use (default is default allocator). 03412 * 03413 * NB: @a __s must have at least @a __n characters, '\\0' 03414 * has no special meaning. 03415 */ 03416 basic_string(const _CharT* __s, size_type __n, 03417 const _Alloc& __a = _Alloc()); 03418 /** 03419 * @brief Construct string as copy of a C string. 03420 * @param __s Source C string. 03421 * @param __a Allocator to use (default is default allocator). 03422 */ 03423 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()); 03424 /** 03425 * @brief Construct string as multiple characters. 03426 * @param __n Number of characters. 03427 * @param __c Character to use. 03428 * @param __a Allocator to use (default is default allocator). 03429 */ 03430 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()); 03431 03432 #if __cplusplus >= 201103L 03433 /** 03434 * @brief Move construct string. 03435 * @param __str Source string. 03436 * 03437 * The newly-created string contains the exact contents of @a __str. 03438 * @a __str is a valid, but unspecified string. 03439 **/ 03440 basic_string(basic_string&& __str) 03441 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 03442 noexcept // FIXME C++11: should always be noexcept. 03443 #endif 03444 : _M_dataplus(__str._M_dataplus) 03445 { 03446 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 03447 __str._M_data(_S_empty_rep()._M_refdata()); 03448 #else 03449 __str._M_data(_S_construct(size_type(), _CharT(), get_allocator())); 03450 #endif 03451 } 03452 03453 /** 03454 * @brief Construct string from an initializer %list. 03455 * @param __l std::initializer_list of characters. 03456 * @param __a Allocator to use (default is default allocator). 03457 */ 03458 basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()); 03459 #endif // C++11 03460 03461 /** 03462 * @brief Construct string as copy of a range. 03463 * @param __beg Start of range. 03464 * @param __end End of range. 03465 * @param __a Allocator to use (default is default allocator). 03466 */ 03467 template<class _InputIterator> 03468 basic_string(_InputIterator __beg, _InputIterator __end, 03469 const _Alloc& __a = _Alloc()); 03470 03471 #if __cplusplus > 201402L 03472 /** 03473 * @brief Construct string from a substring of a string_view. 03474 * @param __t Source string view. 03475 * @param __pos The index of the first character to copy from __t. 03476 * @param __n The number of characters to copy from __t. 03477 * @param __a Allocator to use. 03478 */ 03479 template<typename _Tp, typename = _If_sv<_Tp, void>> 03480 basic_string(const _Tp& __t, size_type __pos, size_type __n, 03481 const _Alloc& __a = _Alloc()) 03482 : basic_string(__sv_type(__t).substr(__pos, __n), __a) { } 03483 03484 /** 03485 * @brief Construct string from a string_view. 03486 * @param __sv Source string view. 03487 * @param __a Allocator to use (default is default allocator). 03488 */ 03489 explicit 03490 basic_string(__sv_type __sv, const _Alloc& __a = _Alloc()) 03491 : basic_string(__sv.data(), __sv.size(), __a) { } 03492 #endif // C++17 03493 03494 /** 03495 * @brief Destroy the string instance. 03496 */ 03497 ~basic_string() _GLIBCXX_NOEXCEPT 03498 { _M_rep()->_M_dispose(this->get_allocator()); } 03499 03500 /** 03501 * @brief Assign the value of @a str to this string. 03502 * @param __str Source string. 03503 */ 03504 basic_string& 03505 operator=(const basic_string& __str) 03506 { return this->assign(__str); } 03507 03508 /** 03509 * @brief Copy contents of @a s into this string. 03510 * @param __s Source null-terminated string. 03511 */ 03512 basic_string& 03513 operator=(const _CharT* __s) 03514 { return this->assign(__s); } 03515 03516 /** 03517 * @brief Set value to string of length 1. 03518 * @param __c Source character. 03519 * 03520 * Assigning to a character makes this string length 1 and 03521 * (*this)[0] == @a c. 03522 */ 03523 basic_string& 03524 operator=(_CharT __c) 03525 { 03526 this->assign(1, __c); 03527 return *this; 03528 } 03529 03530 #if __cplusplus >= 201103L 03531 /** 03532 * @brief Move assign the value of @a str to this string. 03533 * @param __str Source string. 03534 * 03535 * The contents of @a str are moved into this string (without copying). 03536 * @a str is a valid, but unspecified string. 03537 **/ 03538 // PR 58265, this should be noexcept. 03539 basic_string& 03540 operator=(basic_string&& __str) 03541 { 03542 // NB: DR 1204. 03543 this->swap(__str); 03544 return *this; 03545 } 03546 03547 /** 03548 * @brief Set value to string constructed from initializer %list. 03549 * @param __l std::initializer_list. 03550 */ 03551 basic_string& 03552 operator=(initializer_list<_CharT> __l) 03553 { 03554 this->assign(__l.begin(), __l.size()); 03555 return *this; 03556 } 03557 #endif // C++11 03558 03559 #if __cplusplus > 201402L 03560 /** 03561 * @brief Set value to string constructed from a string_view. 03562 * @param __sv A string_view. 03563 */ 03564 template<typename _Tp> 03565 _If_sv<_Tp, basic_string&> 03566 operator=(_Tp __sv) 03567 { return this->assign(__sv); } 03568 03569 /** 03570 * @brief Convert to a string_view. 03571 * @return A string_view. 03572 */ 03573 operator __sv_type() const noexcept 03574 { return __sv_type(data(), size()); } 03575 #endif // C++17 03576 03577 // Iterators: 03578 /** 03579 * Returns a read/write iterator that points to the first character in 03580 * the %string. Unshares the string. 03581 */ 03582 iterator 03583 begin() // FIXME C++11: should be noexcept. 03584 { 03585 _M_leak(); 03586 return iterator(_M_data()); 03587 } 03588 03589 /** 03590 * Returns a read-only (constant) iterator that points to the first 03591 * character in the %string. 03592 */ 03593 const_iterator 03594 begin() const _GLIBCXX_NOEXCEPT 03595 { return const_iterator(_M_data()); } 03596 03597 /** 03598 * Returns a read/write iterator that points one past the last 03599 * character in the %string. Unshares the string. 03600 */ 03601 iterator 03602 end() // FIXME C++11: should be noexcept. 03603 { 03604 _M_leak(); 03605 return iterator(_M_data() + this->size()); 03606 } 03607 03608 /** 03609 * Returns a read-only (constant) iterator that points one past the 03610 * last character in the %string. 03611 */ 03612 const_iterator 03613 end() const _GLIBCXX_NOEXCEPT 03614 { return const_iterator(_M_data() + this->size()); } 03615 03616 /** 03617 * Returns a read/write reverse iterator that points to the last 03618 * character in the %string. Iteration is done in reverse element 03619 * order. Unshares the string. 03620 */ 03621 reverse_iterator 03622 rbegin() // FIXME C++11: should be noexcept. 03623 { return reverse_iterator(this->end()); } 03624 03625 /** 03626 * Returns a read-only (constant) reverse iterator that points 03627 * to the last character in the %string. Iteration is done in 03628 * reverse element order. 03629 */ 03630 const_reverse_iterator 03631 rbegin() const _GLIBCXX_NOEXCEPT 03632 { return const_reverse_iterator(this->end()); } 03633 03634 /** 03635 * Returns a read/write reverse iterator that points to one before the 03636 * first character in the %string. Iteration is done in reverse 03637 * element order. Unshares the string. 03638 */ 03639 reverse_iterator 03640 rend() // FIXME C++11: should be noexcept. 03641 { return reverse_iterator(this->begin()); } 03642 03643 /** 03644 * Returns a read-only (constant) reverse iterator that points 03645 * to one before the first character in the %string. Iteration 03646 * is done in reverse element order. 03647 */ 03648 const_reverse_iterator 03649 rend() const _GLIBCXX_NOEXCEPT 03650 { return const_reverse_iterator(this->begin()); } 03651 03652 #if __cplusplus >= 201103L 03653 /** 03654 * Returns a read-only (constant) iterator that points to the first 03655 * character in the %string. 03656 */ 03657 const_iterator 03658 cbegin() const noexcept 03659 { return const_iterator(this->_M_data()); } 03660 03661 /** 03662 * Returns a read-only (constant) iterator that points one past the 03663 * last character in the %string. 03664 */ 03665 const_iterator 03666 cend() const noexcept 03667 { return const_iterator(this->_M_data() + this->size()); } 03668 03669 /** 03670 * Returns a read-only (constant) reverse iterator that points 03671 * to the last character in the %string. Iteration is done in 03672 * reverse element order. 03673 */ 03674 const_reverse_iterator 03675 crbegin() const noexcept 03676 { return const_reverse_iterator(this->end()); } 03677 03678 /** 03679 * Returns a read-only (constant) reverse iterator that points 03680 * to one before the first character in the %string. Iteration 03681 * is done in reverse element order. 03682 */ 03683 const_reverse_iterator 03684 crend() const noexcept 03685 { return const_reverse_iterator(this->begin()); } 03686 #endif 03687 03688 public: 03689 // Capacity: 03690 /// Returns the number of characters in the string, not including any 03691 /// null-termination. 03692 size_type 03693 size() const _GLIBCXX_NOEXCEPT 03694 { return _M_rep()->_M_length; } 03695 03696 /// Returns the number of characters in the string, not including any 03697 /// null-termination. 03698 size_type 03699 length() const _GLIBCXX_NOEXCEPT 03700 { return _M_rep()->_M_length; } 03701 03702 /// Returns the size() of the largest possible %string. 03703 size_type 03704 max_size() const _GLIBCXX_NOEXCEPT 03705 { return _Rep::_S_max_size; } 03706 03707 /** 03708 * @brief Resizes the %string to the specified number of characters. 03709 * @param __n Number of characters the %string should contain. 03710 * @param __c Character to fill any new elements. 03711 * 03712 * This function will %resize the %string to the specified 03713 * number of characters. If the number is smaller than the 03714 * %string's current size the %string is truncated, otherwise 03715 * the %string is extended and new elements are %set to @a __c. 03716 */ 03717 void 03718 resize(size_type __n, _CharT __c); 03719 03720 /** 03721 * @brief Resizes the %string to the specified number of characters. 03722 * @param __n Number of characters the %string should contain. 03723 * 03724 * This function will resize the %string to the specified length. If 03725 * the new size is smaller than the %string's current size the %string 03726 * is truncated, otherwise the %string is extended and new characters 03727 * are default-constructed. For basic types such as char, this means 03728 * setting them to 0. 03729 */ 03730 void 03731 resize(size_type __n) 03732 { this->resize(__n, _CharT()); } 03733 03734 #if __cplusplus >= 201103L 03735 /// A non-binding request to reduce capacity() to size(). 03736 void 03737 shrink_to_fit() _GLIBCXX_NOEXCEPT 03738 { 03739 #if __cpp_exceptions 03740 if (capacity() > size()) 03741 { 03742 try 03743 { reserve(0); } 03744 catch(...) 03745 { } 03746 } 03747 #endif 03748 } 03749 #endif 03750 03751 /** 03752 * Returns the total number of characters that the %string can hold 03753 * before needing to allocate more memory. 03754 */ 03755 size_type 03756 capacity() const _GLIBCXX_NOEXCEPT 03757 { return _M_rep()->_M_capacity; } 03758 03759 /** 03760 * @brief Attempt to preallocate enough memory for specified number of 03761 * characters. 03762 * @param __res_arg Number of characters required. 03763 * @throw std::length_error If @a __res_arg exceeds @c max_size(). 03764 * 03765 * This function attempts to reserve enough memory for the 03766 * %string to hold the specified number of characters. If the 03767 * number requested is more than max_size(), length_error is 03768 * thrown. 03769 * 03770 * The advantage of this function is that if optimal code is a 03771 * necessity and the user can determine the string length that will be 03772 * required, the user can reserve the memory in %advance, and thus 03773 * prevent a possible reallocation of memory and copying of %string 03774 * data. 03775 */ 03776 void 03777 reserve(size_type __res_arg = 0); 03778 03779 /** 03780 * Erases the string, making it empty. 03781 */ 03782 #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 03783 void 03784 clear() _GLIBCXX_NOEXCEPT 03785 { 03786 if (_M_rep()->_M_is_shared()) 03787 { 03788 _M_rep()->_M_dispose(this->get_allocator()); 03789 _M_data(_S_empty_rep()._M_refdata()); 03790 } 03791 else 03792 _M_rep()->_M_set_length_and_sharable(0); 03793 } 03794 #else 03795 // PR 56166: this should not throw. 03796 void 03797 clear() 03798 { _M_mutate(0, this->size(), 0); } 03799 #endif 03800 03801 /** 03802 * Returns true if the %string is empty. Equivalent to 03803 * <code>*this == ""</code>. 03804 */ 03805 bool 03806 empty() const _GLIBCXX_NOEXCEPT 03807 { return this->size() == 0; } 03808 03809 // Element access: 03810 /** 03811 * @brief Subscript access to the data contained in the %string. 03812 * @param __pos The index of the character to access. 03813 * @return Read-only (constant) reference to the character. 03814 * 03815 * This operator allows for easy, array-style, data access. 03816 * Note that data access with this operator is unchecked and 03817 * out_of_range lookups are not defined. (For checked lookups 03818 * see at().) 03819 */ 03820 const_reference 03821 operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT 03822 { 03823 __glibcxx_assert(__pos <= size()); 03824 return _M_data()[__pos]; 03825 } 03826 03827 /** 03828 * @brief Subscript access to the data contained in the %string. 03829 * @param __pos The index of the character to access. 03830 * @return Read/write reference to the character. 03831 * 03832 * This operator allows for easy, array-style, data access. 03833 * Note that data access with this operator is unchecked and 03834 * out_of_range lookups are not defined. (For checked lookups 03835 * see at().) Unshares the string. 03836 */ 03837 reference 03838 operator[](size_type __pos) 03839 { 03840 // Allow pos == size() both in C++98 mode, as v3 extension, 03841 // and in C++11 mode. 03842 __glibcxx_assert(__pos <= size()); 03843 // In pedantic mode be strict in C++98 mode. 03844 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size()); 03845 _M_leak(); 03846 return _M_data()[__pos]; 03847 } 03848 03849 /** 03850 * @brief Provides access to the data contained in the %string. 03851 * @param __n The index of the character to access. 03852 * @return Read-only (const) reference to the character. 03853 * @throw std::out_of_range If @a n is an invalid index. 03854 * 03855 * This function provides for safer data access. The parameter is 03856 * first checked that it is in the range of the string. The function 03857 * throws out_of_range if the check fails. 03858 */ 03859 const_reference 03860 at(size_type __n) const 03861 { 03862 if (__n >= this->size()) 03863 __throw_out_of_range_fmt(__N("basic_string::at: __n " 03864 "(which is %zu) >= this->size() " 03865 "(which is %zu)"), 03866 __n, this->size()); 03867 return _M_data()[__n]; 03868 } 03869 03870 /** 03871 * @brief Provides access to the data contained in the %string. 03872 * @param __n The index of the character to access. 03873 * @return Read/write reference to the character. 03874 * @throw std::out_of_range If @a n is an invalid index. 03875 * 03876 * This function provides for safer data access. The parameter is 03877 * first checked that it is in the range of the string. The function 03878 * throws out_of_range if the check fails. Success results in 03879 * unsharing the string. 03880 */ 03881 reference 03882 at(size_type __n) 03883 { 03884 if (__n >= size()) 03885 __throw_out_of_range_fmt(__N("basic_string::at: __n " 03886 "(which is %zu) >= this->size() " 03887 "(which is %zu)"), 03888 __n, this->size()); 03889 _M_leak(); 03890 return _M_data()[__n]; 03891 } 03892 03893 #if __cplusplus >= 201103L 03894 /** 03895 * Returns a read/write reference to the data at the first 03896 * element of the %string. 03897 */ 03898 reference 03899 front() 03900 { 03901 __glibcxx_assert(!empty()); 03902 return operator[](0); 03903 } 03904 03905 /** 03906 * Returns a read-only (constant) reference to the data at the first 03907 * element of the %string. 03908 */ 03909 const_reference 03910 front() const noexcept 03911 { 03912 __glibcxx_assert(!empty()); 03913 return operator[](0); 03914 } 03915 03916 /** 03917 * Returns a read/write reference to the data at the last 03918 * element of the %string. 03919 */ 03920 reference 03921 back() 03922 { 03923 __glibcxx_assert(!empty()); 03924 return operator[](this->size() - 1); 03925 } 03926 03927 /** 03928 * Returns a read-only (constant) reference to the data at the 03929 * last element of the %string. 03930 */ 03931 const_reference 03932 back() const noexcept 03933 { 03934 __glibcxx_assert(!empty()); 03935 return operator[](this->size() - 1); 03936 } 03937 #endif 03938 03939 // Modifiers: 03940 /** 03941 * @brief Append a string to this string. 03942 * @param __str The string to append. 03943 * @return Reference to this string. 03944 */ 03945 basic_string& 03946 operator+=(const basic_string& __str) 03947 { return this->append(__str); } 03948 03949 /** 03950 * @brief Append a C string. 03951 * @param __s The C string to append. 03952 * @return Reference to this string. 03953 */ 03954 basic_string& 03955 operator+=(const _CharT* __s) 03956 { return this->append(__s); } 03957 03958 /** 03959 * @brief Append a character. 03960 * @param __c The character to append. 03961 * @return Reference to this string. 03962 */ 03963 basic_string& 03964 operator+=(_CharT __c) 03965 { 03966 this->push_back(__c); 03967 return *this; 03968 } 03969 03970 #if __cplusplus >= 201103L 03971 /** 03972 * @brief Append an initializer_list of characters. 03973 * @param __l The initializer_list of characters to be appended. 03974 * @return Reference to this string. 03975 */ 03976 basic_string& 03977 operator+=(initializer_list<_CharT> __l) 03978 { return this->append(__l.begin(), __l.size()); } 03979 #endif // C++11 03980 03981 #if __cplusplus > 201402L 03982 /** 03983 * @brief Append a string_view. 03984 * @param __sv The string_view to be appended. 03985 * @return Reference to this string. 03986 */ 03987 basic_string& 03988 operator+=(__sv_type __sv) 03989 { return this->append(__sv); } 03990 #endif // C++17 03991 03992 /** 03993 * @brief Append a string to this string. 03994 * @param __str The string to append. 03995 * @return Reference to this string. 03996 */ 03997 basic_string& 03998 append(const basic_string& __str); 03999 04000 /** 04001 * @brief Append a substring. 04002 * @param __str The string to append. 04003 * @param __pos Index of the first character of str to append. 04004 * @param __n The number of characters to append. 04005 * @return Reference to this string. 04006 * @throw std::out_of_range if @a __pos is not a valid index. 04007 * 04008 * This function appends @a __n characters from @a __str 04009 * starting at @a __pos to this string. If @a __n is is larger 04010 * than the number of available characters in @a __str, the 04011 * remainder of @a __str is appended. 04012 */ 04013 basic_string& 04014 append(const basic_string& __str, size_type __pos, size_type __n); 04015 04016 /** 04017 * @brief Append a C substring. 04018 * @param __s The C string to append. 04019 * @param __n The number of characters to append. 04020 * @return Reference to this string. 04021 */ 04022 basic_string& 04023 append(const _CharT* __s, size_type __n); 04024 04025 /** 04026 * @brief Append a C string. 04027 * @param __s The C string to append. 04028 * @return Reference to this string. 04029 */ 04030 basic_string& 04031 append(const _CharT* __s) 04032 { 04033 __glibcxx_requires_string(__s); 04034 return this->append(__s, traits_type::length(__s)); 04035 } 04036 04037 /** 04038 * @brief Append multiple characters. 04039 * @param __n The number of characters to append. 04040 * @param __c The character to use. 04041 * @return Reference to this string. 04042 * 04043 * Appends __n copies of __c to this string. 04044 */ 04045 basic_string& 04046 append(size_type __n, _CharT __c); 04047 04048 #if __cplusplus >= 201103L 04049 /** 04050 * @brief Append an initializer_list of characters. 04051 * @param __l The initializer_list of characters to append. 04052 * @return Reference to this string. 04053 */ 04054 basic_string& 04055 append(initializer_list<_CharT> __l) 04056 { return this->append(__l.begin(), __l.size()); } 04057 #endif // C++11 04058 04059 /** 04060 * @brief Append a range of characters. 04061 * @param __first Iterator referencing the first character to append. 04062 * @param __last Iterator marking the end of the range. 04063 * @return Reference to this string. 04064 * 04065 * Appends characters in the range [__first,__last) to this string. 04066 */ 04067 template<class _InputIterator> 04068 basic_string& 04069 append(_InputIterator __first, _InputIterator __last) 04070 { return this->replace(_M_iend(), _M_iend(), __first, __last); } 04071 04072 #if __cplusplus > 201402L 04073 /** 04074 * @brief Append a string_view. 04075 * @param __sv The string_view to be appended. 04076 * @return Reference to this string. 04077 */ 04078 basic_string& 04079 append(__sv_type __sv) 04080 { return this->append(__sv.data(), __sv.size()); } 04081 04082 /** 04083 * @brief Append a range of characters from a string_view. 04084 * @param __sv The string_view to be appended from. 04085 * @param __pos The position in the string_view to append from. 04086 * @param __n The number of characters to append from the string_view. 04087 * @return Reference to this string. 04088 */ 04089 template <typename _Tp> 04090 _If_sv<_Tp, basic_string&> 04091 append(const _Tp& __svt, size_type __pos, size_type __n = npos) 04092 { 04093 __sv_type __sv = __svt; 04094 return append(__sv.data() 04095 + __sv._M_check(__pos, "basic_string::append"), 04096 __sv._M_limit(__pos, __n)); 04097 } 04098 #endif // C++17 04099 04100 /** 04101 * @brief Append a single character. 04102 * @param __c Character to append. 04103 */ 04104 void 04105 push_back(_CharT __c) 04106 { 04107 const size_type __len = 1 + this->size(); 04108 if (__len > this->capacity() || _M_rep()->_M_is_shared()) 04109 this->reserve(__len); 04110 traits_type::assign(_M_data()[this->size()], __c); 04111 _M_rep()->_M_set_length_and_sharable(__len); 04112 } 04113 04114 /** 04115 * @brief Set value to contents of another string. 04116 * @param __str Source string to use. 04117 * @return Reference to this string. 04118 */ 04119 basic_string& 04120 assign(const basic_string& __str); 04121 04122 #if __cplusplus >= 201103L 04123 /** 04124 * @brief Set value to contents of another string. 04125 * @param __str Source string to use. 04126 * @return Reference to this string. 04127 * 04128 * This function sets this string to the exact contents of @a __str. 04129 * @a __str is a valid, but unspecified string. 04130 */ 04131 // PR 58265, this should be noexcept. 04132 basic_string& 04133 assign(basic_string&& __str) 04134 { 04135 this->swap(__str); 04136 return *this; 04137 } 04138 #endif // C++11 04139 04140 /** 04141 * @brief Set value to a substring of a string. 04142 * @param __str The string to use. 04143 * @param __pos Index of the first character of str. 04144 * @param __n Number of characters to use. 04145 * @return Reference to this string. 04146 * @throw std::out_of_range if @a pos is not a valid index. 04147 * 04148 * This function sets this string to the substring of @a __str 04149 * consisting of @a __n characters at @a __pos. If @a __n is 04150 * is larger than the number of available characters in @a 04151 * __str, the remainder of @a __str is used. 04152 */ 04153 basic_string& 04154 assign(const basic_string& __str, size_type __pos, size_type __n) 04155 { return this->assign(__str._M_data() 04156 + __str._M_check(__pos, "basic_string::assign"), 04157 __str._M_limit(__pos, __n)); } 04158 04159 /** 04160 * @brief Set value to a C substring. 04161 * @param __s The C string to use. 04162 * @param __n Number of characters to use. 04163 * @return Reference to this string. 04164 * 04165 * This function sets the value of this string to the first @a __n 04166 * characters of @a __s. If @a __n is is larger than the number of 04167 * available characters in @a __s, the remainder of @a __s is used. 04168 */ 04169 basic_string& 04170 assign(const _CharT* __s, size_type __n); 04171 04172 /** 04173 * @brief Set value to contents of a C string. 04174 * @param __s The C string to use. 04175 * @return Reference to this string. 04176 * 04177 * This function sets the value of this string to the value of @a __s. 04178 * The data is copied, so there is no dependence on @a __s once the 04179 * function returns. 04180 */ 04181 basic_string& 04182 assign(const _CharT* __s) 04183 { 04184 __glibcxx_requires_string(__s); 04185 return this->assign(__s, traits_type::length(__s)); 04186 } 04187 04188 /** 04189 * @brief Set value to multiple characters. 04190 * @param __n Length of the resulting string. 04191 * @param __c The character to use. 04192 * @return Reference to this string. 04193 * 04194 * This function sets the value of this string to @a __n copies of 04195 * character @a __c. 04196 */ 04197 basic_string& 04198 assign(size_type __n, _CharT __c) 04199 { return _M_replace_aux(size_type(0), this->size(), __n, __c); } 04200 04201 /** 04202 * @brief Set value to a range of characters. 04203 * @param __first Iterator referencing the first character to append. 04204 * @param __last Iterator marking the end of the range. 04205 * @return Reference to this string. 04206 * 04207 * Sets value of string to characters in the range [__first,__last). 04208 */ 04209 template<class _InputIterator> 04210 basic_string& 04211 assign(_InputIterator __first, _InputIterator __last) 04212 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } 04213 04214 #if __cplusplus >= 201103L 04215 /** 04216 * @brief Set value to an initializer_list of characters. 04217 * @param __l The initializer_list of characters to assign. 04218 * @return Reference to this string. 04219 */ 04220 basic_string& 04221 assign(initializer_list<_CharT> __l) 04222 { return this->assign(__l.begin(), __l.size()); } 04223 #endif // C++11 04224 04225 #if __cplusplus > 201402L 04226 /** 04227 * @brief Set value from a string_view. 04228 * @param __sv The source string_view. 04229 * @return Reference to this string. 04230 */ 04231 basic_string& 04232 assign(__sv_type __sv) 04233 { return this->assign(__sv.data(), __sv.size()); } 04234 04235 /** 04236 * @brief Set value from a range of characters in a string_view. 04237 * @param __sv The source string_view. 04238 * @param __pos The position in the string_view to assign from. 04239 * @param __n The number of characters to assign. 04240 * @return Reference to this string. 04241 */ 04242 template <typename _Tp> 04243 _If_sv<_Tp, basic_string&> 04244 assign(const _Tp& __svt, size_type __pos, size_type __n = npos) 04245 { 04246 __sv_type __sv = __svt; 04247 return assign(__sv.data() 04248 + __sv._M_check(__pos, "basic_string::assign"), 04249 __sv._M_limit(__pos, __n)); 04250 } 04251 #endif // C++17 04252 04253 /** 04254 * @brief Insert multiple characters. 04255 * @param __p Iterator referencing location in string to insert at. 04256 * @param __n Number of characters to insert 04257 * @param __c The character to insert. 04258 * @throw std::length_error If new length exceeds @c max_size(). 04259 * 04260 * Inserts @a __n copies of character @a __c starting at the 04261 * position referenced by iterator @a __p. If adding 04262 * characters causes the length to exceed max_size(), 04263 * length_error is thrown. The value of the string doesn't 04264 * change if an error is thrown. 04265 */ 04266 void 04267 insert(iterator __p, size_type __n, _CharT __c) 04268 { this->replace(__p, __p, __n, __c); } 04269 04270 /** 04271 * @brief Insert a range of characters. 04272 * @param __p Iterator referencing location in string to insert at. 04273 * @param __beg Start of range. 04274 * @param __end End of range. 04275 * @throw std::length_error If new length exceeds @c max_size(). 04276 * 04277 * Inserts characters in range [__beg,__end). If adding 04278 * characters causes the length to exceed max_size(), 04279 * length_error is thrown. The value of the string doesn't 04280 * change if an error is thrown. 04281 */ 04282 template<class _InputIterator> 04283 void 04284 insert(iterator __p, _InputIterator __beg, _InputIterator __end) 04285 { this->replace(__p, __p, __beg, __end); } 04286 04287 #if __cplusplus >= 201103L 04288 /** 04289 * @brief Insert an initializer_list of characters. 04290 * @param __p Iterator referencing location in string to insert at. 04291 * @param __l The initializer_list of characters to insert. 04292 * @throw std::length_error If new length exceeds @c max_size(). 04293 */ 04294 void 04295 insert(iterator __p, initializer_list<_CharT> __l) 04296 { 04297 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 04298 this->insert(__p - _M_ibegin(), __l.begin(), __l.size()); 04299 } 04300 #endif // C++11 04301 04302 /** 04303 * @brief Insert value of a string. 04304 * @param __pos1 Iterator referencing location in string to insert at. 04305 * @param __str The string to insert. 04306 * @return Reference to this string. 04307 * @throw std::length_error If new length exceeds @c max_size(). 04308 * 04309 * Inserts value of @a __str starting at @a __pos1. If adding 04310 * characters causes the length to exceed max_size(), 04311 * length_error is thrown. The value of the string doesn't 04312 * change if an error is thrown. 04313 */ 04314 basic_string& 04315 insert(size_type __pos1, const basic_string& __str) 04316 { return this->insert(__pos1, __str, size_type(0), __str.size()); } 04317 04318 /** 04319 * @brief Insert a substring. 04320 * @param __pos1 Iterator referencing location in string to insert at. 04321 * @param __str The string to insert. 04322 * @param __pos2 Start of characters in str to insert. 04323 * @param __n Number of characters to insert. 04324 * @return Reference to this string. 04325 * @throw std::length_error If new length exceeds @c max_size(). 04326 * @throw std::out_of_range If @a pos1 > size() or 04327 * @a __pos2 > @a str.size(). 04328 * 04329 * Starting at @a pos1, insert @a __n character of @a __str 04330 * beginning with @a __pos2. If adding characters causes the 04331 * length to exceed max_size(), length_error is thrown. If @a 04332 * __pos1 is beyond the end of this string or @a __pos2 is 04333 * beyond the end of @a __str, out_of_range is thrown. The 04334 * value of the string doesn't change if an error is thrown. 04335 */ 04336 basic_string& 04337 insert(size_type __pos1, const basic_string& __str, 04338 size_type __pos2, size_type __n) 04339 { return this->insert(__pos1, __str._M_data() 04340 + __str._M_check(__pos2, "basic_string::insert"), 04341 __str._M_limit(__pos2, __n)); } 04342 04343 /** 04344 * @brief Insert a C substring. 04345 * @param __pos Iterator referencing location in string to insert at. 04346 * @param __s The C string to insert. 04347 * @param __n The number of characters to insert. 04348 * @return Reference to this string. 04349 * @throw std::length_error If new length exceeds @c max_size(). 04350 * @throw std::out_of_range If @a __pos is beyond the end of this 04351 * string. 04352 * 04353 * Inserts the first @a __n characters of @a __s starting at @a 04354 * __pos. If adding characters causes the length to exceed 04355 * max_size(), length_error is thrown. If @a __pos is beyond 04356 * end(), out_of_range is thrown. The value of the string 04357 * doesn't change if an error is thrown. 04358 */ 04359 basic_string& 04360 insert(size_type __pos, const _CharT* __s, size_type __n); 04361 04362 /** 04363 * @brief Insert a C string. 04364 * @param __pos Iterator referencing location in string to insert at. 04365 * @param __s The C string to insert. 04366 * @return Reference to this string. 04367 * @throw std::length_error If new length exceeds @c max_size(). 04368 * @throw std::out_of_range If @a pos is beyond the end of this 04369 * string. 04370 * 04371 * Inserts the first @a n characters of @a __s starting at @a __pos. If 04372 * adding characters causes the length to exceed max_size(), 04373 * length_error is thrown. If @a __pos is beyond end(), out_of_range is 04374 * thrown. The value of the string doesn't change if an error is 04375 * thrown. 04376 */ 04377 basic_string& 04378 insert(size_type __pos, const _CharT* __s) 04379 { 04380 __glibcxx_requires_string(__s); 04381 return this->insert(__pos, __s, traits_type::length(__s)); 04382 } 04383 04384 /** 04385 * @brief Insert multiple characters. 04386 * @param __pos Index in string to insert at. 04387 * @param __n Number of characters to insert 04388 * @param __c The character to insert. 04389 * @return Reference to this string. 04390 * @throw std::length_error If new length exceeds @c max_size(). 04391 * @throw std::out_of_range If @a __pos is beyond the end of this 04392 * string. 04393 * 04394 * Inserts @a __n copies of character @a __c starting at index 04395 * @a __pos. If adding characters causes the length to exceed 04396 * max_size(), length_error is thrown. If @a __pos > length(), 04397 * out_of_range is thrown. The value of the string doesn't 04398 * change if an error is thrown. 04399 */ 04400 basic_string& 04401 insert(size_type __pos, size_type __n, _CharT __c) 04402 { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), 04403 size_type(0), __n, __c); } 04404 04405 /** 04406 * @brief Insert one character. 04407 * @param __p Iterator referencing position in string to insert at. 04408 * @param __c The character to insert. 04409 * @return Iterator referencing newly inserted char. 04410 * @throw std::length_error If new length exceeds @c max_size(). 04411 * 04412 * Inserts character @a __c at position referenced by @a __p. 04413 * If adding character causes the length to exceed max_size(), 04414 * length_error is thrown. If @a __p is beyond end of string, 04415 * out_of_range is thrown. The value of the string doesn't 04416 * change if an error is thrown. 04417 */ 04418 iterator 04419 insert(iterator __p, _CharT __c) 04420 { 04421 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 04422 const size_type __pos = __p - _M_ibegin(); 04423 _M_replace_aux(__pos, size_type(0), size_type(1), __c); 04424 _M_rep()->_M_set_leaked(); 04425 return iterator(_M_data() + __pos); 04426 } 04427 04428 #if __cplusplus > 201402L 04429 /** 04430 * @brief Insert a string_view. 04431 * @param __pos Iterator referencing position in string to insert at. 04432 * @param __sv The string_view to insert. 04433 * @return Reference to this string. 04434 */ 04435 basic_string& 04436 insert(size_type __pos, __sv_type __sv) 04437 { return this->insert(__pos, __sv.data(), __sv.size()); } 04438 04439 /** 04440 * @brief Insert a string_view. 04441 * @param __pos Iterator referencing position in string to insert at. 04442 * @param __sv The string_view to insert from. 04443 * @param __pos Iterator referencing position in string_view to insert 04444 * from. 04445 * @param __n The number of characters to insert. 04446 * @return Reference to this string. 04447 */ 04448 template <typename _Tp> 04449 _If_sv<_Tp, basic_string&> 04450 insert(size_type __pos1, const _Tp& __svt, 04451 size_type __pos2, size_type __n = npos) 04452 { 04453 __sv_type __sv = __svt; 04454 return this->replace(__pos1, size_type(0), __sv.data() 04455 + __sv._M_check(__pos2, "basic_string::insert"), 04456 __sv._M_limit(__pos2, __n)); 04457 } 04458 #endif // C++17 04459 04460 /** 04461 * @brief Remove characters. 04462 * @param __pos Index of first character to remove (default 0). 04463 * @param __n Number of characters to remove (default remainder). 04464 * @return Reference to this string. 04465 * @throw std::out_of_range If @a pos is beyond the end of this 04466 * string. 04467 * 04468 * Removes @a __n characters from this string starting at @a 04469 * __pos. The length of the string is reduced by @a __n. If 04470 * there are < @a __n characters to remove, the remainder of 04471 * the string is truncated. If @a __p is beyond end of string, 04472 * out_of_range is thrown. The value of the string doesn't 04473 * change if an error is thrown. 04474 */ 04475 basic_string& 04476 erase(size_type __pos = 0, size_type __n = npos) 04477 { 04478 _M_mutate(_M_check(__pos, "basic_string::erase"), 04479 _M_limit(__pos, __n), size_type(0)); 04480 return *this; 04481 } 04482 04483 /** 04484 * @brief Remove one character. 04485 * @param __position Iterator referencing the character to remove. 04486 * @return iterator referencing same location after removal. 04487 * 04488 * Removes the character at @a __position from this string. The value 04489 * of the string doesn't change if an error is thrown. 04490 */ 04491 iterator 04492 erase(iterator __position) 04493 { 04494 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() 04495 && __position < _M_iend()); 04496 const size_type __pos = __position - _M_ibegin(); 04497 _M_mutate(__pos, size_type(1), size_type(0)); 04498 _M_rep()->_M_set_leaked(); 04499 return iterator(_M_data() + __pos); 04500 } 04501 04502 /** 04503 * @brief Remove a range of characters. 04504 * @param __first Iterator referencing the first character to remove. 04505 * @param __last Iterator referencing the end of the range. 04506 * @return Iterator referencing location of first after removal. 04507 * 04508 * Removes the characters in the range [first,last) from this string. 04509 * The value of the string doesn't change if an error is thrown. 04510 */ 04511 iterator 04512 erase(iterator __first, iterator __last); 04513 04514 #if __cplusplus >= 201103L 04515 /** 04516 * @brief Remove the last character. 04517 * 04518 * The string must be non-empty. 04519 */ 04520 void 04521 pop_back() // FIXME C++11: should be noexcept. 04522 { 04523 __glibcxx_assert(!empty()); 04524 erase(size() - 1, 1); 04525 } 04526 #endif // C++11 04527 04528 /** 04529 * @brief Replace characters with value from another string. 04530 * @param __pos Index of first character to replace. 04531 * @param __n Number of characters to be replaced. 04532 * @param __str String to insert. 04533 * @return Reference to this string. 04534 * @throw std::out_of_range If @a pos is beyond the end of this 04535 * string. 04536 * @throw std::length_error If new length exceeds @c max_size(). 04537 * 04538 * Removes the characters in the range [__pos,__pos+__n) from 04539 * this string. In place, the value of @a __str is inserted. 04540 * If @a __pos is beyond end of string, out_of_range is thrown. 04541 * If the length of the result exceeds max_size(), length_error 04542 * is thrown. The value of the string doesn't change if an 04543 * error is thrown. 04544 */ 04545 basic_string& 04546 replace(size_type __pos, size_type __n, const basic_string& __str) 04547 { return this->replace(__pos, __n, __str._M_data(), __str.size()); } 04548 04549 /** 04550 * @brief Replace characters with value from another string. 04551 * @param __pos1 Index of first character to replace. 04552 * @param __n1 Number of characters to be replaced. 04553 * @param __str String to insert. 04554 * @param __pos2 Index of first character of str to use. 04555 * @param __n2 Number of characters from str to use. 04556 * @return Reference to this string. 04557 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > 04558 * __str.size(). 04559 * @throw std::length_error If new length exceeds @c max_size(). 04560 * 04561 * Removes the characters in the range [__pos1,__pos1 + n) from this 04562 * string. In place, the value of @a __str is inserted. If @a __pos is 04563 * beyond end of string, out_of_range is thrown. If the length of the 04564 * result exceeds max_size(), length_error is thrown. The value of the 04565 * string doesn't change if an error is thrown. 04566 */ 04567 basic_string& 04568 replace(size_type __pos1, size_type __n1, const basic_string& __str, 04569 size_type __pos2, size_type __n2) 04570 { return this->replace(__pos1, __n1, __str._M_data() 04571 + __str._M_check(__pos2, "basic_string::replace"), 04572 __str._M_limit(__pos2, __n2)); } 04573 04574 /** 04575 * @brief Replace characters with value of a C substring. 04576 * @param __pos Index of first character to replace. 04577 * @param __n1 Number of characters to be replaced. 04578 * @param __s C string to insert. 04579 * @param __n2 Number of characters from @a s to use. 04580 * @return Reference to this string. 04581 * @throw std::out_of_range If @a pos1 > size(). 04582 * @throw std::length_error If new length exceeds @c max_size(). 04583 * 04584 * Removes the characters in the range [__pos,__pos + __n1) 04585 * from this string. In place, the first @a __n2 characters of 04586 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If 04587 * @a __pos is beyond end of string, out_of_range is thrown. If 04588 * the length of result exceeds max_size(), length_error is 04589 * thrown. The value of the string doesn't change if an error 04590 * is thrown. 04591 */ 04592 basic_string& 04593 replace(size_type __pos, size_type __n1, const _CharT* __s, 04594 size_type __n2); 04595 04596 /** 04597 * @brief Replace characters with value of a C string. 04598 * @param __pos Index of first character to replace. 04599 * @param __n1 Number of characters to be replaced. 04600 * @param __s C string to insert. 04601 * @return Reference to this string. 04602 * @throw std::out_of_range If @a pos > size(). 04603 * @throw std::length_error If new length exceeds @c max_size(). 04604 * 04605 * Removes the characters in the range [__pos,__pos + __n1) 04606 * from this string. In place, the characters of @a __s are 04607 * inserted. If @a __pos is beyond end of string, out_of_range 04608 * is thrown. If the length of result exceeds max_size(), 04609 * length_error is thrown. The value of the string doesn't 04610 * change if an error is thrown. 04611 */ 04612 basic_string& 04613 replace(size_type __pos, size_type __n1, const _CharT* __s) 04614 { 04615 __glibcxx_requires_string(__s); 04616 return this->replace(__pos, __n1, __s, traits_type::length(__s)); 04617 } 04618 04619 /** 04620 * @brief Replace characters with multiple characters. 04621 * @param __pos Index of first character to replace. 04622 * @param __n1 Number of characters to be replaced. 04623 * @param __n2 Number of characters to insert. 04624 * @param __c Character to insert. 04625 * @return Reference to this string. 04626 * @throw std::out_of_range If @a __pos > size(). 04627 * @throw std::length_error If new length exceeds @c max_size(). 04628 * 04629 * Removes the characters in the range [pos,pos + n1) from this 04630 * string. In place, @a __n2 copies of @a __c are inserted. 04631 * If @a __pos is beyond end of string, out_of_range is thrown. 04632 * If the length of result exceeds max_size(), length_error is 04633 * thrown. The value of the string doesn't change if an error 04634 * is thrown. 04635 */ 04636 basic_string& 04637 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) 04638 { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), 04639 _M_limit(__pos, __n1), __n2, __c); } 04640 04641 /** 04642 * @brief Replace range of characters with string. 04643 * @param __i1 Iterator referencing start of range to replace. 04644 * @param __i2 Iterator referencing end of range to replace. 04645 * @param __str String value to insert. 04646 * @return Reference to this string. 04647 * @throw std::length_error If new length exceeds @c max_size(). 04648 * 04649 * Removes the characters in the range [__i1,__i2). In place, 04650 * the value of @a __str is inserted. If the length of result 04651 * exceeds max_size(), length_error is thrown. The value of 04652 * the string doesn't change if an error is thrown. 04653 */ 04654 basic_string& 04655 replace(iterator __i1, iterator __i2, const basic_string& __str) 04656 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } 04657 04658 /** 04659 * @brief Replace range of characters with C substring. 04660 * @param __i1 Iterator referencing start of range to replace. 04661 * @param __i2 Iterator referencing end of range to replace. 04662 * @param __s C string value to insert. 04663 * @param __n Number of characters from s to insert. 04664 * @return Reference to this string. 04665 * @throw std::length_error If new length exceeds @c max_size(). 04666 * 04667 * Removes the characters in the range [__i1,__i2). In place, 04668 * the first @a __n characters of @a __s are inserted. If the 04669 * length of result exceeds max_size(), length_error is thrown. 04670 * The value of the string doesn't change if an error is 04671 * thrown. 04672 */ 04673 basic_string& 04674 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) 04675 { 04676 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 04677 && __i2 <= _M_iend()); 04678 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); 04679 } 04680 04681 /** 04682 * @brief Replace range of characters with C string. 04683 * @param __i1 Iterator referencing start of range to replace. 04684 * @param __i2 Iterator referencing end of range to replace. 04685 * @param __s C string value to insert. 04686 * @return Reference to this string. 04687 * @throw std::length_error If new length exceeds @c max_size(). 04688 * 04689 * Removes the characters in the range [__i1,__i2). In place, 04690 * the characters of @a __s are inserted. If the length of 04691 * result exceeds max_size(), length_error is thrown. The 04692 * value of the string doesn't change if an error is thrown. 04693 */ 04694 basic_string& 04695 replace(iterator __i1, iterator __i2, const _CharT* __s) 04696 { 04697 __glibcxx_requires_string(__s); 04698 return this->replace(__i1, __i2, __s, traits_type::length(__s)); 04699 } 04700 04701 /** 04702 * @brief Replace range of characters with multiple characters 04703 * @param __i1 Iterator referencing start of range to replace. 04704 * @param __i2 Iterator referencing end of range to replace. 04705 * @param __n Number of characters to insert. 04706 * @param __c Character to insert. 04707 * @return Reference to this string. 04708 * @throw std::length_error If new length exceeds @c max_size(). 04709 * 04710 * Removes the characters in the range [__i1,__i2). In place, 04711 * @a __n copies of @a __c are inserted. If the length of 04712 * result exceeds max_size(), length_error is thrown. The 04713 * value of the string doesn't change if an error is thrown. 04714 */ 04715 basic_string& 04716 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) 04717 { 04718 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 04719 && __i2 <= _M_iend()); 04720 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); 04721 } 04722 04723 /** 04724 * @brief Replace range of characters with range. 04725 * @param __i1 Iterator referencing start of range to replace. 04726 * @param __i2 Iterator referencing end of range to replace. 04727 * @param __k1 Iterator referencing start of range to insert. 04728 * @param __k2 Iterator referencing end of range to insert. 04729 * @return Reference to this string. 04730 * @throw std::length_error If new length exceeds @c max_size(). 04731 * 04732 * Removes the characters in the range [__i1,__i2). In place, 04733 * characters in the range [__k1,__k2) are inserted. If the 04734 * length of result exceeds max_size(), length_error is thrown. 04735 * The value of the string doesn't change if an error is 04736 * thrown. 04737 */ 04738 template<class _InputIterator> 04739 basic_string& 04740 replace(iterator __i1, iterator __i2, 04741 _InputIterator __k1, _InputIterator __k2) 04742 { 04743 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 04744 && __i2 <= _M_iend()); 04745 __glibcxx_requires_valid_range(__k1, __k2); 04746 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 04747 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); 04748 } 04749 04750 // Specializations for the common case of pointer and iterator: 04751 // useful to avoid the overhead of temporary buffering in _M_replace. 04752 basic_string& 04753 replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) 04754 { 04755 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 04756 && __i2 <= _M_iend()); 04757 __glibcxx_requires_valid_range(__k1, __k2); 04758 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 04759 __k1, __k2 - __k1); 04760 } 04761 04762 basic_string& 04763 replace(iterator __i1, iterator __i2, 04764 const _CharT* __k1, const _CharT* __k2) 04765 { 04766 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 04767 && __i2 <= _M_iend()); 04768 __glibcxx_requires_valid_range(__k1, __k2); 04769 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 04770 __k1, __k2 - __k1); 04771 } 04772 04773 basic_string& 04774 replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) 04775 { 04776 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 04777 && __i2 <= _M_iend()); 04778 __glibcxx_requires_valid_range(__k1, __k2); 04779 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 04780 __k1.base(), __k2 - __k1); 04781 } 04782 04783 basic_string& 04784 replace(iterator __i1, iterator __i2, 04785 const_iterator __k1, const_iterator __k2) 04786 { 04787 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 04788 && __i2 <= _M_iend()); 04789 __glibcxx_requires_valid_range(__k1, __k2); 04790 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 04791 __k1.base(), __k2 - __k1); 04792 } 04793 04794 #if __cplusplus >= 201103L 04795 /** 04796 * @brief Replace range of characters with initializer_list. 04797 * @param __i1 Iterator referencing start of range to replace. 04798 * @param __i2 Iterator referencing end of range to replace. 04799 * @param __l The initializer_list of characters to insert. 04800 * @return Reference to this string. 04801 * @throw std::length_error If new length exceeds @c max_size(). 04802 * 04803 * Removes the characters in the range [__i1,__i2). In place, 04804 * characters in the range [__k1,__k2) are inserted. If the 04805 * length of result exceeds max_size(), length_error is thrown. 04806 * The value of the string doesn't change if an error is 04807 * thrown. 04808 */ 04809 basic_string& replace(iterator __i1, iterator __i2, 04810 initializer_list<_CharT> __l) 04811 { return this->replace(__i1, __i2, __l.begin(), __l.end()); } 04812 #endif // C++11 04813 04814 #if __cplusplus > 201402L 04815 /** 04816 * @brief Replace range of characters with string_view. 04817 * @param __pos The position to replace at. 04818 * @param __n The number of characters to replace. 04819 * @param __sv The string_view to insert. 04820 * @return Reference to this string. 04821 */ 04822 basic_string& 04823 replace(size_type __pos, size_type __n, __sv_type __sv) 04824 { return this->replace(__pos, __n, __sv.data(), __sv.size()); } 04825 04826 /** 04827 * @brief Replace range of characters with string_view. 04828 * @param __pos1 The position to replace at. 04829 * @param __n1 The number of characters to replace. 04830 * @param __sv The string_view to insert from. 04831 * @param __pos2 The position in the string_view to insert from. 04832 * @param __n2 The number of characters to insert. 04833 * @return Reference to this string. 04834 */ 04835 template <typename _Tp> 04836 _If_sv<_Tp, basic_string&> 04837 replace(size_type __pos1, size_type __n1, const _Tp& __svt, 04838 size_type __pos2, size_type __n2 = npos) 04839 { 04840 __sv_type __sv = __svt; 04841 return this->replace(__pos1, __n1, __sv.data() 04842 + __sv._M_check(__pos2, "basic_string::replace"), 04843 __sv._M_limit(__pos2, __n2)); 04844 } 04845 04846 /** 04847 * @brief Replace range of characters with string_view. 04848 * @param __i1 An iterator referencing the start position 04849 to replace at. 04850 * @param __i2 An iterator referencing the end position 04851 for the replace. 04852 * @param __sv The string_view to insert from. 04853 * @return Reference to this string. 04854 */ 04855 basic_string& 04856 replace(const_iterator __i1, const_iterator __i2, __sv_type __sv) 04857 { return this->replace(__i1 - begin(), __i2 - __i1, __sv); } 04858 #endif // C++17 04859 04860 private: 04861 template<class _Integer> 04862 basic_string& 04863 _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n, 04864 _Integer __val, __true_type) 04865 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } 04866 04867 template<class _InputIterator> 04868 basic_string& 04869 _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1, 04870 _InputIterator __k2, __false_type); 04871 04872 basic_string& 04873 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, 04874 _CharT __c); 04875 04876 basic_string& 04877 _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s, 04878 size_type __n2); 04879 04880 // _S_construct_aux is used to implement the 21.3.1 para 15 which 04881 // requires special behaviour if _InIter is an integral type 04882 template<class _InIterator> 04883 static _CharT* 04884 _S_construct_aux(_InIterator __beg, _InIterator __end, 04885 const _Alloc& __a, __false_type) 04886 { 04887 typedef typename iterator_traits<_InIterator>::iterator_category _Tag; 04888 return _S_construct(__beg, __end, __a, _Tag()); 04889 } 04890 04891 // _GLIBCXX_RESOLVE_LIB_DEFECTS 04892 // 438. Ambiguity in the "do the right thing" clause 04893 template<class _Integer> 04894 static _CharT* 04895 _S_construct_aux(_Integer __beg, _Integer __end, 04896 const _Alloc& __a, __true_type) 04897 { return _S_construct_aux_2(static_cast<size_type>(__beg), 04898 __end, __a); } 04899 04900 static _CharT* 04901 _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a) 04902 { return _S_construct(__req, __c, __a); } 04903 04904 template<class _InIterator> 04905 static _CharT* 04906 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a) 04907 { 04908 typedef typename std::__is_integer<_InIterator>::__type _Integral; 04909 return _S_construct_aux(__beg, __end, __a, _Integral()); 04910 } 04911 04912 // For Input Iterators, used in istreambuf_iterators, etc. 04913 template<class _InIterator> 04914 static _CharT* 04915 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, 04916 input_iterator_tag); 04917 04918 // For forward_iterators up to random_access_iterators, used for 04919 // string::iterator, _CharT*, etc. 04920 template<class _FwdIterator> 04921 static _CharT* 04922 _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a, 04923 forward_iterator_tag); 04924 04925 static _CharT* 04926 _S_construct(size_type __req, _CharT __c, const _Alloc& __a); 04927 04928 public: 04929 04930 /** 04931 * @brief Copy substring into C string. 04932 * @param __s C string to copy value into. 04933 * @param __n Number of characters to copy. 04934 * @param __pos Index of first character to copy. 04935 * @return Number of characters actually copied 04936 * @throw std::out_of_range If __pos > size(). 04937 * 04938 * Copies up to @a __n characters starting at @a __pos into the 04939 * C string @a __s. If @a __pos is %greater than size(), 04940 * out_of_range is thrown. 04941 */ 04942 size_type 04943 copy(_CharT* __s, size_type __n, size_type __pos = 0) const; 04944 04945 /** 04946 * @brief Swap contents with another string. 04947 * @param __s String to swap with. 04948 * 04949 * Exchanges the contents of this string with that of @a __s in constant 04950 * time. 04951 */ 04952 // PR 58265, this should be noexcept. 04953 void 04954 swap(basic_string& __s); 04955 04956 // String operations: 04957 /** 04958 * @brief Return const pointer to null-terminated contents. 04959 * 04960 * This is a handle to internal data. Do not modify or dire things may 04961 * happen. 04962 */ 04963 const _CharT* 04964 c_str() const _GLIBCXX_NOEXCEPT 04965 { return _M_data(); } 04966 04967 /** 04968 * @brief Return const pointer to contents. 04969 * 04970 * This is a pointer to internal data. It is undefined to modify 04971 * the contents through the returned pointer. To get a pointer that 04972 * allows modifying the contents use @c &str[0] instead, 04973 * (or in C++17 the non-const @c str.data() overload). 04974 */ 04975 const _CharT* 04976 data() const _GLIBCXX_NOEXCEPT 04977 { return _M_data(); } 04978 04979 #if __cplusplus > 201402L 04980 /** 04981 * @brief Return non-const pointer to contents. 04982 * 04983 * This is a pointer to the character sequence held by the string. 04984 * Modifying the characters in the sequence is allowed. 04985 */ 04986 _CharT* 04987 data() noexcept 04988 { return _M_data(); } 04989 #endif 04990 04991 /** 04992 * @brief Return copy of allocator used to construct this string. 04993 */ 04994 allocator_type 04995 get_allocator() const _GLIBCXX_NOEXCEPT 04996 { return _M_dataplus; } 04997 04998 /** 04999 * @brief Find position of a C substring. 05000 * @param __s C string to locate. 05001 * @param __pos Index of character to search from. 05002 * @param __n Number of characters from @a s to search for. 05003 * @return Index of start of first occurrence. 05004 * 05005 * Starting from @a __pos, searches forward for the first @a 05006 * __n characters in @a __s within this string. If found, 05007 * returns the index where it begins. If not found, returns 05008 * npos. 05009 */ 05010 size_type 05011 find(const _CharT* __s, size_type __pos, size_type __n) const 05012 _GLIBCXX_NOEXCEPT; 05013 05014 /** 05015 * @brief Find position of a string. 05016 * @param __str String to locate. 05017 * @param __pos Index of character to search from (default 0). 05018 * @return Index of start of first occurrence. 05019 * 05020 * Starting from @a __pos, searches forward for value of @a __str within 05021 * this string. If found, returns the index where it begins. If not 05022 * found, returns npos. 05023 */ 05024 size_type 05025 find(const basic_string& __str, size_type __pos = 0) const 05026 _GLIBCXX_NOEXCEPT 05027 { return this->find(__str.data(), __pos, __str.size()); } 05028 05029 /** 05030 * @brief Find position of a C string. 05031 * @param __s C string to locate. 05032 * @param __pos Index of character to search from (default 0). 05033 * @return Index of start of first occurrence. 05034 * 05035 * Starting from @a __pos, searches forward for the value of @a 05036 * __s within this string. If found, returns the index where 05037 * it begins. If not found, returns npos. 05038 */ 05039 size_type 05040 find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 05041 { 05042 __glibcxx_requires_string(__s); 05043 return this->find(__s, __pos, traits_type::length(__s)); 05044 } 05045 05046 /** 05047 * @brief Find position of a character. 05048 * @param __c Character to locate. 05049 * @param __pos Index of character to search from (default 0). 05050 * @return Index of first occurrence. 05051 * 05052 * Starting from @a __pos, searches forward for @a __c within 05053 * this string. If found, returns the index where it was 05054 * found. If not found, returns npos. 05055 */ 05056 size_type 05057 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; 05058 05059 #if __cplusplus > 201402L 05060 /** 05061 * @brief Find position of a string_view. 05062 * @param __sv The string_view to locate. 05063 * @param __pos Index of character to search from (default 0). 05064 * @return Index of start of first occurrence. 05065 */ 05066 size_type 05067 find(__sv_type __sv, size_type __pos = 0) const noexcept 05068 { return this->find(__sv.data(), __pos, __sv.size()); } 05069 #endif // C++17 05070 05071 /** 05072 * @brief Find last position of a string. 05073 * @param __str String to locate. 05074 * @param __pos Index of character to search back from (default end). 05075 * @return Index of start of last occurrence. 05076 * 05077 * Starting from @a __pos, searches backward for value of @a 05078 * __str within this string. If found, returns the index where 05079 * it begins. If not found, returns npos. 05080 */ 05081 size_type 05082 rfind(const basic_string& __str, size_type __pos = npos) const 05083 _GLIBCXX_NOEXCEPT 05084 { return this->rfind(__str.data(), __pos, __str.size()); } 05085 05086 /** 05087 * @brief Find last position of a C substring. 05088 * @param __s C string to locate. 05089 * @param __pos Index of character to search back from. 05090 * @param __n Number of characters from s to search for. 05091 * @return Index of start of last occurrence. 05092 * 05093 * Starting from @a __pos, searches backward for the first @a 05094 * __n characters in @a __s within this string. If found, 05095 * returns the index where it begins. If not found, returns 05096 * npos. 05097 */ 05098 size_type 05099 rfind(const _CharT* __s, size_type __pos, size_type __n) const 05100 _GLIBCXX_NOEXCEPT; 05101 05102 /** 05103 * @brief Find last position of a C string. 05104 * @param __s C string to locate. 05105 * @param __pos Index of character to start search at (default end). 05106 * @return Index of start of last occurrence. 05107 * 05108 * Starting from @a __pos, searches backward for the value of 05109 * @a __s within this string. If found, returns the index 05110 * where it begins. If not found, returns npos. 05111 */ 05112 size_type 05113 rfind(const _CharT* __s, size_type __pos = npos) const _GLIBCXX_NOEXCEPT 05114 { 05115 __glibcxx_requires_string(__s); 05116 return this->rfind(__s, __pos, traits_type::length(__s)); 05117 } 05118 05119 /** 05120 * @brief Find last position of a character. 05121 * @param __c Character to locate. 05122 * @param __pos Index of character to search back from (default end). 05123 * @return Index of last occurrence. 05124 * 05125 * Starting from @a __pos, searches backward for @a __c within 05126 * this string. If found, returns the index where it was 05127 * found. If not found, returns npos. 05128 */ 05129 size_type 05130 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; 05131 05132 #if __cplusplus > 201402L 05133 /** 05134 * @brief Find last position of a string_view. 05135 * @param __sv The string_view to locate. 05136 * @param __pos Index of character to search back from (default end). 05137 * @return Index of start of last occurrence. 05138 */ 05139 size_type 05140 rfind(__sv_type __sv, size_type __pos = npos) const noexcept 05141 { return this->rfind(__sv.data(), __pos, __sv.size()); } 05142 #endif // C++17 05143 05144 /** 05145 * @brief Find position of a character of string. 05146 * @param __str String containing characters to locate. 05147 * @param __pos Index of character to search from (default 0). 05148 * @return Index of first occurrence. 05149 * 05150 * Starting from @a __pos, searches forward for one of the 05151 * characters of @a __str within this string. If found, 05152 * returns the index where it was found. If not found, returns 05153 * npos. 05154 */ 05155 size_type 05156 find_first_of(const basic_string& __str, size_type __pos = 0) const 05157 _GLIBCXX_NOEXCEPT 05158 { return this->find_first_of(__str.data(), __pos, __str.size()); } 05159 05160 /** 05161 * @brief Find position of a character of C substring. 05162 * @param __s String containing characters to locate. 05163 * @param __pos Index of character to search from. 05164 * @param __n Number of characters from s to search for. 05165 * @return Index of first occurrence. 05166 * 05167 * Starting from @a __pos, searches forward for one of the 05168 * first @a __n characters of @a __s within this string. If 05169 * found, returns the index where it was found. If not found, 05170 * returns npos. 05171 */ 05172 size_type 05173 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const 05174 _GLIBCXX_NOEXCEPT; 05175 05176 /** 05177 * @brief Find position of a character of C string. 05178 * @param __s String containing characters to locate. 05179 * @param __pos Index of character to search from (default 0). 05180 * @return Index of first occurrence. 05181 * 05182 * Starting from @a __pos, searches forward for one of the 05183 * characters of @a __s within this string. If found, returns 05184 * the index where it was found. If not found, returns npos. 05185 */ 05186 size_type 05187 find_first_of(const _CharT* __s, size_type __pos = 0) const 05188 _GLIBCXX_NOEXCEPT 05189 { 05190 __glibcxx_requires_string(__s); 05191 return this->find_first_of(__s, __pos, traits_type::length(__s)); 05192 } 05193 05194 /** 05195 * @brief Find position of a character. 05196 * @param __c Character to locate. 05197 * @param __pos Index of character to search from (default 0). 05198 * @return Index of first occurrence. 05199 * 05200 * Starting from @a __pos, searches forward for the character 05201 * @a __c within this string. If found, returns the index 05202 * where it was found. If not found, returns npos. 05203 * 05204 * Note: equivalent to find(__c, __pos). 05205 */ 05206 size_type 05207 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 05208 { return this->find(__c, __pos); } 05209 05210 #if __cplusplus > 201402L 05211 /** 05212 * @brief Find position of a character of a string_view. 05213 * @param __sv A string_view containing characters to locate. 05214 * @param __pos Index of character to search from (default 0). 05215 * @return Index of first occurrence. 05216 */ 05217 size_type 05218 find_first_of(__sv_type __sv, size_type __pos = 0) const noexcept 05219 { return this->find_first_of(__sv.data(), __pos, __sv.size()); } 05220 #endif // C++17 05221 05222 /** 05223 * @brief Find last position of a character of string. 05224 * @param __str String containing characters to locate. 05225 * @param __pos Index of character to search back from (default end). 05226 * @return Index of last occurrence. 05227 * 05228 * Starting from @a __pos, searches backward for one of the 05229 * characters of @a __str within this string. If found, 05230 * returns the index where it was found. If not found, returns 05231 * npos. 05232 */ 05233 size_type 05234 find_last_of(const basic_string& __str, size_type __pos = npos) const 05235 _GLIBCXX_NOEXCEPT 05236 { return this->find_last_of(__str.data(), __pos, __str.size()); } 05237 05238 /** 05239 * @brief Find last position of a character of C substring. 05240 * @param __s C string containing characters to locate. 05241 * @param __pos Index of character to search back from. 05242 * @param __n Number of characters from s to search for. 05243 * @return Index of last occurrence. 05244 * 05245 * Starting from @a __pos, searches backward for one of the 05246 * first @a __n characters of @a __s within this string. If 05247 * found, returns the index where it was found. If not found, 05248 * returns npos. 05249 */ 05250 size_type 05251 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const 05252 _GLIBCXX_NOEXCEPT; 05253 05254 /** 05255 * @brief Find last position of a character of C string. 05256 * @param __s C string containing characters to locate. 05257 * @param __pos Index of character to search back from (default end). 05258 * @return Index of last occurrence. 05259 * 05260 * Starting from @a __pos, searches backward for one of the 05261 * characters of @a __s within this string. If found, returns 05262 * the index where it was found. If not found, returns npos. 05263 */ 05264 size_type 05265 find_last_of(const _CharT* __s, size_type __pos = npos) const 05266 _GLIBCXX_NOEXCEPT 05267 { 05268 __glibcxx_requires_string(__s); 05269 return this->find_last_of(__s, __pos, traits_type::length(__s)); 05270 } 05271 05272 /** 05273 * @brief Find last position of a character. 05274 * @param __c Character to locate. 05275 * @param __pos Index of character to search back from (default end). 05276 * @return Index of last occurrence. 05277 * 05278 * Starting from @a __pos, searches backward for @a __c within 05279 * this string. If found, returns the index where it was 05280 * found. If not found, returns npos. 05281 * 05282 * Note: equivalent to rfind(__c, __pos). 05283 */ 05284 size_type 05285 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT 05286 { return this->rfind(__c, __pos); } 05287 05288 #if __cplusplus > 201402L 05289 /** 05290 * @brief Find last position of a character of string. 05291 * @param __sv A string_view containing characters to locate. 05292 * @param __pos Index of character to search back from (default end). 05293 * @return Index of last occurrence. 05294 */ 05295 size_type 05296 find_last_of(__sv_type __sv, size_type __pos = npos) const noexcept 05297 { return this->find_last_of(__sv.data(), __pos, __sv.size()); } 05298 #endif // C++17 05299 05300 /** 05301 * @brief Find position of a character not in string. 05302 * @param __str String containing characters to avoid. 05303 * @param __pos Index of character to search from (default 0). 05304 * @return Index of first occurrence. 05305 * 05306 * Starting from @a __pos, searches forward for a character not contained 05307 * in @a __str within this string. If found, returns the index where it 05308 * was found. If not found, returns npos. 05309 */ 05310 size_type 05311 find_first_not_of(const basic_string& __str, size_type __pos = 0) const 05312 _GLIBCXX_NOEXCEPT 05313 { return this->find_first_not_of(__str.data(), __pos, __str.size()); } 05314 05315 /** 05316 * @brief Find position of a character not in C substring. 05317 * @param __s C string containing characters to avoid. 05318 * @param __pos Index of character to search from. 05319 * @param __n Number of characters from __s to consider. 05320 * @return Index of first occurrence. 05321 * 05322 * Starting from @a __pos, searches forward for a character not 05323 * contained in the first @a __n characters of @a __s within 05324 * this string. If found, returns the index where it was 05325 * found. If not found, returns npos. 05326 */ 05327 size_type 05328 find_first_not_of(const _CharT* __s, size_type __pos, 05329 size_type __n) const _GLIBCXX_NOEXCEPT; 05330 05331 /** 05332 * @brief Find position of a character not in C string. 05333 * @param __s C string containing characters to avoid. 05334 * @param __pos Index of character to search from (default 0). 05335 * @return Index of first occurrence. 05336 * 05337 * Starting from @a __pos, searches forward for a character not 05338 * contained in @a __s within this string. If found, returns 05339 * the index where it was found. If not found, returns npos. 05340 */ 05341 size_type 05342 find_first_not_of(const _CharT* __s, size_type __pos = 0) const 05343 _GLIBCXX_NOEXCEPT 05344 { 05345 __glibcxx_requires_string(__s); 05346 return this->find_first_not_of(__s, __pos, traits_type::length(__s)); 05347 } 05348 05349 /** 05350 * @brief Find position of a different character. 05351 * @param __c Character to avoid. 05352 * @param __pos Index of character to search from (default 0). 05353 * @return Index of first occurrence. 05354 * 05355 * Starting from @a __pos, searches forward for a character 05356 * other than @a __c within this string. If found, returns the 05357 * index where it was found. If not found, returns npos. 05358 */ 05359 size_type 05360 find_first_not_of(_CharT __c, size_type __pos = 0) const 05361 _GLIBCXX_NOEXCEPT; 05362 05363 #if __cplusplus > 201402L 05364 /** 05365 * @brief Find position of a character not in a string_view. 05366 * @param __sv A string_view containing characters to avoid. 05367 * @param __pos Index of character to search from (default 0). 05368 * @return Index of first occurrence. 05369 */ 05370 size_type 05371 find_first_not_of(__sv_type __sv, size_type __pos = 0) const noexcept 05372 { return this->find_first_not_of(__sv.data(), __pos, __sv.size()); } 05373 #endif // C++17 05374 05375 /** 05376 * @brief Find last position of a character not in string. 05377 * @param __str String containing characters to avoid. 05378 * @param __pos Index of character to search back from (default end). 05379 * @return Index of last occurrence. 05380 * 05381 * Starting from @a __pos, searches backward for a character 05382 * not contained in @a __str within this string. If found, 05383 * returns the index where it was found. If not found, returns 05384 * npos. 05385 */ 05386 size_type 05387 find_last_not_of(const basic_string& __str, size_type __pos = npos) const 05388 _GLIBCXX_NOEXCEPT 05389 { return this->find_last_not_of(__str.data(), __pos, __str.size()); } 05390 05391 /** 05392 * @brief Find last position of a character not in C substring. 05393 * @param __s C string containing characters to avoid. 05394 * @param __pos Index of character to search back from. 05395 * @param __n Number of characters from s to consider. 05396 * @return Index of last occurrence. 05397 * 05398 * Starting from @a __pos, searches backward for a character not 05399 * contained in the first @a __n characters of @a __s within this string. 05400 * If found, returns the index where it was found. If not found, 05401 * returns npos. 05402 */ 05403 size_type 05404 find_last_not_of(const _CharT* __s, size_type __pos, 05405 size_type __n) const _GLIBCXX_NOEXCEPT; 05406 /** 05407 * @brief Find last position of a character not in C string. 05408 * @param __s C string containing characters to avoid. 05409 * @param __pos Index of character to search back from (default end). 05410 * @return Index of last occurrence. 05411 * 05412 * Starting from @a __pos, searches backward for a character 05413 * not contained in @a __s within this string. If found, 05414 * returns the index where it was found. If not found, returns 05415 * npos. 05416 */ 05417 size_type 05418 find_last_not_of(const _CharT* __s, size_type __pos = npos) const 05419 _GLIBCXX_NOEXCEPT 05420 { 05421 __glibcxx_requires_string(__s); 05422 return this->find_last_not_of(__s, __pos, traits_type::length(__s)); 05423 } 05424 05425 /** 05426 * @brief Find last position of a different character. 05427 * @param __c Character to avoid. 05428 * @param __pos Index of character to search back from (default end). 05429 * @return Index of last occurrence. 05430 * 05431 * Starting from @a __pos, searches backward for a character other than 05432 * @a __c within this string. If found, returns the index where it was 05433 * found. If not found, returns npos. 05434 */ 05435 size_type 05436 find_last_not_of(_CharT __c, size_type __pos = npos) const 05437 _GLIBCXX_NOEXCEPT; 05438 05439 #if __cplusplus > 201402L 05440 /** 05441 * @brief Find last position of a character not in a string_view. 05442 * @param __sv A string_view containing characters to avoid. 05443 * @param __pos Index of character to search back from (default end). 05444 * @return Index of last occurrence. 05445 */ 05446 size_type 05447 find_last_not_of(__sv_type __sv, size_type __pos = npos) const noexcept 05448 { return this->find_last_not_of(__sv.data(), __pos, __sv.size()); } 05449 #endif // C++17 05450 05451 /** 05452 * @brief Get a substring. 05453 * @param __pos Index of first character (default 0). 05454 * @param __n Number of characters in substring (default remainder). 05455 * @return The new string. 05456 * @throw std::out_of_range If __pos > size(). 05457 * 05458 * Construct and return a new string using the @a __n 05459 * characters starting at @a __pos. If the string is too 05460 * short, use the remainder of the characters. If @a __pos is 05461 * beyond the end of the string, out_of_range is thrown. 05462 */ 05463 basic_string 05464 substr(size_type __pos = 0, size_type __n = npos) const 05465 { return basic_string(*this, 05466 _M_check(__pos, "basic_string::substr"), __n); } 05467 05468 /** 05469 * @brief Compare to a string. 05470 * @param __str String to compare against. 05471 * @return Integer < 0, 0, or > 0. 05472 * 05473 * Returns an integer < 0 if this string is ordered before @a 05474 * __str, 0 if their values are equivalent, or > 0 if this 05475 * string is ordered after @a __str. Determines the effective 05476 * length rlen of the strings to compare as the smallest of 05477 * size() and str.size(). The function then compares the two 05478 * strings by calling traits::compare(data(), str.data(),rlen). 05479 * If the result of the comparison is nonzero returns it, 05480 * otherwise the shorter one is ordered first. 05481 */ 05482 int 05483 compare(const basic_string& __str) const 05484 { 05485 const size_type __size = this->size(); 05486 const size_type __osize = __str.size(); 05487 const size_type __len = std::min(__size, __osize); 05488 05489 int __r = traits_type::compare(_M_data(), __str.data(), __len); 05490 if (!__r) 05491 __r = _S_compare(__size, __osize); 05492 return __r; 05493 } 05494 05495 #if __cplusplus > 201402L 05496 /** 05497 * @brief Compare to a string_view. 05498 * @param __sv A string_view to compare against. 05499 * @return Integer < 0, 0, or > 0. 05500 */ 05501 int 05502 compare(__sv_type __sv) const 05503 { 05504 const size_type __size = this->size(); 05505 const size_type __osize = __sv.size(); 05506 const size_type __len = std::min(__size, __osize); 05507 05508 int __r = traits_type::compare(_M_data(), __sv.data(), __len); 05509 if (!__r) 05510 __r = _S_compare(__size, __osize); 05511 return __r; 05512 } 05513 05514 /** 05515 * @brief Compare to a string_view. 05516 * @param __pos A position in the string to start comparing from. 05517 * @param __n The number of characters to compare. 05518 * @param __sv A string_view to compare against. 05519 * @return Integer < 0, 0, or > 0. 05520 */ 05521 int 05522 compare(size_type __pos, size_type __n, __sv_type __sv) const 05523 { return __sv_type(*this).substr(__pos, __n).compare(__sv); } 05524 05525 /** 05526 * @brief Compare to a string_view. 05527 * @param __pos1 A position in the string to start comparing from. 05528 * @param __n1 The number of characters to compare. 05529 * @param __sv A string_view to compare against. 05530 * @param __pos2 A position in the string_view to start comparing from. 05531 * @param __n2 The number of characters to compare. 05532 * @return Integer < 0, 0, or > 0. 05533 */ 05534 template <typename _Tp> 05535 _If_sv<_Tp, int> 05536 compare(size_type __pos1, size_type __n1, const _Tp& __svt, 05537 size_type __pos2, size_type __n2 = npos) const 05538 { 05539 __sv_type __sv = __svt; 05540 return __sv_type(*this) 05541 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); 05542 } 05543 #endif // C++17 05544 05545 /** 05546 * @brief Compare substring to a string. 05547 * @param __pos Index of first character of substring. 05548 * @param __n Number of characters in substring. 05549 * @param __str String to compare against. 05550 * @return Integer < 0, 0, or > 0. 05551 * 05552 * Form the substring of this string from the @a __n characters 05553 * starting at @a __pos. Returns an integer < 0 if the 05554 * substring is ordered before @a __str, 0 if their values are 05555 * equivalent, or > 0 if the substring is ordered after @a 05556 * __str. Determines the effective length rlen of the strings 05557 * to compare as the smallest of the length of the substring 05558 * and @a __str.size(). The function then compares the two 05559 * strings by calling 05560 * traits::compare(substring.data(),str.data(),rlen). If the 05561 * result of the comparison is nonzero returns it, otherwise 05562 * the shorter one is ordered first. 05563 */ 05564 int 05565 compare(size_type __pos, size_type __n, const basic_string& __str) const; 05566 05567 /** 05568 * @brief Compare substring to a substring. 05569 * @param __pos1 Index of first character of substring. 05570 * @param __n1 Number of characters in substring. 05571 * @param __str String to compare against. 05572 * @param __pos2 Index of first character of substring of str. 05573 * @param __n2 Number of characters in substring of str. 05574 * @return Integer < 0, 0, or > 0. 05575 * 05576 * Form the substring of this string from the @a __n1 05577 * characters starting at @a __pos1. Form the substring of @a 05578 * __str from the @a __n2 characters starting at @a __pos2. 05579 * Returns an integer < 0 if this substring is ordered before 05580 * the substring of @a __str, 0 if their values are equivalent, 05581 * or > 0 if this substring is ordered after the substring of 05582 * @a __str. Determines the effective length rlen of the 05583 * strings to compare as the smallest of the lengths of the 05584 * substrings. The function then compares the two strings by 05585 * calling 05586 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). 05587 * If the result of the comparison is nonzero returns it, 05588 * otherwise the shorter one is ordered first. 05589 */ 05590 int 05591 compare(size_type __pos1, size_type __n1, const basic_string& __str, 05592 size_type __pos2, size_type __n2) const; 05593 05594 /** 05595 * @brief Compare to a C string. 05596 * @param __s C string to compare against. 05597 * @return Integer < 0, 0, or > 0. 05598 * 05599 * Returns an integer < 0 if this string is ordered before @a __s, 0 if 05600 * their values are equivalent, or > 0 if this string is ordered after 05601 * @a __s. Determines the effective length rlen of the strings to 05602 * compare as the smallest of size() and the length of a string 05603 * constructed from @a __s. The function then compares the two strings 05604 * by calling traits::compare(data(),s,rlen). If the result of the 05605 * comparison is nonzero returns it, otherwise the shorter one is 05606 * ordered first. 05607 */ 05608 int 05609 compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT; 05610 05611 // _GLIBCXX_RESOLVE_LIB_DEFECTS 05612 // 5 String::compare specification questionable 05613 /** 05614 * @brief Compare substring to a C string. 05615 * @param __pos Index of first character of substring. 05616 * @param __n1 Number of characters in substring. 05617 * @param __s C string to compare against. 05618 * @return Integer < 0, 0, or > 0. 05619 * 05620 * Form the substring of this string from the @a __n1 05621 * characters starting at @a pos. Returns an integer < 0 if 05622 * the substring is ordered before @a __s, 0 if their values 05623 * are equivalent, or > 0 if the substring is ordered after @a 05624 * __s. Determines the effective length rlen of the strings to 05625 * compare as the smallest of the length of the substring and 05626 * the length of a string constructed from @a __s. The 05627 * function then compares the two string by calling 05628 * traits::compare(substring.data(),__s,rlen). If the result of 05629 * the comparison is nonzero returns it, otherwise the shorter 05630 * one is ordered first. 05631 */ 05632 int 05633 compare(size_type __pos, size_type __n1, const _CharT* __s) const; 05634 05635 /** 05636 * @brief Compare substring against a character %array. 05637 * @param __pos Index of first character of substring. 05638 * @param __n1 Number of characters in substring. 05639 * @param __s character %array to compare against. 05640 * @param __n2 Number of characters of s. 05641 * @return Integer < 0, 0, or > 0. 05642 * 05643 * Form the substring of this string from the @a __n1 05644 * characters starting at @a __pos. Form a string from the 05645 * first @a __n2 characters of @a __s. Returns an integer < 0 05646 * if this substring is ordered before the string from @a __s, 05647 * 0 if their values are equivalent, or > 0 if this substring 05648 * is ordered after the string from @a __s. Determines the 05649 * effective length rlen of the strings to compare as the 05650 * smallest of the length of the substring and @a __n2. The 05651 * function then compares the two strings by calling 05652 * traits::compare(substring.data(),s,rlen). If the result of 05653 * the comparison is nonzero returns it, otherwise the shorter 05654 * one is ordered first. 05655 * 05656 * NB: s must have at least n2 characters, '\\0' has 05657 * no special meaning. 05658 */ 05659 int 05660 compare(size_type __pos, size_type __n1, const _CharT* __s, 05661 size_type __n2) const; 05662 05663 # ifdef _GLIBCXX_TM_TS_INTERNAL 05664 friend void 05665 ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s, 05666 void* exc); 05667 friend const char* 05668 ::_txnal_cow_string_c_str(const void *that); 05669 friend void 05670 ::_txnal_cow_string_D1(void *that); 05671 friend void 05672 ::_txnal_cow_string_D1_commit(void *that); 05673 # endif 05674 }; 05675 #endif // !_GLIBCXX_USE_CXX11_ABI 05676 05677 // operator+ 05678 /** 05679 * @brief Concatenate two strings. 05680 * @param __lhs First string. 05681 * @param __rhs Last string. 05682 * @return New string with value of @a __lhs followed by @a __rhs. 05683 */ 05684 template<typename _CharT, typename _Traits, typename _Alloc> 05685 basic_string<_CharT, _Traits, _Alloc> 05686 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05687 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05688 { 05689 basic_string<_CharT, _Traits, _Alloc> __str(__lhs); 05690 __str.append(__rhs); 05691 return __str; 05692 } 05693 05694 /** 05695 * @brief Concatenate C string and string. 05696 * @param __lhs First string. 05697 * @param __rhs Last string. 05698 * @return New string with value of @a __lhs followed by @a __rhs. 05699 */ 05700 template<typename _CharT, typename _Traits, typename _Alloc> 05701 basic_string<_CharT,_Traits,_Alloc> 05702 operator+(const _CharT* __lhs, 05703 const basic_string<_CharT,_Traits,_Alloc>& __rhs); 05704 05705 /** 05706 * @brief Concatenate character and string. 05707 * @param __lhs First string. 05708 * @param __rhs Last string. 05709 * @return New string with @a __lhs followed by @a __rhs. 05710 */ 05711 template<typename _CharT, typename _Traits, typename _Alloc> 05712 basic_string<_CharT,_Traits,_Alloc> 05713 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs); 05714 05715 /** 05716 * @brief Concatenate string and C string. 05717 * @param __lhs First string. 05718 * @param __rhs Last string. 05719 * @return New string with @a __lhs followed by @a __rhs. 05720 */ 05721 template<typename _CharT, typename _Traits, typename _Alloc> 05722 inline basic_string<_CharT, _Traits, _Alloc> 05723 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05724 const _CharT* __rhs) 05725 { 05726 basic_string<_CharT, _Traits, _Alloc> __str(__lhs); 05727 __str.append(__rhs); 05728 return __str; 05729 } 05730 05731 /** 05732 * @brief Concatenate string and character. 05733 * @param __lhs First string. 05734 * @param __rhs Last string. 05735 * @return New string with @a __lhs followed by @a __rhs. 05736 */ 05737 template<typename _CharT, typename _Traits, typename _Alloc> 05738 inline basic_string<_CharT, _Traits, _Alloc> 05739 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) 05740 { 05741 typedef basic_string<_CharT, _Traits, _Alloc> __string_type; 05742 typedef typename __string_type::size_type __size_type; 05743 __string_type __str(__lhs); 05744 __str.append(__size_type(1), __rhs); 05745 return __str; 05746 } 05747 05748 #if __cplusplus >= 201103L 05749 template<typename _CharT, typename _Traits, typename _Alloc> 05750 inline basic_string<_CharT, _Traits, _Alloc> 05751 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, 05752 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05753 { return std::move(__lhs.append(__rhs)); } 05754 05755 template<typename _CharT, typename _Traits, typename _Alloc> 05756 inline basic_string<_CharT, _Traits, _Alloc> 05757 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05758 basic_string<_CharT, _Traits, _Alloc>&& __rhs) 05759 { return std::move(__rhs.insert(0, __lhs)); } 05760 05761 template<typename _CharT, typename _Traits, typename _Alloc> 05762 inline basic_string<_CharT, _Traits, _Alloc> 05763 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, 05764 basic_string<_CharT, _Traits, _Alloc>&& __rhs) 05765 { 05766 const auto __size = __lhs.size() + __rhs.size(); 05767 const bool __cond = (__size > __lhs.capacity() 05768 && __size <= __rhs.capacity()); 05769 return __cond ? std::move(__rhs.insert(0, __lhs)) 05770 : std::move(__lhs.append(__rhs)); 05771 } 05772 05773 template<typename _CharT, typename _Traits, typename _Alloc> 05774 inline basic_string<_CharT, _Traits, _Alloc> 05775 operator+(const _CharT* __lhs, 05776 basic_string<_CharT, _Traits, _Alloc>&& __rhs) 05777 { return std::move(__rhs.insert(0, __lhs)); } 05778 05779 template<typename _CharT, typename _Traits, typename _Alloc> 05780 inline basic_string<_CharT, _Traits, _Alloc> 05781 operator+(_CharT __lhs, 05782 basic_string<_CharT, _Traits, _Alloc>&& __rhs) 05783 { return std::move(__rhs.insert(0, 1, __lhs)); } 05784 05785 template<typename _CharT, typename _Traits, typename _Alloc> 05786 inline basic_string<_CharT, _Traits, _Alloc> 05787 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, 05788 const _CharT* __rhs) 05789 { return std::move(__lhs.append(__rhs)); } 05790 05791 template<typename _CharT, typename _Traits, typename _Alloc> 05792 inline basic_string<_CharT, _Traits, _Alloc> 05793 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, 05794 _CharT __rhs) 05795 { return std::move(__lhs.append(1, __rhs)); } 05796 #endif 05797 05798 // operator == 05799 /** 05800 * @brief Test equivalence of two strings. 05801 * @param __lhs First string. 05802 * @param __rhs Second string. 05803 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 05804 */ 05805 template<typename _CharT, typename _Traits, typename _Alloc> 05806 inline bool 05807 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05808 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05809 _GLIBCXX_NOEXCEPT 05810 { return __lhs.compare(__rhs) == 0; } 05811 05812 template<typename _CharT> 05813 inline 05814 typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type 05815 operator==(const basic_string<_CharT>& __lhs, 05816 const basic_string<_CharT>& __rhs) _GLIBCXX_NOEXCEPT 05817 { return (__lhs.size() == __rhs.size() 05818 && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), 05819 __lhs.size())); } 05820 05821 /** 05822 * @brief Test equivalence of C string and string. 05823 * @param __lhs C string. 05824 * @param __rhs String. 05825 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. 05826 */ 05827 template<typename _CharT, typename _Traits, typename _Alloc> 05828 inline bool 05829 operator==(const _CharT* __lhs, 05830 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05831 { return __rhs.compare(__lhs) == 0; } 05832 05833 /** 05834 * @brief Test equivalence of string and C string. 05835 * @param __lhs String. 05836 * @param __rhs C string. 05837 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 05838 */ 05839 template<typename _CharT, typename _Traits, typename _Alloc> 05840 inline bool 05841 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05842 const _CharT* __rhs) 05843 { return __lhs.compare(__rhs) == 0; } 05844 05845 // operator != 05846 /** 05847 * @brief Test difference of two strings. 05848 * @param __lhs First string. 05849 * @param __rhs Second string. 05850 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 05851 */ 05852 template<typename _CharT, typename _Traits, typename _Alloc> 05853 inline bool 05854 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05855 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05856 _GLIBCXX_NOEXCEPT 05857 { return !(__lhs == __rhs); } 05858 05859 /** 05860 * @brief Test difference of C string and string. 05861 * @param __lhs C string. 05862 * @param __rhs String. 05863 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. 05864 */ 05865 template<typename _CharT, typename _Traits, typename _Alloc> 05866 inline bool 05867 operator!=(const _CharT* __lhs, 05868 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05869 { return !(__lhs == __rhs); } 05870 05871 /** 05872 * @brief Test difference of string and C string. 05873 * @param __lhs String. 05874 * @param __rhs C string. 05875 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 05876 */ 05877 template<typename _CharT, typename _Traits, typename _Alloc> 05878 inline bool 05879 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05880 const _CharT* __rhs) 05881 { return !(__lhs == __rhs); } 05882 05883 // operator < 05884 /** 05885 * @brief Test if string precedes string. 05886 * @param __lhs First string. 05887 * @param __rhs Second string. 05888 * @return True if @a __lhs precedes @a __rhs. False otherwise. 05889 */ 05890 template<typename _CharT, typename _Traits, typename _Alloc> 05891 inline bool 05892 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05893 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05894 _GLIBCXX_NOEXCEPT 05895 { return __lhs.compare(__rhs) < 0; } 05896 05897 /** 05898 * @brief Test if string precedes C string. 05899 * @param __lhs String. 05900 * @param __rhs C string. 05901 * @return True if @a __lhs precedes @a __rhs. False otherwise. 05902 */ 05903 template<typename _CharT, typename _Traits, typename _Alloc> 05904 inline bool 05905 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05906 const _CharT* __rhs) 05907 { return __lhs.compare(__rhs) < 0; } 05908 05909 /** 05910 * @brief Test if C string precedes string. 05911 * @param __lhs C string. 05912 * @param __rhs String. 05913 * @return True if @a __lhs precedes @a __rhs. False otherwise. 05914 */ 05915 template<typename _CharT, typename _Traits, typename _Alloc> 05916 inline bool 05917 operator<(const _CharT* __lhs, 05918 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05919 { return __rhs.compare(__lhs) > 0; } 05920 05921 // operator > 05922 /** 05923 * @brief Test if string follows string. 05924 * @param __lhs First string. 05925 * @param __rhs Second string. 05926 * @return True if @a __lhs follows @a __rhs. False otherwise. 05927 */ 05928 template<typename _CharT, typename _Traits, typename _Alloc> 05929 inline bool 05930 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05931 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05932 _GLIBCXX_NOEXCEPT 05933 { return __lhs.compare(__rhs) > 0; } 05934 05935 /** 05936 * @brief Test if string follows C string. 05937 * @param __lhs String. 05938 * @param __rhs C string. 05939 * @return True if @a __lhs follows @a __rhs. False otherwise. 05940 */ 05941 template<typename _CharT, typename _Traits, typename _Alloc> 05942 inline bool 05943 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05944 const _CharT* __rhs) 05945 { return __lhs.compare(__rhs) > 0; } 05946 05947 /** 05948 * @brief Test if C string follows string. 05949 * @param __lhs C string. 05950 * @param __rhs String. 05951 * @return True if @a __lhs follows @a __rhs. False otherwise. 05952 */ 05953 template<typename _CharT, typename _Traits, typename _Alloc> 05954 inline bool 05955 operator>(const _CharT* __lhs, 05956 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05957 { return __rhs.compare(__lhs) < 0; } 05958 05959 // operator <= 05960 /** 05961 * @brief Test if string doesn't follow string. 05962 * @param __lhs First string. 05963 * @param __rhs Second string. 05964 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 05965 */ 05966 template<typename _CharT, typename _Traits, typename _Alloc> 05967 inline bool 05968 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05969 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05970 _GLIBCXX_NOEXCEPT 05971 { return __lhs.compare(__rhs) <= 0; } 05972 05973 /** 05974 * @brief Test if string doesn't follow C string. 05975 * @param __lhs String. 05976 * @param __rhs C string. 05977 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 05978 */ 05979 template<typename _CharT, typename _Traits, typename _Alloc> 05980 inline bool 05981 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 05982 const _CharT* __rhs) 05983 { return __lhs.compare(__rhs) <= 0; } 05984 05985 /** 05986 * @brief Test if C string doesn't follow string. 05987 * @param __lhs C string. 05988 * @param __rhs String. 05989 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 05990 */ 05991 template<typename _CharT, typename _Traits, typename _Alloc> 05992 inline bool 05993 operator<=(const _CharT* __lhs, 05994 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 05995 { return __rhs.compare(__lhs) >= 0; } 05996 05997 // operator >= 05998 /** 05999 * @brief Test if string doesn't precede string. 06000 * @param __lhs First string. 06001 * @param __rhs Second string. 06002 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 06003 */ 06004 template<typename _CharT, typename _Traits, typename _Alloc> 06005 inline bool 06006 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 06007 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 06008 _GLIBCXX_NOEXCEPT 06009 { return __lhs.compare(__rhs) >= 0; } 06010 06011 /** 06012 * @brief Test if string doesn't precede C string. 06013 * @param __lhs String. 06014 * @param __rhs C string. 06015 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 06016 */ 06017 template<typename _CharT, typename _Traits, typename _Alloc> 06018 inline bool 06019 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 06020 const _CharT* __rhs) 06021 { return __lhs.compare(__rhs) >= 0; } 06022 06023 /** 06024 * @brief Test if C string doesn't precede string. 06025 * @param __lhs C string. 06026 * @param __rhs String. 06027 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 06028 */ 06029 template<typename _CharT, typename _Traits, typename _Alloc> 06030 inline bool 06031 operator>=(const _CharT* __lhs, 06032 const basic_string<_CharT, _Traits, _Alloc>& __rhs) 06033 { return __rhs.compare(__lhs) <= 0; } 06034 06035 /** 06036 * @brief Swap contents of two strings. 06037 * @param __lhs First string. 06038 * @param __rhs Second string. 06039 * 06040 * Exchanges the contents of @a __lhs and @a __rhs in constant time. 06041 */ 06042 template<typename _CharT, typename _Traits, typename _Alloc> 06043 inline void 06044 swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, 06045 basic_string<_CharT, _Traits, _Alloc>& __rhs) 06046 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs))) 06047 { __lhs.swap(__rhs); } 06048 06049 06050 /** 06051 * @brief Read stream into a string. 06052 * @param __is Input stream. 06053 * @param __str Buffer to store into. 06054 * @return Reference to the input stream. 06055 * 06056 * Stores characters from @a __is into @a __str until whitespace is 06057 * found, the end of the stream is encountered, or str.max_size() 06058 * is reached. If is.width() is non-zero, that is the limit on the 06059 * number of characters stored into @a __str. Any previous 06060 * contents of @a __str are erased. 06061 */ 06062 template<typename _CharT, typename _Traits, typename _Alloc> 06063 basic_istream<_CharT, _Traits>& 06064 operator>>(basic_istream<_CharT, _Traits>& __is, 06065 basic_string<_CharT, _Traits, _Alloc>& __str); 06066 06067 template<> 06068 basic_istream<char>& 06069 operator>>(basic_istream<char>& __is, basic_string<char>& __str); 06070 06071 /** 06072 * @brief Write string to a stream. 06073 * @param __os Output stream. 06074 * @param __str String to write out. 06075 * @return Reference to the output stream. 06076 * 06077 * Output characters of @a __str into os following the same rules as for 06078 * writing a C string. 06079 */ 06080 template<typename _CharT, typename _Traits, typename _Alloc> 06081 inline basic_ostream<_CharT, _Traits>& 06082 operator<<(basic_ostream<_CharT, _Traits>& __os, 06083 const basic_string<_CharT, _Traits, _Alloc>& __str) 06084 { 06085 // _GLIBCXX_RESOLVE_LIB_DEFECTS 06086 // 586. string inserter not a formatted function 06087 return __ostream_insert(__os, __str.data(), __str.size()); 06088 } 06089 06090 /** 06091 * @brief Read a line from stream into a string. 06092 * @param __is Input stream. 06093 * @param __str Buffer to store into. 06094 * @param __delim Character marking end of line. 06095 * @return Reference to the input stream. 06096 * 06097 * Stores characters from @a __is into @a __str until @a __delim is 06098 * found, the end of the stream is encountered, or str.max_size() 06099 * is reached. Any previous contents of @a __str are erased. If 06100 * @a __delim is encountered, it is extracted but not stored into 06101 * @a __str. 06102 */ 06103 template<typename _CharT, typename _Traits, typename _Alloc> 06104 basic_istream<_CharT, _Traits>& 06105 getline(basic_istream<_CharT, _Traits>& __is, 06106 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim); 06107 06108 /** 06109 * @brief Read a line from stream into a string. 06110 * @param __is Input stream. 06111 * @param __str Buffer to store into. 06112 * @return Reference to the input stream. 06113 * 06114 * Stores characters from is into @a __str until '\n' is 06115 * found, the end of the stream is encountered, or str.max_size() 06116 * is reached. Any previous contents of @a __str are erased. If 06117 * end of line is encountered, it is extracted but not stored into 06118 * @a __str. 06119 */ 06120 template<typename _CharT, typename _Traits, typename _Alloc> 06121 inline basic_istream<_CharT, _Traits>& 06122 getline(basic_istream<_CharT, _Traits>& __is, 06123 basic_string<_CharT, _Traits, _Alloc>& __str) 06124 { return std::getline(__is, __str, __is.widen('\n')); } 06125 06126 #if __cplusplus >= 201103L 06127 /// Read a line from an rvalue stream into a string. 06128 template<typename _CharT, typename _Traits, typename _Alloc> 06129 inline basic_istream<_CharT, _Traits>& 06130 getline(basic_istream<_CharT, _Traits>&& __is, 06131 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim) 06132 { return std::getline(__is, __str, __delim); } 06133 06134 /// Read a line from an rvalue stream into a string. 06135 template<typename _CharT, typename _Traits, typename _Alloc> 06136 inline basic_istream<_CharT, _Traits>& 06137 getline(basic_istream<_CharT, _Traits>&& __is, 06138 basic_string<_CharT, _Traits, _Alloc>& __str) 06139 { return std::getline(__is, __str); } 06140 #endif 06141 06142 template<> 06143 basic_istream<char>& 06144 getline(basic_istream<char>& __in, basic_string<char>& __str, 06145 char __delim); 06146 06147 #ifdef _GLIBCXX_USE_WCHAR_T 06148 template<> 06149 basic_istream<wchar_t>& 06150 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str, 06151 wchar_t __delim); 06152 #endif 06153 06154 _GLIBCXX_END_NAMESPACE_VERSION 06155 } // namespace 06156 06157 #if __cplusplus >= 201103L 06158 06159 #include <ext/string_conversions.h> 06160 06161 namespace std _GLIBCXX_VISIBILITY(default) 06162 { 06163 _GLIBCXX_BEGIN_NAMESPACE_VERSION 06164 _GLIBCXX_BEGIN_NAMESPACE_CXX11 06165 06166 #if _GLIBCXX_USE_C99_STDLIB 06167 // 21.4 Numeric Conversions [string.conversions]. 06168 inline int 06169 stoi(const string& __str, size_t* __idx = 0, int __base = 10) 06170 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), 06171 __idx, __base); } 06172 06173 inline long 06174 stol(const string& __str, size_t* __idx = 0, int __base = 10) 06175 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), 06176 __idx, __base); } 06177 06178 inline unsigned long 06179 stoul(const string& __str, size_t* __idx = 0, int __base = 10) 06180 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), 06181 __idx, __base); } 06182 06183 inline long long 06184 stoll(const string& __str, size_t* __idx = 0, int __base = 10) 06185 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), 06186 __idx, __base); } 06187 06188 inline unsigned long long 06189 stoull(const string& __str, size_t* __idx = 0, int __base = 10) 06190 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), 06191 __idx, __base); } 06192 06193 // NB: strtof vs strtod. 06194 inline float 06195 stof(const string& __str, size_t* __idx = 0) 06196 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } 06197 06198 inline double 06199 stod(const string& __str, size_t* __idx = 0) 06200 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } 06201 06202 inline long double 06203 stold(const string& __str, size_t* __idx = 0) 06204 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } 06205 #endif // _GLIBCXX_USE_C99_STDLIB 06206 06207 #if _GLIBCXX_USE_C99_STDIO 06208 // NB: (v)snprintf vs sprintf. 06209 06210 // DR 1261. 06211 inline string 06212 to_string(int __val) 06213 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int), 06214 "%d", __val); } 06215 06216 inline string 06217 to_string(unsigned __val) 06218 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 06219 4 * sizeof(unsigned), 06220 "%u", __val); } 06221 06222 inline string 06223 to_string(long __val) 06224 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long), 06225 "%ld", __val); } 06226 06227 inline string 06228 to_string(unsigned long __val) 06229 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 06230 4 * sizeof(unsigned long), 06231 "%lu", __val); } 06232 06233 inline string 06234 to_string(long long __val) 06235 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 06236 4 * sizeof(long long), 06237 "%lld", __val); } 06238 06239 inline string 06240 to_string(unsigned long long __val) 06241 { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 06242 4 * sizeof(unsigned long long), 06243 "%llu", __val); } 06244 06245 inline string 06246 to_string(float __val) 06247 { 06248 const int __n = 06249 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; 06250 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, 06251 "%f", __val); 06252 } 06253 06254 inline string 06255 to_string(double __val) 06256 { 06257 const int __n = 06258 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; 06259 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, 06260 "%f", __val); 06261 } 06262 06263 inline string 06264 to_string(long double __val) 06265 { 06266 const int __n = 06267 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; 06268 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, 06269 "%Lf", __val); 06270 } 06271 #endif // _GLIBCXX_USE_C99_STDIO 06272 06273 #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR 06274 inline int 06275 stoi(const wstring& __str, size_t* __idx = 0, int __base = 10) 06276 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), 06277 __idx, __base); } 06278 06279 inline long 06280 stol(const wstring& __str, size_t* __idx = 0, int __base = 10) 06281 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), 06282 __idx, __base); } 06283 06284 inline unsigned long 06285 stoul(const wstring& __str, size_t* __idx = 0, int __base = 10) 06286 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), 06287 __idx, __base); } 06288 06289 inline long long 06290 stoll(const wstring& __str, size_t* __idx = 0, int __base = 10) 06291 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), 06292 __idx, __base); } 06293 06294 inline unsigned long long 06295 stoull(const wstring& __str, size_t* __idx = 0, int __base = 10) 06296 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), 06297 __idx, __base); } 06298 06299 // NB: wcstof vs wcstod. 06300 inline float 06301 stof(const wstring& __str, size_t* __idx = 0) 06302 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } 06303 06304 inline double 06305 stod(const wstring& __str, size_t* __idx = 0) 06306 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } 06307 06308 inline long double 06309 stold(const wstring& __str, size_t* __idx = 0) 06310 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } 06311 06312 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF 06313 // DR 1261. 06314 inline wstring 06315 to_wstring(int __val) 06316 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(int), 06317 L"%d", __val); } 06318 06319 inline wstring 06320 to_wstring(unsigned __val) 06321 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 06322 4 * sizeof(unsigned), 06323 L"%u", __val); } 06324 06325 inline wstring 06326 to_wstring(long __val) 06327 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long), 06328 L"%ld", __val); } 06329 06330 inline wstring 06331 to_wstring(unsigned long __val) 06332 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 06333 4 * sizeof(unsigned long), 06334 L"%lu", __val); } 06335 06336 inline wstring 06337 to_wstring(long long __val) 06338 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 06339 4 * sizeof(long long), 06340 L"%lld", __val); } 06341 06342 inline wstring 06343 to_wstring(unsigned long long __val) 06344 { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 06345 4 * sizeof(unsigned long long), 06346 L"%llu", __val); } 06347 06348 inline wstring 06349 to_wstring(float __val) 06350 { 06351 const int __n = 06352 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; 06353 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, 06354 L"%f", __val); 06355 } 06356 06357 inline wstring 06358 to_wstring(double __val) 06359 { 06360 const int __n = 06361 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; 06362 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, 06363 L"%f", __val); 06364 } 06365 06366 inline wstring 06367 to_wstring(long double __val) 06368 { 06369 const int __n = 06370 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; 06371 return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, 06372 L"%Lf", __val); 06373 } 06374 #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF 06375 #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR 06376 06377 _GLIBCXX_END_NAMESPACE_CXX11 06378 _GLIBCXX_END_NAMESPACE_VERSION 06379 } // namespace 06380 06381 #endif /* C++11 */ 06382 06383 #if __cplusplus >= 201103L 06384 06385 #include <bits/functional_hash.h> 06386 06387 namespace std _GLIBCXX_VISIBILITY(default) 06388 { 06389 _GLIBCXX_BEGIN_NAMESPACE_VERSION 06390 06391 // DR 1182. 06392 06393 #ifndef _GLIBCXX_COMPATIBILITY_CXX0X 06394 /// std::hash specialization for string. 06395 template<> 06396 struct hash<string> 06397 : public __hash_base<size_t, string> 06398 { 06399 size_t 06400 operator()(const string& __s) const noexcept 06401 { return std::_Hash_impl::hash(__s.data(), __s.length()); } 06402 }; 06403 06404 template<> 06405 struct __is_fast_hash<hash<string>> : std::false_type 06406 { }; 06407 06408 #ifdef _GLIBCXX_USE_WCHAR_T 06409 /// std::hash specialization for wstring. 06410 template<> 06411 struct hash<wstring> 06412 : public __hash_base<size_t, wstring> 06413 { 06414 size_t 06415 operator()(const wstring& __s) const noexcept 06416 { return std::_Hash_impl::hash(__s.data(), 06417 __s.length() * sizeof(wchar_t)); } 06418 }; 06419 06420 template<> 06421 struct __is_fast_hash<hash<wstring>> : std::false_type 06422 { }; 06423 #endif 06424 #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */ 06425 06426 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 06427 /// std::hash specialization for u16string. 06428 template<> 06429 struct hash<u16string> 06430 : public __hash_base<size_t, u16string> 06431 { 06432 size_t 06433 operator()(const u16string& __s) const noexcept 06434 { return std::_Hash_impl::hash(__s.data(), 06435 __s.length() * sizeof(char16_t)); } 06436 }; 06437 06438 template<> 06439 struct __is_fast_hash<hash<u16string>> : std::false_type 06440 { }; 06441 06442 /// std::hash specialization for u32string. 06443 template<> 06444 struct hash<u32string> 06445 : public __hash_base<size_t, u32string> 06446 { 06447 size_t 06448 operator()(const u32string& __s) const noexcept 06449 { return std::_Hash_impl::hash(__s.data(), 06450 __s.length() * sizeof(char32_t)); } 06451 }; 06452 06453 template<> 06454 struct __is_fast_hash<hash<u32string>> : std::false_type 06455 { }; 06456 #endif 06457 06458 _GLIBCXX_END_NAMESPACE_VERSION 06459 06460 #if __cplusplus > 201103L 06461 06462 #define __cpp_lib_string_udls 201304 06463 06464 inline namespace literals 06465 { 06466 inline namespace string_literals 06467 { 06468 _GLIBCXX_BEGIN_NAMESPACE_VERSION 06469 06470 _GLIBCXX_DEFAULT_ABI_TAG 06471 inline basic_string<char> 06472 operator""s(const char* __str, size_t __len) 06473 { return basic_string<char>{__str, __len}; } 06474 06475 #ifdef _GLIBCXX_USE_WCHAR_T 06476 _GLIBCXX_DEFAULT_ABI_TAG 06477 inline basic_string<wchar_t> 06478 operator""s(const wchar_t* __str, size_t __len) 06479 { return basic_string<wchar_t>{__str, __len}; } 06480 #endif 06481 06482 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 06483 _GLIBCXX_DEFAULT_ABI_TAG 06484 inline basic_string<char16_t> 06485 operator""s(const char16_t* __str, size_t __len) 06486 { return basic_string<char16_t>{__str, __len}; } 06487 06488 _GLIBCXX_DEFAULT_ABI_TAG 06489 inline basic_string<char32_t> 06490 operator""s(const char32_t* __str, size_t __len) 06491 { return basic_string<char32_t>{__str, __len}; } 06492 #endif 06493 06494 _GLIBCXX_END_NAMESPACE_VERSION 06495 } // inline namespace string_literals 06496 } // inline namespace literals 06497 06498 #endif // __cplusplus > 201103L 06499 06500 } // namespace std 06501 06502 #endif // C++11 06503 06504 #endif /* _BASIC_STRING_H */