1e4b17023SJohn Marino // Components for manipulating sequences of characters -*- C++ -*- 2e4b17023SJohn Marino 3e4b17023SJohn Marino // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 4e4b17023SJohn Marino // 2006, 2007, 2008, 2009, 2010, 2011 5e4b17023SJohn Marino // Free Software Foundation, Inc. 6e4b17023SJohn Marino // 7e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library. This library is free 8e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the 9e4b17023SJohn Marino // terms of the GNU General Public License as published by the 10e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option) 11e4b17023SJohn Marino // any later version. 12e4b17023SJohn Marino 13e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, 14e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of 15e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16e4b17023SJohn Marino // GNU General Public License for more details. 17e4b17023SJohn Marino 18e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional 19e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version 20e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation. 21e4b17023SJohn Marino 22e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and 23e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program; 24e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 25e4b17023SJohn Marino // <http://www.gnu.org/licenses/>. 26e4b17023SJohn Marino 27e4b17023SJohn Marino /** @file bits/basic_string.h 28e4b17023SJohn Marino * This is an internal header file, included by other library headers. 29e4b17023SJohn Marino * Do not attempt to use it directly. @headername{string} 30e4b17023SJohn Marino */ 31e4b17023SJohn Marino 32e4b17023SJohn Marino // 33e4b17023SJohn Marino // ISO C++ 14882: 21 Strings library 34e4b17023SJohn Marino // 35e4b17023SJohn Marino 36e4b17023SJohn Marino #ifndef _BASIC_STRING_H 37e4b17023SJohn Marino #define _BASIC_STRING_H 1 38e4b17023SJohn Marino 39e4b17023SJohn Marino #pragma GCC system_header 40e4b17023SJohn Marino 41e4b17023SJohn Marino #include <ext/atomicity.h> 42e4b17023SJohn Marino #include <debug/debug.h> 43e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 44e4b17023SJohn Marino #include <initializer_list> 45e4b17023SJohn Marino #endif 46e4b17023SJohn Marino 47e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 48e4b17023SJohn Marino { 49e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 50e4b17023SJohn Marino 51e4b17023SJohn Marino /** 52e4b17023SJohn Marino * @class basic_string basic_string.h <string> 53e4b17023SJohn Marino * @brief Managing sequences of characters and character-like objects. 54e4b17023SJohn Marino * 55e4b17023SJohn Marino * @ingroup strings 56e4b17023SJohn Marino * @ingroup sequences 57e4b17023SJohn Marino * 58e4b17023SJohn Marino * Meets the requirements of a <a href="tables.html#65">container</a>, a 59e4b17023SJohn Marino * <a href="tables.html#66">reversible container</a>, and a 60e4b17023SJohn Marino * <a href="tables.html#67">sequence</a>. Of the 61e4b17023SJohn Marino * <a href="tables.html#68">optional sequence requirements</a>, only 62e4b17023SJohn Marino * @c push_back, @c at, and @c %array access are supported. 63e4b17023SJohn Marino * 64e4b17023SJohn Marino * @doctodo 65e4b17023SJohn Marino * 66e4b17023SJohn Marino * 67e4b17023SJohn Marino * Documentation? What's that? 68e4b17023SJohn Marino * Nathan Myers <ncm@cantrip.org>. 69e4b17023SJohn Marino * 70e4b17023SJohn Marino * A string looks like this: 71e4b17023SJohn Marino * 72e4b17023SJohn Marino * @code 73e4b17023SJohn Marino * [_Rep] 74e4b17023SJohn Marino * _M_length 75e4b17023SJohn Marino * [basic_string<char_type>] _M_capacity 76e4b17023SJohn Marino * _M_dataplus _M_refcount 77e4b17023SJohn Marino * _M_p ----------------> unnamed array of char_type 78e4b17023SJohn Marino * @endcode 79e4b17023SJohn Marino * 80e4b17023SJohn Marino * Where the _M_p points to the first character in the string, and 81e4b17023SJohn Marino * you cast it to a pointer-to-_Rep and subtract 1 to get a 82e4b17023SJohn Marino * pointer to the header. 83e4b17023SJohn Marino * 84e4b17023SJohn Marino * This approach has the enormous advantage that a string object 85e4b17023SJohn Marino * requires only one allocation. All the ugliness is confined 86e4b17023SJohn Marino * within a single %pair of inline functions, which each compile to 87e4b17023SJohn Marino * a single @a add instruction: _Rep::_M_data(), and 88e4b17023SJohn Marino * string::_M_rep(); and the allocation function which gets a 89e4b17023SJohn Marino * block of raw bytes and with room enough and constructs a _Rep 90e4b17023SJohn Marino * object at the front. 91e4b17023SJohn Marino * 92e4b17023SJohn Marino * The reason you want _M_data pointing to the character %array and 93e4b17023SJohn Marino * not the _Rep is so that the debugger can see the string 94e4b17023SJohn Marino * contents. (Probably we should add a non-inline member to get 95e4b17023SJohn Marino * the _Rep for the debugger to use, so users can check the actual 96e4b17023SJohn Marino * string length.) 97e4b17023SJohn Marino * 98e4b17023SJohn Marino * Note that the _Rep object is a POD so that you can have a 99e4b17023SJohn Marino * static <em>empty string</em> _Rep object already @a constructed before 100e4b17023SJohn Marino * static constructors have run. The reference-count encoding is 101e4b17023SJohn Marino * chosen so that a 0 indicates one reference, so you never try to 102e4b17023SJohn Marino * destroy the empty-string _Rep object. 103e4b17023SJohn Marino * 104e4b17023SJohn Marino * All but the last paragraph is considered pretty conventional 105e4b17023SJohn Marino * for a C++ string implementation. 106e4b17023SJohn Marino */ 107e4b17023SJohn Marino // 21.3 Template class basic_string 108e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 109e4b17023SJohn Marino class basic_string 110e4b17023SJohn Marino { 111e4b17023SJohn Marino typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; 112e4b17023SJohn Marino 113e4b17023SJohn Marino // Types: 114e4b17023SJohn Marino public: 115e4b17023SJohn Marino typedef _Traits traits_type; 116e4b17023SJohn Marino typedef typename _Traits::char_type value_type; 117e4b17023SJohn Marino typedef _Alloc allocator_type; 118e4b17023SJohn Marino typedef typename _CharT_alloc_type::size_type size_type; 119e4b17023SJohn Marino typedef typename _CharT_alloc_type::difference_type difference_type; 120e4b17023SJohn Marino typedef typename _CharT_alloc_type::reference reference; 121e4b17023SJohn Marino typedef typename _CharT_alloc_type::const_reference const_reference; 122e4b17023SJohn Marino typedef typename _CharT_alloc_type::pointer pointer; 123e4b17023SJohn Marino typedef typename _CharT_alloc_type::const_pointer const_pointer; 124e4b17023SJohn Marino typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; 125e4b17023SJohn Marino typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> 126e4b17023SJohn Marino const_iterator; 127e4b17023SJohn Marino typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 128e4b17023SJohn Marino typedef std::reverse_iterator<iterator> reverse_iterator; 129e4b17023SJohn Marino 130e4b17023SJohn Marino private: 131e4b17023SJohn Marino // _Rep: string representation 132e4b17023SJohn Marino // Invariants: 133e4b17023SJohn Marino // 1. String really contains _M_length + 1 characters: due to 21.3.4 134e4b17023SJohn Marino // must be kept null-terminated. 135e4b17023SJohn Marino // 2. _M_capacity >= _M_length 136e4b17023SJohn Marino // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT). 137e4b17023SJohn Marino // 3. _M_refcount has three states: 138e4b17023SJohn Marino // -1: leaked, one reference, no ref-copies allowed, non-const. 139e4b17023SJohn Marino // 0: one reference, non-const. 140e4b17023SJohn Marino // n>0: n + 1 references, operations require a lock, const. 141e4b17023SJohn Marino // 4. All fields==0 is an empty string, given the extra storage 142e4b17023SJohn Marino // beyond-the-end for a null terminator; thus, the shared 143e4b17023SJohn Marino // empty string representation needs no constructor. 144e4b17023SJohn Marino 145e4b17023SJohn Marino struct _Rep_base 146e4b17023SJohn Marino { 147e4b17023SJohn Marino size_type _M_length; 148e4b17023SJohn Marino size_type _M_capacity; 149e4b17023SJohn Marino _Atomic_word _M_refcount; 150e4b17023SJohn Marino }; 151e4b17023SJohn Marino 152e4b17023SJohn Marino struct _Rep : _Rep_base 153e4b17023SJohn Marino { 154e4b17023SJohn Marino // Types: 155e4b17023SJohn Marino typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc; 156e4b17023SJohn Marino 157e4b17023SJohn Marino // (Public) Data members: 158e4b17023SJohn Marino 159e4b17023SJohn Marino // The maximum number of individual char_type elements of an 160e4b17023SJohn Marino // individual string is determined by _S_max_size. This is the 161e4b17023SJohn Marino // value that will be returned by max_size(). (Whereas npos 162e4b17023SJohn Marino // is the maximum number of bytes the allocator can allocate.) 163e4b17023SJohn Marino // If one was to divvy up the theoretical largest size string, 164e4b17023SJohn Marino // with a terminating character and m _CharT elements, it'd 165e4b17023SJohn Marino // look like this: 166e4b17023SJohn Marino // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT) 167e4b17023SJohn Marino // Solving for m: 168e4b17023SJohn Marino // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1 169e4b17023SJohn Marino // In addition, this implementation quarters this amount. 170e4b17023SJohn Marino static const size_type _S_max_size; 171e4b17023SJohn Marino static const _CharT _S_terminal; 172e4b17023SJohn Marino 173e4b17023SJohn Marino // The following storage is init'd to 0 by the linker, resulting 174e4b17023SJohn Marino // (carefully) in an empty string with one reference. 175e4b17023SJohn Marino static size_type _S_empty_rep_storage[]; 176e4b17023SJohn Marino 177e4b17023SJohn Marino static _Rep& 178e4b17023SJohn Marino _S_empty_rep() 179e4b17023SJohn Marino { 180e4b17023SJohn Marino // NB: Mild hack to avoid strict-aliasing warnings. Note that 181e4b17023SJohn Marino // _S_empty_rep_storage is never modified and the punning should 182e4b17023SJohn Marino // be reasonably safe in this case. 183e4b17023SJohn Marino void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage); 184e4b17023SJohn Marino return *reinterpret_cast<_Rep*>(__p); 185e4b17023SJohn Marino } 186e4b17023SJohn Marino 187e4b17023SJohn Marino bool 188e4b17023SJohn Marino _M_is_leaked() const 189e4b17023SJohn Marino { return this->_M_refcount < 0; } 190e4b17023SJohn Marino 191e4b17023SJohn Marino bool 192e4b17023SJohn Marino _M_is_shared() const 193e4b17023SJohn Marino { return this->_M_refcount > 0; } 194e4b17023SJohn Marino 195e4b17023SJohn Marino void 196e4b17023SJohn Marino _M_set_leaked() 197e4b17023SJohn Marino { this->_M_refcount = -1; } 198e4b17023SJohn Marino 199e4b17023SJohn Marino void 200e4b17023SJohn Marino _M_set_sharable() 201e4b17023SJohn Marino { this->_M_refcount = 0; } 202e4b17023SJohn Marino 203e4b17023SJohn Marino void 204e4b17023SJohn Marino _M_set_length_and_sharable(size_type __n) 205e4b17023SJohn Marino { 206e4b17023SJohn Marino #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 207e4b17023SJohn Marino if (__builtin_expect(this != &_S_empty_rep(), false)) 208e4b17023SJohn Marino #endif 209e4b17023SJohn Marino { 210e4b17023SJohn Marino this->_M_set_sharable(); // One reference. 211e4b17023SJohn Marino this->_M_length = __n; 212e4b17023SJohn Marino traits_type::assign(this->_M_refdata()[__n], _S_terminal); 213e4b17023SJohn Marino // grrr. (per 21.3.4) 214e4b17023SJohn Marino // You cannot leave those LWG people alone for a second. 215e4b17023SJohn Marino } 216e4b17023SJohn Marino } 217e4b17023SJohn Marino 218e4b17023SJohn Marino _CharT* 219e4b17023SJohn Marino _M_refdata() throw() 220e4b17023SJohn Marino { return reinterpret_cast<_CharT*>(this + 1); } 221e4b17023SJohn Marino 222e4b17023SJohn Marino _CharT* 223e4b17023SJohn Marino _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2) 224e4b17023SJohn Marino { 225e4b17023SJohn Marino return (!_M_is_leaked() && __alloc1 == __alloc2) 226e4b17023SJohn Marino ? _M_refcopy() : _M_clone(__alloc1); 227e4b17023SJohn Marino } 228e4b17023SJohn Marino 229e4b17023SJohn Marino // Create & Destroy 230e4b17023SJohn Marino static _Rep* 231e4b17023SJohn Marino _S_create(size_type, size_type, const _Alloc&); 232e4b17023SJohn Marino 233e4b17023SJohn Marino void 234e4b17023SJohn Marino _M_dispose(const _Alloc& __a) 235e4b17023SJohn Marino { 236e4b17023SJohn Marino #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 237e4b17023SJohn Marino if (__builtin_expect(this != &_S_empty_rep(), false)) 238e4b17023SJohn Marino #endif 239e4b17023SJohn Marino { 240e4b17023SJohn Marino // Be race-detector-friendly. For more info see bits/c++config. 241e4b17023SJohn Marino _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount); 242e4b17023SJohn Marino if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, 243e4b17023SJohn Marino -1) <= 0) 244e4b17023SJohn Marino { 245e4b17023SJohn Marino _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount); 246e4b17023SJohn Marino _M_destroy(__a); 247e4b17023SJohn Marino } 248e4b17023SJohn Marino } 249e4b17023SJohn Marino } // XXX MT 250e4b17023SJohn Marino 251e4b17023SJohn Marino void 252e4b17023SJohn Marino _M_destroy(const _Alloc&) throw(); 253e4b17023SJohn Marino 254e4b17023SJohn Marino _CharT* 255e4b17023SJohn Marino _M_refcopy() throw() 256e4b17023SJohn Marino { 257e4b17023SJohn Marino #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 258e4b17023SJohn Marino if (__builtin_expect(this != &_S_empty_rep(), false)) 259e4b17023SJohn Marino #endif 260e4b17023SJohn Marino __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1); 261e4b17023SJohn Marino return _M_refdata(); 262e4b17023SJohn Marino } // XXX MT 263e4b17023SJohn Marino 264e4b17023SJohn Marino _CharT* 265e4b17023SJohn Marino _M_clone(const _Alloc&, size_type __res = 0); 266e4b17023SJohn Marino }; 267e4b17023SJohn Marino 268e4b17023SJohn Marino // Use empty-base optimization: http://www.cantrip.org/emptyopt.html 269e4b17023SJohn Marino struct _Alloc_hider : _Alloc 270e4b17023SJohn Marino { 271e4b17023SJohn Marino _Alloc_hider(_CharT* __dat, const _Alloc& __a) 272e4b17023SJohn Marino : _Alloc(__a), _M_p(__dat) { } 273e4b17023SJohn Marino 274e4b17023SJohn Marino _CharT* _M_p; // The actual data. 275e4b17023SJohn Marino }; 276e4b17023SJohn Marino 277e4b17023SJohn Marino public: 278e4b17023SJohn Marino // Data Members (public): 279e4b17023SJohn Marino // NB: This is an unsigned type, and thus represents the maximum 280e4b17023SJohn Marino // size that the allocator can hold. 281e4b17023SJohn Marino /// Value returned by various member functions when they fail. 282e4b17023SJohn Marino static const size_type npos = static_cast<size_type>(-1); 283e4b17023SJohn Marino 284e4b17023SJohn Marino private: 285e4b17023SJohn Marino // Data Members (private): 286e4b17023SJohn Marino mutable _Alloc_hider _M_dataplus; 287e4b17023SJohn Marino 288e4b17023SJohn Marino _CharT* 289e4b17023SJohn Marino _M_data() const 290e4b17023SJohn Marino { return _M_dataplus._M_p; } 291e4b17023SJohn Marino 292e4b17023SJohn Marino _CharT* 293e4b17023SJohn Marino _M_data(_CharT* __p) 294e4b17023SJohn Marino { return (_M_dataplus._M_p = __p); } 295e4b17023SJohn Marino 296e4b17023SJohn Marino _Rep* 297e4b17023SJohn Marino _M_rep() const 298e4b17023SJohn Marino { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); } 299e4b17023SJohn Marino 300e4b17023SJohn Marino // For the internal use we have functions similar to `begin'/`end' 301e4b17023SJohn Marino // but they do not call _M_leak. 302e4b17023SJohn Marino iterator 303e4b17023SJohn Marino _M_ibegin() const 304e4b17023SJohn Marino { return iterator(_M_data()); } 305e4b17023SJohn Marino 306e4b17023SJohn Marino iterator 307e4b17023SJohn Marino _M_iend() const 308e4b17023SJohn Marino { return iterator(_M_data() + this->size()); } 309e4b17023SJohn Marino 310e4b17023SJohn Marino void 311e4b17023SJohn Marino _M_leak() // for use in begin() & non-const op[] 312e4b17023SJohn Marino { 313e4b17023SJohn Marino if (!_M_rep()->_M_is_leaked()) 314e4b17023SJohn Marino _M_leak_hard(); 315e4b17023SJohn Marino } 316e4b17023SJohn Marino 317e4b17023SJohn Marino size_type 318e4b17023SJohn Marino _M_check(size_type __pos, const char* __s) const 319e4b17023SJohn Marino { 320e4b17023SJohn Marino if (__pos > this->size()) 321e4b17023SJohn Marino __throw_out_of_range(__N(__s)); 322e4b17023SJohn Marino return __pos; 323e4b17023SJohn Marino } 324e4b17023SJohn Marino 325e4b17023SJohn Marino void 326e4b17023SJohn Marino _M_check_length(size_type __n1, size_type __n2, const char* __s) const 327e4b17023SJohn Marino { 328e4b17023SJohn Marino if (this->max_size() - (this->size() - __n1) < __n2) 329e4b17023SJohn Marino __throw_length_error(__N(__s)); 330e4b17023SJohn Marino } 331e4b17023SJohn Marino 332e4b17023SJohn Marino // NB: _M_limit doesn't check for a bad __pos value. 333e4b17023SJohn Marino size_type 334e4b17023SJohn Marino _M_limit(size_type __pos, size_type __off) const 335e4b17023SJohn Marino { 336e4b17023SJohn Marino const bool __testoff = __off < this->size() - __pos; 337e4b17023SJohn Marino return __testoff ? __off : this->size() - __pos; 338e4b17023SJohn Marino } 339e4b17023SJohn Marino 340e4b17023SJohn Marino // True if _Rep and source do not overlap. 341e4b17023SJohn Marino bool 342e4b17023SJohn Marino _M_disjunct(const _CharT* __s) const 343e4b17023SJohn Marino { 344e4b17023SJohn Marino return (less<const _CharT*>()(__s, _M_data()) 345e4b17023SJohn Marino || less<const _CharT*>()(_M_data() + this->size(), __s)); 346e4b17023SJohn Marino } 347e4b17023SJohn Marino 348e4b17023SJohn Marino // When __n = 1 way faster than the general multichar 349e4b17023SJohn Marino // traits_type::copy/move/assign. 350e4b17023SJohn Marino static void 351e4b17023SJohn Marino _M_copy(_CharT* __d, const _CharT* __s, size_type __n) 352e4b17023SJohn Marino { 353e4b17023SJohn Marino if (__n == 1) 354e4b17023SJohn Marino traits_type::assign(*__d, *__s); 355e4b17023SJohn Marino else 356e4b17023SJohn Marino traits_type::copy(__d, __s, __n); 357e4b17023SJohn Marino } 358e4b17023SJohn Marino 359e4b17023SJohn Marino static void 360e4b17023SJohn Marino _M_move(_CharT* __d, const _CharT* __s, size_type __n) 361e4b17023SJohn Marino { 362e4b17023SJohn Marino if (__n == 1) 363e4b17023SJohn Marino traits_type::assign(*__d, *__s); 364e4b17023SJohn Marino else 365e4b17023SJohn Marino traits_type::move(__d, __s, __n); 366e4b17023SJohn Marino } 367e4b17023SJohn Marino 368e4b17023SJohn Marino static void 369e4b17023SJohn Marino _M_assign(_CharT* __d, size_type __n, _CharT __c) 370e4b17023SJohn Marino { 371e4b17023SJohn Marino if (__n == 1) 372e4b17023SJohn Marino traits_type::assign(*__d, __c); 373e4b17023SJohn Marino else 374e4b17023SJohn Marino traits_type::assign(__d, __n, __c); 375e4b17023SJohn Marino } 376e4b17023SJohn Marino 377e4b17023SJohn Marino // _S_copy_chars is a separate template to permit specialization 378e4b17023SJohn Marino // to optimize for the common case of pointers as iterators. 379e4b17023SJohn Marino template<class _Iterator> 380e4b17023SJohn Marino static void 381e4b17023SJohn Marino _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) 382e4b17023SJohn Marino { 383e4b17023SJohn Marino for (; __k1 != __k2; ++__k1, ++__p) 384e4b17023SJohn Marino traits_type::assign(*__p, *__k1); // These types are off. 385e4b17023SJohn Marino } 386e4b17023SJohn Marino 387e4b17023SJohn Marino static void 388e4b17023SJohn Marino _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) 389e4b17023SJohn Marino { _S_copy_chars(__p, __k1.base(), __k2.base()); } 390e4b17023SJohn Marino 391e4b17023SJohn Marino static void 392e4b17023SJohn Marino _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) 393e4b17023SJohn Marino { _S_copy_chars(__p, __k1.base(), __k2.base()); } 394e4b17023SJohn Marino 395e4b17023SJohn Marino static void 396e4b17023SJohn Marino _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) 397e4b17023SJohn Marino { _M_copy(__p, __k1, __k2 - __k1); } 398e4b17023SJohn Marino 399e4b17023SJohn Marino static void 400e4b17023SJohn Marino _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) 401e4b17023SJohn Marino { _M_copy(__p, __k1, __k2 - __k1); } 402e4b17023SJohn Marino 403e4b17023SJohn Marino static int 404e4b17023SJohn Marino _S_compare(size_type __n1, size_type __n2) 405e4b17023SJohn Marino { 406e4b17023SJohn Marino const difference_type __d = difference_type(__n1 - __n2); 407e4b17023SJohn Marino 408e4b17023SJohn Marino if (__d > __gnu_cxx::__numeric_traits<int>::__max) 409e4b17023SJohn Marino return __gnu_cxx::__numeric_traits<int>::__max; 410e4b17023SJohn Marino else if (__d < __gnu_cxx::__numeric_traits<int>::__min) 411e4b17023SJohn Marino return __gnu_cxx::__numeric_traits<int>::__min; 412e4b17023SJohn Marino else 413e4b17023SJohn Marino return int(__d); 414e4b17023SJohn Marino } 415e4b17023SJohn Marino 416e4b17023SJohn Marino void 417e4b17023SJohn Marino _M_mutate(size_type __pos, size_type __len1, size_type __len2); 418e4b17023SJohn Marino 419e4b17023SJohn Marino void 420e4b17023SJohn Marino _M_leak_hard(); 421e4b17023SJohn Marino 422e4b17023SJohn Marino static _Rep& 423e4b17023SJohn Marino _S_empty_rep() 424e4b17023SJohn Marino { return _Rep::_S_empty_rep(); } 425e4b17023SJohn Marino 426e4b17023SJohn Marino public: 427e4b17023SJohn Marino // Construct/copy/destroy: 428e4b17023SJohn Marino // NB: We overload ctors in some cases instead of using default 429e4b17023SJohn Marino // arguments, per 17.4.4.4 para. 2 item 2. 430e4b17023SJohn Marino 431e4b17023SJohn Marino /** 432e4b17023SJohn Marino * @brief Default constructor creates an empty string. 433e4b17023SJohn Marino */ 434e4b17023SJohn Marino basic_string() 435e4b17023SJohn Marino #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 436e4b17023SJohn Marino : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) { } 437e4b17023SJohn Marino #else 438e4b17023SJohn Marino : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()){ } 439e4b17023SJohn Marino #endif 440e4b17023SJohn Marino 441e4b17023SJohn Marino /** 442e4b17023SJohn Marino * @brief Construct an empty string using allocator @a a. 443e4b17023SJohn Marino */ 444e4b17023SJohn Marino explicit 445e4b17023SJohn Marino basic_string(const _Alloc& __a); 446e4b17023SJohn Marino 447e4b17023SJohn Marino // NB: per LWG issue 42, semantics different from IS: 448e4b17023SJohn Marino /** 449e4b17023SJohn Marino * @brief Construct string with copy of value of @a str. 450e4b17023SJohn Marino * @param __str Source string. 451e4b17023SJohn Marino */ 452e4b17023SJohn Marino basic_string(const basic_string& __str); 453e4b17023SJohn Marino /** 454e4b17023SJohn Marino * @brief Construct string as copy of a substring. 455e4b17023SJohn Marino * @param __str Source string. 456e4b17023SJohn Marino * @param __pos Index of first character to copy from. 457e4b17023SJohn Marino * @param __n Number of characters to copy (default remainder). 458e4b17023SJohn Marino */ 459e4b17023SJohn Marino basic_string(const basic_string& __str, size_type __pos, 460e4b17023SJohn Marino size_type __n = npos); 461e4b17023SJohn Marino /** 462e4b17023SJohn Marino * @brief Construct string as copy of a substring. 463e4b17023SJohn Marino * @param __str Source string. 464e4b17023SJohn Marino * @param __pos Index of first character to copy from. 465e4b17023SJohn Marino * @param __n Number of characters to copy. 466e4b17023SJohn Marino * @param __a Allocator to use. 467e4b17023SJohn Marino */ 468e4b17023SJohn Marino basic_string(const basic_string& __str, size_type __pos, 469e4b17023SJohn Marino size_type __n, const _Alloc& __a); 470e4b17023SJohn Marino 471e4b17023SJohn Marino /** 472e4b17023SJohn Marino * @brief Construct string initialized by a character %array. 473e4b17023SJohn Marino * @param __s Source character %array. 474e4b17023SJohn Marino * @param __n Number of characters to copy. 475e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator). 476e4b17023SJohn Marino * 477e4b17023SJohn Marino * NB: @a __s must have at least @a __n characters, '\\0' 478e4b17023SJohn Marino * has no special meaning. 479e4b17023SJohn Marino */ 480e4b17023SJohn Marino basic_string(const _CharT* __s, size_type __n, 481e4b17023SJohn Marino const _Alloc& __a = _Alloc()); 482e4b17023SJohn Marino /** 483e4b17023SJohn Marino * @brief Construct string as copy of a C string. 484e4b17023SJohn Marino * @param __s Source C string. 485e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator). 486e4b17023SJohn Marino */ 487e4b17023SJohn Marino basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()); 488e4b17023SJohn Marino /** 489e4b17023SJohn Marino * @brief Construct string as multiple characters. 490e4b17023SJohn Marino * @param __n Number of characters. 491e4b17023SJohn Marino * @param __c Character to use. 492e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator). 493e4b17023SJohn Marino */ 494e4b17023SJohn Marino basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()); 495e4b17023SJohn Marino 496e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 497e4b17023SJohn Marino /** 498e4b17023SJohn Marino * @brief Move construct string. 499e4b17023SJohn Marino * @param __str Source string. 500e4b17023SJohn Marino * 501e4b17023SJohn Marino * The newly-created string contains the exact contents of @a __str. 502e4b17023SJohn Marino * @a __str is a valid, but unspecified string. 503e4b17023SJohn Marino **/ 504e4b17023SJohn Marino basic_string(basic_string&& __str) noexcept 505e4b17023SJohn Marino : _M_dataplus(__str._M_dataplus) 506e4b17023SJohn Marino { 507e4b17023SJohn Marino #if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 508e4b17023SJohn Marino __str._M_data(_S_empty_rep()._M_refdata()); 509e4b17023SJohn Marino #else 510e4b17023SJohn Marino __str._M_data(_S_construct(size_type(), _CharT(), get_allocator())); 511e4b17023SJohn Marino #endif 512e4b17023SJohn Marino } 513e4b17023SJohn Marino 514e4b17023SJohn Marino /** 515e4b17023SJohn Marino * @brief Construct string from an initializer %list. 516e4b17023SJohn Marino * @param __l std::initializer_list of characters. 517e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator). 518e4b17023SJohn Marino */ 519e4b17023SJohn Marino basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()); 520e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__ 521e4b17023SJohn Marino 522e4b17023SJohn Marino /** 523e4b17023SJohn Marino * @brief Construct string as copy of a range. 524e4b17023SJohn Marino * @param __beg Start of range. 525e4b17023SJohn Marino * @param __end End of range. 526e4b17023SJohn Marino * @param __a Allocator to use (default is default allocator). 527e4b17023SJohn Marino */ 528e4b17023SJohn Marino template<class _InputIterator> 529e4b17023SJohn Marino basic_string(_InputIterator __beg, _InputIterator __end, 530e4b17023SJohn Marino const _Alloc& __a = _Alloc()); 531e4b17023SJohn Marino 532e4b17023SJohn Marino /** 533e4b17023SJohn Marino * @brief Destroy the string instance. 534e4b17023SJohn Marino */ 535e4b17023SJohn Marino ~basic_string() _GLIBCXX_NOEXCEPT 536e4b17023SJohn Marino { _M_rep()->_M_dispose(this->get_allocator()); } 537e4b17023SJohn Marino 538e4b17023SJohn Marino /** 539e4b17023SJohn Marino * @brief Assign the value of @a str to this string. 540e4b17023SJohn Marino * @param __str Source string. 541e4b17023SJohn Marino */ 542e4b17023SJohn Marino basic_string& 543e4b17023SJohn Marino operator=(const basic_string& __str) 544e4b17023SJohn Marino { return this->assign(__str); } 545e4b17023SJohn Marino 546e4b17023SJohn Marino /** 547e4b17023SJohn Marino * @brief Copy contents of @a s into this string. 548e4b17023SJohn Marino * @param __s Source null-terminated string. 549e4b17023SJohn Marino */ 550e4b17023SJohn Marino basic_string& 551e4b17023SJohn Marino operator=(const _CharT* __s) 552e4b17023SJohn Marino { return this->assign(__s); } 553e4b17023SJohn Marino 554e4b17023SJohn Marino /** 555e4b17023SJohn Marino * @brief Set value to string of length 1. 556e4b17023SJohn Marino * @param __c Source character. 557e4b17023SJohn Marino * 558e4b17023SJohn Marino * Assigning to a character makes this string length 1 and 559e4b17023SJohn Marino * (*this)[0] == @a c. 560e4b17023SJohn Marino */ 561e4b17023SJohn Marino basic_string& 562e4b17023SJohn Marino operator=(_CharT __c) 563e4b17023SJohn Marino { 564e4b17023SJohn Marino this->assign(1, __c); 565e4b17023SJohn Marino return *this; 566e4b17023SJohn Marino } 567e4b17023SJohn Marino 568e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 569e4b17023SJohn Marino /** 570e4b17023SJohn Marino * @brief Move assign the value of @a str to this string. 571e4b17023SJohn Marino * @param __str Source string. 572e4b17023SJohn Marino * 573e4b17023SJohn Marino * The contents of @a str are moved into this string (without copying). 574e4b17023SJohn Marino * @a str is a valid, but unspecified string. 575e4b17023SJohn Marino **/ 576e4b17023SJohn Marino basic_string& 577e4b17023SJohn Marino operator=(basic_string&& __str) 578e4b17023SJohn Marino { 579e4b17023SJohn Marino // NB: DR 1204. 580e4b17023SJohn Marino this->swap(__str); 581e4b17023SJohn Marino return *this; 582e4b17023SJohn Marino } 583e4b17023SJohn Marino 584e4b17023SJohn Marino /** 585e4b17023SJohn Marino * @brief Set value to string constructed from initializer %list. 586e4b17023SJohn Marino * @param __l std::initializer_list. 587e4b17023SJohn Marino */ 588e4b17023SJohn Marino basic_string& 589e4b17023SJohn Marino operator=(initializer_list<_CharT> __l) 590e4b17023SJohn Marino { 591e4b17023SJohn Marino this->assign(__l.begin(), __l.size()); 592e4b17023SJohn Marino return *this; 593e4b17023SJohn Marino } 594e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__ 595e4b17023SJohn Marino 596e4b17023SJohn Marino // Iterators: 597e4b17023SJohn Marino /** 598e4b17023SJohn Marino * Returns a read/write iterator that points to the first character in 599e4b17023SJohn Marino * the %string. Unshares the string. 600e4b17023SJohn Marino */ 601e4b17023SJohn Marino iterator 602e4b17023SJohn Marino begin() _GLIBCXX_NOEXCEPT 603e4b17023SJohn Marino { 604e4b17023SJohn Marino _M_leak(); 605e4b17023SJohn Marino return iterator(_M_data()); 606e4b17023SJohn Marino } 607e4b17023SJohn Marino 608e4b17023SJohn Marino /** 609e4b17023SJohn Marino * Returns a read-only (constant) iterator that points to the first 610e4b17023SJohn Marino * character in the %string. 611e4b17023SJohn Marino */ 612e4b17023SJohn Marino const_iterator 613e4b17023SJohn Marino begin() const _GLIBCXX_NOEXCEPT 614e4b17023SJohn Marino { return const_iterator(_M_data()); } 615e4b17023SJohn Marino 616e4b17023SJohn Marino /** 617e4b17023SJohn Marino * Returns a read/write iterator that points one past the last 618e4b17023SJohn Marino * character in the %string. Unshares the string. 619e4b17023SJohn Marino */ 620e4b17023SJohn Marino iterator 621e4b17023SJohn Marino end() _GLIBCXX_NOEXCEPT 622e4b17023SJohn Marino { 623e4b17023SJohn Marino _M_leak(); 624e4b17023SJohn Marino return iterator(_M_data() + this->size()); 625e4b17023SJohn Marino } 626e4b17023SJohn Marino 627e4b17023SJohn Marino /** 628e4b17023SJohn Marino * Returns a read-only (constant) iterator that points one past the 629e4b17023SJohn Marino * last character in the %string. 630e4b17023SJohn Marino */ 631e4b17023SJohn Marino const_iterator 632e4b17023SJohn Marino end() const _GLIBCXX_NOEXCEPT 633e4b17023SJohn Marino { return const_iterator(_M_data() + this->size()); } 634e4b17023SJohn Marino 635e4b17023SJohn Marino /** 636e4b17023SJohn Marino * Returns a read/write reverse iterator that points to the last 637e4b17023SJohn Marino * character in the %string. Iteration is done in reverse element 638e4b17023SJohn Marino * order. Unshares the string. 639e4b17023SJohn Marino */ 640e4b17023SJohn Marino reverse_iterator 641e4b17023SJohn Marino rbegin() _GLIBCXX_NOEXCEPT 642e4b17023SJohn Marino { return reverse_iterator(this->end()); } 643e4b17023SJohn Marino 644e4b17023SJohn Marino /** 645e4b17023SJohn Marino * Returns a read-only (constant) reverse iterator that points 646e4b17023SJohn Marino * to the last character in the %string. Iteration is done in 647e4b17023SJohn Marino * reverse element order. 648e4b17023SJohn Marino */ 649e4b17023SJohn Marino const_reverse_iterator 650e4b17023SJohn Marino rbegin() const _GLIBCXX_NOEXCEPT 651e4b17023SJohn Marino { return const_reverse_iterator(this->end()); } 652e4b17023SJohn Marino 653e4b17023SJohn Marino /** 654e4b17023SJohn Marino * Returns a read/write reverse iterator that points to one before the 655e4b17023SJohn Marino * first character in the %string. Iteration is done in reverse 656e4b17023SJohn Marino * element order. Unshares the string. 657e4b17023SJohn Marino */ 658e4b17023SJohn Marino reverse_iterator 659e4b17023SJohn Marino rend() _GLIBCXX_NOEXCEPT 660e4b17023SJohn Marino { return reverse_iterator(this->begin()); } 661e4b17023SJohn Marino 662e4b17023SJohn Marino /** 663e4b17023SJohn Marino * Returns a read-only (constant) reverse iterator that points 664e4b17023SJohn Marino * to one before the first character in the %string. Iteration 665e4b17023SJohn Marino * is done in reverse element order. 666e4b17023SJohn Marino */ 667e4b17023SJohn Marino const_reverse_iterator 668e4b17023SJohn Marino rend() const _GLIBCXX_NOEXCEPT 669e4b17023SJohn Marino { return const_reverse_iterator(this->begin()); } 670e4b17023SJohn Marino 671e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 672e4b17023SJohn Marino /** 673e4b17023SJohn Marino * Returns a read-only (constant) iterator that points to the first 674e4b17023SJohn Marino * character in the %string. 675e4b17023SJohn Marino */ 676e4b17023SJohn Marino const_iterator 677e4b17023SJohn Marino cbegin() const noexcept 678e4b17023SJohn Marino { return const_iterator(this->_M_data()); } 679e4b17023SJohn Marino 680e4b17023SJohn Marino /** 681e4b17023SJohn Marino * Returns a read-only (constant) iterator that points one past the 682e4b17023SJohn Marino * last character in the %string. 683e4b17023SJohn Marino */ 684e4b17023SJohn Marino const_iterator 685e4b17023SJohn Marino cend() const noexcept 686e4b17023SJohn Marino { return const_iterator(this->_M_data() + this->size()); } 687e4b17023SJohn Marino 688e4b17023SJohn Marino /** 689e4b17023SJohn Marino * Returns a read-only (constant) reverse iterator that points 690e4b17023SJohn Marino * to the last character in the %string. Iteration is done in 691e4b17023SJohn Marino * reverse element order. 692e4b17023SJohn Marino */ 693e4b17023SJohn Marino const_reverse_iterator 694e4b17023SJohn Marino crbegin() const noexcept 695e4b17023SJohn Marino { return const_reverse_iterator(this->end()); } 696e4b17023SJohn Marino 697e4b17023SJohn Marino /** 698e4b17023SJohn Marino * Returns a read-only (constant) reverse iterator that points 699e4b17023SJohn Marino * to one before the first character in the %string. Iteration 700e4b17023SJohn Marino * is done in reverse element order. 701e4b17023SJohn Marino */ 702e4b17023SJohn Marino const_reverse_iterator 703e4b17023SJohn Marino crend() const noexcept 704e4b17023SJohn Marino { return const_reverse_iterator(this->begin()); } 705e4b17023SJohn Marino #endif 706e4b17023SJohn Marino 707e4b17023SJohn Marino public: 708e4b17023SJohn Marino // Capacity: 709e4b17023SJohn Marino /// Returns the number of characters in the string, not including any 710e4b17023SJohn Marino /// null-termination. 711e4b17023SJohn Marino size_type 712e4b17023SJohn Marino size() const _GLIBCXX_NOEXCEPT 713e4b17023SJohn Marino { return _M_rep()->_M_length; } 714e4b17023SJohn Marino 715e4b17023SJohn Marino /// Returns the number of characters in the string, not including any 716e4b17023SJohn Marino /// null-termination. 717e4b17023SJohn Marino size_type 718e4b17023SJohn Marino length() const _GLIBCXX_NOEXCEPT 719e4b17023SJohn Marino { return _M_rep()->_M_length; } 720e4b17023SJohn Marino 721e4b17023SJohn Marino /// Returns the size() of the largest possible %string. 722e4b17023SJohn Marino size_type 723e4b17023SJohn Marino max_size() const _GLIBCXX_NOEXCEPT 724e4b17023SJohn Marino { return _Rep::_S_max_size; } 725e4b17023SJohn Marino 726e4b17023SJohn Marino /** 727e4b17023SJohn Marino * @brief Resizes the %string to the specified number of characters. 728e4b17023SJohn Marino * @param __n Number of characters the %string should contain. 729e4b17023SJohn Marino * @param __c Character to fill any new elements. 730e4b17023SJohn Marino * 731e4b17023SJohn Marino * This function will %resize the %string to the specified 732e4b17023SJohn Marino * number of characters. If the number is smaller than the 733e4b17023SJohn Marino * %string's current size the %string is truncated, otherwise 734e4b17023SJohn Marino * the %string is extended and new elements are %set to @a __c. 735e4b17023SJohn Marino */ 736e4b17023SJohn Marino void 737e4b17023SJohn Marino resize(size_type __n, _CharT __c); 738e4b17023SJohn Marino 739e4b17023SJohn Marino /** 740e4b17023SJohn Marino * @brief Resizes the %string to the specified number of characters. 741e4b17023SJohn Marino * @param __n Number of characters the %string should contain. 742e4b17023SJohn Marino * 743e4b17023SJohn Marino * This function will resize the %string to the specified length. If 744e4b17023SJohn Marino * the new size is smaller than the %string's current size the %string 745e4b17023SJohn Marino * is truncated, otherwise the %string is extended and new characters 746e4b17023SJohn Marino * are default-constructed. For basic types such as char, this means 747e4b17023SJohn Marino * setting them to 0. 748e4b17023SJohn Marino */ 749e4b17023SJohn Marino void 750e4b17023SJohn Marino resize(size_type __n) 751e4b17023SJohn Marino { this->resize(__n, _CharT()); } 752e4b17023SJohn Marino 753e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 754e4b17023SJohn Marino /// A non-binding request to reduce capacity() to size(). 755e4b17023SJohn Marino void 756e4b17023SJohn Marino shrink_to_fit() 757e4b17023SJohn Marino { 758e4b17023SJohn Marino if (capacity() > size()) 759e4b17023SJohn Marino { 760e4b17023SJohn Marino __try 761e4b17023SJohn Marino { reserve(0); } 762e4b17023SJohn Marino __catch(...) 763e4b17023SJohn Marino { } 764e4b17023SJohn Marino } 765e4b17023SJohn Marino } 766e4b17023SJohn Marino #endif 767e4b17023SJohn Marino 768e4b17023SJohn Marino /** 769e4b17023SJohn Marino * Returns the total number of characters that the %string can hold 770e4b17023SJohn Marino * before needing to allocate more memory. 771e4b17023SJohn Marino */ 772e4b17023SJohn Marino size_type 773e4b17023SJohn Marino capacity() const _GLIBCXX_NOEXCEPT 774e4b17023SJohn Marino { return _M_rep()->_M_capacity; } 775e4b17023SJohn Marino 776e4b17023SJohn Marino /** 777e4b17023SJohn Marino * @brief Attempt to preallocate enough memory for specified number of 778e4b17023SJohn Marino * characters. 779e4b17023SJohn Marino * @param __res_arg Number of characters required. 780e4b17023SJohn Marino * @throw std::length_error If @a __res_arg exceeds @c max_size(). 781e4b17023SJohn Marino * 782e4b17023SJohn Marino * This function attempts to reserve enough memory for the 783e4b17023SJohn Marino * %string to hold the specified number of characters. If the 784e4b17023SJohn Marino * number requested is more than max_size(), length_error is 785e4b17023SJohn Marino * thrown. 786e4b17023SJohn Marino * 787e4b17023SJohn Marino * The advantage of this function is that if optimal code is a 788e4b17023SJohn Marino * necessity and the user can determine the string length that will be 789e4b17023SJohn Marino * required, the user can reserve the memory in %advance, and thus 790e4b17023SJohn Marino * prevent a possible reallocation of memory and copying of %string 791e4b17023SJohn Marino * data. 792e4b17023SJohn Marino */ 793e4b17023SJohn Marino void 794e4b17023SJohn Marino reserve(size_type __res_arg = 0); 795e4b17023SJohn Marino 796e4b17023SJohn Marino /** 797e4b17023SJohn Marino * Erases the string, making it empty. 798e4b17023SJohn Marino */ 799e4b17023SJohn Marino void 800e4b17023SJohn Marino clear() _GLIBCXX_NOEXCEPT 801e4b17023SJohn Marino { _M_mutate(0, this->size(), 0); } 802e4b17023SJohn Marino 803e4b17023SJohn Marino /** 804e4b17023SJohn Marino * Returns true if the %string is empty. Equivalent to 805e4b17023SJohn Marino * <code>*this == ""</code>. 806e4b17023SJohn Marino */ 807e4b17023SJohn Marino bool 808e4b17023SJohn Marino empty() const _GLIBCXX_NOEXCEPT 809e4b17023SJohn Marino { return this->size() == 0; } 810e4b17023SJohn Marino 811e4b17023SJohn Marino // Element access: 812e4b17023SJohn Marino /** 813e4b17023SJohn Marino * @brief Subscript access to the data contained in the %string. 814e4b17023SJohn Marino * @param __pos The index of the character to access. 815e4b17023SJohn Marino * @return Read-only (constant) reference to the character. 816e4b17023SJohn Marino * 817e4b17023SJohn Marino * This operator allows for easy, array-style, data access. 818e4b17023SJohn Marino * Note that data access with this operator is unchecked and 819e4b17023SJohn Marino * out_of_range lookups are not defined. (For checked lookups 820e4b17023SJohn Marino * see at().) 821e4b17023SJohn Marino */ 822e4b17023SJohn Marino const_reference 823e4b17023SJohn Marino operator[] (size_type __pos) const 824e4b17023SJohn Marino { 825e4b17023SJohn Marino _GLIBCXX_DEBUG_ASSERT(__pos <= size()); 826e4b17023SJohn Marino return _M_data()[__pos]; 827e4b17023SJohn Marino } 828e4b17023SJohn Marino 829e4b17023SJohn Marino /** 830e4b17023SJohn Marino * @brief Subscript access to the data contained in the %string. 831e4b17023SJohn Marino * @param __pos The index of the character to access. 832e4b17023SJohn Marino * @return Read/write reference to the character. 833e4b17023SJohn Marino * 834e4b17023SJohn Marino * This operator allows for easy, array-style, data access. 835e4b17023SJohn Marino * Note that data access with this operator is unchecked and 836e4b17023SJohn Marino * out_of_range lookups are not defined. (For checked lookups 837e4b17023SJohn Marino * see at().) Unshares the string. 838e4b17023SJohn Marino */ 839e4b17023SJohn Marino reference 840e4b17023SJohn Marino operator[](size_type __pos) 841e4b17023SJohn Marino { 842e4b17023SJohn Marino // allow pos == size() as v3 extension: 843e4b17023SJohn Marino _GLIBCXX_DEBUG_ASSERT(__pos <= size()); 844e4b17023SJohn Marino // but be strict in pedantic mode: 845e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(__pos < size()); 846e4b17023SJohn Marino _M_leak(); 847e4b17023SJohn Marino return _M_data()[__pos]; 848e4b17023SJohn Marino } 849e4b17023SJohn Marino 850e4b17023SJohn Marino /** 851e4b17023SJohn Marino * @brief Provides access to the data contained in the %string. 852e4b17023SJohn Marino * @param __n The index of the character to access. 853e4b17023SJohn Marino * @return Read-only (const) reference to the character. 854e4b17023SJohn Marino * @throw std::out_of_range If @a n is an invalid index. 855e4b17023SJohn Marino * 856e4b17023SJohn Marino * This function provides for safer data access. The parameter is 857e4b17023SJohn Marino * first checked that it is in the range of the string. The function 858e4b17023SJohn Marino * throws out_of_range if the check fails. 859e4b17023SJohn Marino */ 860e4b17023SJohn Marino const_reference 861e4b17023SJohn Marino at(size_type __n) const 862e4b17023SJohn Marino { 863e4b17023SJohn Marino if (__n >= this->size()) 864e4b17023SJohn Marino __throw_out_of_range(__N("basic_string::at")); 865e4b17023SJohn Marino return _M_data()[__n]; 866e4b17023SJohn Marino } 867e4b17023SJohn Marino 868e4b17023SJohn Marino /** 869e4b17023SJohn Marino * @brief Provides access to the data contained in the %string. 870e4b17023SJohn Marino * @param __n The index of the character to access. 871e4b17023SJohn Marino * @return Read/write reference to the character. 872e4b17023SJohn Marino * @throw std::out_of_range If @a n is an invalid index. 873e4b17023SJohn Marino * 874e4b17023SJohn Marino * This function provides for safer data access. The parameter is 875e4b17023SJohn Marino * first checked that it is in the range of the string. The function 876e4b17023SJohn Marino * throws out_of_range if the check fails. Success results in 877e4b17023SJohn Marino * unsharing the string. 878e4b17023SJohn Marino */ 879e4b17023SJohn Marino reference 880e4b17023SJohn Marino at(size_type __n) 881e4b17023SJohn Marino { 882e4b17023SJohn Marino if (__n >= size()) 883e4b17023SJohn Marino __throw_out_of_range(__N("basic_string::at")); 884e4b17023SJohn Marino _M_leak(); 885e4b17023SJohn Marino return _M_data()[__n]; 886e4b17023SJohn Marino } 887e4b17023SJohn Marino 888e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 889e4b17023SJohn Marino /** 890e4b17023SJohn Marino * Returns a read/write reference to the data at the first 891e4b17023SJohn Marino * element of the %string. 892e4b17023SJohn Marino */ 893e4b17023SJohn Marino reference 894e4b17023SJohn Marino front() 895e4b17023SJohn Marino { return operator[](0); } 896e4b17023SJohn Marino 897e4b17023SJohn Marino /** 898e4b17023SJohn Marino * Returns a read-only (constant) reference to the data at the first 899e4b17023SJohn Marino * element of the %string. 900e4b17023SJohn Marino */ 901e4b17023SJohn Marino const_reference 902e4b17023SJohn Marino front() const 903e4b17023SJohn Marino { return operator[](0); } 904e4b17023SJohn Marino 905e4b17023SJohn Marino /** 906e4b17023SJohn Marino * Returns a read/write reference to the data at the last 907e4b17023SJohn Marino * element of the %string. 908e4b17023SJohn Marino */ 909e4b17023SJohn Marino reference 910e4b17023SJohn Marino back() 911e4b17023SJohn Marino { return operator[](this->size() - 1); } 912e4b17023SJohn Marino 913e4b17023SJohn Marino /** 914e4b17023SJohn Marino * Returns a read-only (constant) reference to the data at the 915e4b17023SJohn Marino * last element of the %string. 916e4b17023SJohn Marino */ 917e4b17023SJohn Marino const_reference 918e4b17023SJohn Marino back() const 919e4b17023SJohn Marino { return operator[](this->size() - 1); } 920e4b17023SJohn Marino #endif 921e4b17023SJohn Marino 922e4b17023SJohn Marino // Modifiers: 923e4b17023SJohn Marino /** 924e4b17023SJohn Marino * @brief Append a string to this string. 925e4b17023SJohn Marino * @param __str The string to append. 926e4b17023SJohn Marino * @return Reference to this string. 927e4b17023SJohn Marino */ 928e4b17023SJohn Marino basic_string& 929e4b17023SJohn Marino operator+=(const basic_string& __str) 930e4b17023SJohn Marino { return this->append(__str); } 931e4b17023SJohn Marino 932e4b17023SJohn Marino /** 933e4b17023SJohn Marino * @brief Append a C string. 934e4b17023SJohn Marino * @param __s The C string to append. 935e4b17023SJohn Marino * @return Reference to this string. 936e4b17023SJohn Marino */ 937e4b17023SJohn Marino basic_string& 938e4b17023SJohn Marino operator+=(const _CharT* __s) 939e4b17023SJohn Marino { return this->append(__s); } 940e4b17023SJohn Marino 941e4b17023SJohn Marino /** 942e4b17023SJohn Marino * @brief Append a character. 943e4b17023SJohn Marino * @param __c The character to append. 944e4b17023SJohn Marino * @return Reference to this string. 945e4b17023SJohn Marino */ 946e4b17023SJohn Marino basic_string& 947e4b17023SJohn Marino operator+=(_CharT __c) 948e4b17023SJohn Marino { 949e4b17023SJohn Marino this->push_back(__c); 950e4b17023SJohn Marino return *this; 951e4b17023SJohn Marino } 952e4b17023SJohn Marino 953e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 954e4b17023SJohn Marino /** 955e4b17023SJohn Marino * @brief Append an initializer_list of characters. 956e4b17023SJohn Marino * @param __l The initializer_list of characters to be appended. 957e4b17023SJohn Marino * @return Reference to this string. 958e4b17023SJohn Marino */ 959e4b17023SJohn Marino basic_string& 960e4b17023SJohn Marino operator+=(initializer_list<_CharT> __l) 961e4b17023SJohn Marino { return this->append(__l.begin(), __l.size()); } 962e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__ 963e4b17023SJohn Marino 964e4b17023SJohn Marino /** 965e4b17023SJohn Marino * @brief Append a string to this string. 966e4b17023SJohn Marino * @param __str The string to append. 967e4b17023SJohn Marino * @return Reference to this string. 968e4b17023SJohn Marino */ 969e4b17023SJohn Marino basic_string& 970e4b17023SJohn Marino append(const basic_string& __str); 971e4b17023SJohn Marino 972e4b17023SJohn Marino /** 973e4b17023SJohn Marino * @brief Append a substring. 974e4b17023SJohn Marino * @param __str The string to append. 975e4b17023SJohn Marino * @param __pos Index of the first character of str to append. 976e4b17023SJohn Marino * @param __n The number of characters to append. 977e4b17023SJohn Marino * @return Reference to this string. 978e4b17023SJohn Marino * @throw std::out_of_range if @a __pos is not a valid index. 979e4b17023SJohn Marino * 980e4b17023SJohn Marino * This function appends @a __n characters from @a __str 981e4b17023SJohn Marino * starting at @a __pos to this string. If @a __n is is larger 982e4b17023SJohn Marino * than the number of available characters in @a __str, the 983e4b17023SJohn Marino * remainder of @a __str is appended. 984e4b17023SJohn Marino */ 985e4b17023SJohn Marino basic_string& 986e4b17023SJohn Marino append(const basic_string& __str, size_type __pos, size_type __n); 987e4b17023SJohn Marino 988e4b17023SJohn Marino /** 989e4b17023SJohn Marino * @brief Append a C substring. 990e4b17023SJohn Marino * @param __s The C string to append. 991e4b17023SJohn Marino * @param __n The number of characters to append. 992e4b17023SJohn Marino * @return Reference to this string. 993e4b17023SJohn Marino */ 994e4b17023SJohn Marino basic_string& 995e4b17023SJohn Marino append(const _CharT* __s, size_type __n); 996e4b17023SJohn Marino 997e4b17023SJohn Marino /** 998e4b17023SJohn Marino * @brief Append a C string. 999e4b17023SJohn Marino * @param __s The C string to append. 1000e4b17023SJohn Marino * @return Reference to this string. 1001e4b17023SJohn Marino */ 1002e4b17023SJohn Marino basic_string& 1003e4b17023SJohn Marino append(const _CharT* __s) 1004e4b17023SJohn Marino { 1005e4b17023SJohn Marino __glibcxx_requires_string(__s); 1006e4b17023SJohn Marino return this->append(__s, traits_type::length(__s)); 1007e4b17023SJohn Marino } 1008e4b17023SJohn Marino 1009e4b17023SJohn Marino /** 1010e4b17023SJohn Marino * @brief Append multiple characters. 1011e4b17023SJohn Marino * @param __n The number of characters to append. 1012e4b17023SJohn Marino * @param __c The character to use. 1013e4b17023SJohn Marino * @return Reference to this string. 1014e4b17023SJohn Marino * 1015e4b17023SJohn Marino * Appends __n copies of __c to this string. 1016e4b17023SJohn Marino */ 1017e4b17023SJohn Marino basic_string& 1018e4b17023SJohn Marino append(size_type __n, _CharT __c); 1019e4b17023SJohn Marino 1020e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 1021e4b17023SJohn Marino /** 1022e4b17023SJohn Marino * @brief Append an initializer_list of characters. 1023e4b17023SJohn Marino * @param __l The initializer_list of characters to append. 1024e4b17023SJohn Marino * @return Reference to this string. 1025e4b17023SJohn Marino */ 1026e4b17023SJohn Marino basic_string& 1027e4b17023SJohn Marino append(initializer_list<_CharT> __l) 1028e4b17023SJohn Marino { return this->append(__l.begin(), __l.size()); } 1029e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__ 1030e4b17023SJohn Marino 1031e4b17023SJohn Marino /** 1032e4b17023SJohn Marino * @brief Append a range of characters. 1033e4b17023SJohn Marino * @param __first Iterator referencing the first character to append. 1034e4b17023SJohn Marino * @param __last Iterator marking the end of the range. 1035e4b17023SJohn Marino * @return Reference to this string. 1036e4b17023SJohn Marino * 1037e4b17023SJohn Marino * Appends characters in the range [__first,__last) to this string. 1038e4b17023SJohn Marino */ 1039e4b17023SJohn Marino template<class _InputIterator> 1040e4b17023SJohn Marino basic_string& 1041e4b17023SJohn Marino append(_InputIterator __first, _InputIterator __last) 1042e4b17023SJohn Marino { return this->replace(_M_iend(), _M_iend(), __first, __last); } 1043e4b17023SJohn Marino 1044e4b17023SJohn Marino /** 1045e4b17023SJohn Marino * @brief Append a single character. 1046e4b17023SJohn Marino * @param __c Character to append. 1047e4b17023SJohn Marino */ 1048e4b17023SJohn Marino void 1049e4b17023SJohn Marino push_back(_CharT __c) 1050e4b17023SJohn Marino { 1051e4b17023SJohn Marino const size_type __len = 1 + this->size(); 1052e4b17023SJohn Marino if (__len > this->capacity() || _M_rep()->_M_is_shared()) 1053e4b17023SJohn Marino this->reserve(__len); 1054e4b17023SJohn Marino traits_type::assign(_M_data()[this->size()], __c); 1055e4b17023SJohn Marino _M_rep()->_M_set_length_and_sharable(__len); 1056e4b17023SJohn Marino } 1057e4b17023SJohn Marino 1058e4b17023SJohn Marino /** 1059e4b17023SJohn Marino * @brief Set value to contents of another string. 1060e4b17023SJohn Marino * @param __str Source string to use. 1061e4b17023SJohn Marino * @return Reference to this string. 1062e4b17023SJohn Marino */ 1063e4b17023SJohn Marino basic_string& 1064e4b17023SJohn Marino assign(const basic_string& __str); 1065e4b17023SJohn Marino 1066e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 1067e4b17023SJohn Marino /** 1068e4b17023SJohn Marino * @brief Set value to contents of another string. 1069e4b17023SJohn Marino * @param __str Source string to use. 1070e4b17023SJohn Marino * @return Reference to this string. 1071e4b17023SJohn Marino * 1072e4b17023SJohn Marino * This function sets this string to the exact contents of @a __str. 1073e4b17023SJohn Marino * @a __str is a valid, but unspecified string. 1074e4b17023SJohn Marino */ 1075e4b17023SJohn Marino basic_string& 1076e4b17023SJohn Marino assign(basic_string&& __str) 1077e4b17023SJohn Marino { 1078e4b17023SJohn Marino this->swap(__str); 1079e4b17023SJohn Marino return *this; 1080e4b17023SJohn Marino } 1081e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__ 1082e4b17023SJohn Marino 1083e4b17023SJohn Marino /** 1084e4b17023SJohn Marino * @brief Set value to a substring of a string. 1085e4b17023SJohn Marino * @param __str The string to use. 1086e4b17023SJohn Marino * @param __pos Index of the first character of str. 1087e4b17023SJohn Marino * @param __n Number of characters to use. 1088e4b17023SJohn Marino * @return Reference to this string. 1089e4b17023SJohn Marino * @throw std::out_of_range if @a pos is not a valid index. 1090e4b17023SJohn Marino * 1091e4b17023SJohn Marino * This function sets this string to the substring of @a __str 1092e4b17023SJohn Marino * consisting of @a __n characters at @a __pos. If @a __n is 1093e4b17023SJohn Marino * is larger than the number of available characters in @a 1094e4b17023SJohn Marino * __str, the remainder of @a __str is used. 1095e4b17023SJohn Marino */ 1096e4b17023SJohn Marino basic_string& 1097e4b17023SJohn Marino assign(const basic_string& __str, size_type __pos, size_type __n) 1098e4b17023SJohn Marino { return this->assign(__str._M_data() 1099e4b17023SJohn Marino + __str._M_check(__pos, "basic_string::assign"), 1100e4b17023SJohn Marino __str._M_limit(__pos, __n)); } 1101e4b17023SJohn Marino 1102e4b17023SJohn Marino /** 1103e4b17023SJohn Marino * @brief Set value to a C substring. 1104e4b17023SJohn Marino * @param __s The C string to use. 1105e4b17023SJohn Marino * @param __n Number of characters to use. 1106e4b17023SJohn Marino * @return Reference to this string. 1107e4b17023SJohn Marino * 1108e4b17023SJohn Marino * This function sets the value of this string to the first @a __n 1109e4b17023SJohn Marino * characters of @a __s. If @a __n is is larger than the number of 1110e4b17023SJohn Marino * available characters in @a __s, the remainder of @a __s is used. 1111e4b17023SJohn Marino */ 1112e4b17023SJohn Marino basic_string& 1113e4b17023SJohn Marino assign(const _CharT* __s, size_type __n); 1114e4b17023SJohn Marino 1115e4b17023SJohn Marino /** 1116e4b17023SJohn Marino * @brief Set value to contents of a C string. 1117e4b17023SJohn Marino * @param __s The C string to use. 1118e4b17023SJohn Marino * @return Reference to this string. 1119e4b17023SJohn Marino * 1120e4b17023SJohn Marino * This function sets the value of this string to the value of @a __s. 1121e4b17023SJohn Marino * The data is copied, so there is no dependence on @a __s once the 1122e4b17023SJohn Marino * function returns. 1123e4b17023SJohn Marino */ 1124e4b17023SJohn Marino basic_string& 1125e4b17023SJohn Marino assign(const _CharT* __s) 1126e4b17023SJohn Marino { 1127e4b17023SJohn Marino __glibcxx_requires_string(__s); 1128e4b17023SJohn Marino return this->assign(__s, traits_type::length(__s)); 1129e4b17023SJohn Marino } 1130e4b17023SJohn Marino 1131e4b17023SJohn Marino /** 1132e4b17023SJohn Marino * @brief Set value to multiple characters. 1133e4b17023SJohn Marino * @param __n Length of the resulting string. 1134e4b17023SJohn Marino * @param __c The character to use. 1135e4b17023SJohn Marino * @return Reference to this string. 1136e4b17023SJohn Marino * 1137e4b17023SJohn Marino * This function sets the value of this string to @a __n copies of 1138e4b17023SJohn Marino * character @a __c. 1139e4b17023SJohn Marino */ 1140e4b17023SJohn Marino basic_string& 1141e4b17023SJohn Marino assign(size_type __n, _CharT __c) 1142e4b17023SJohn Marino { return _M_replace_aux(size_type(0), this->size(), __n, __c); } 1143e4b17023SJohn Marino 1144e4b17023SJohn Marino /** 1145e4b17023SJohn Marino * @brief Set value to a range of characters. 1146e4b17023SJohn Marino * @param __first Iterator referencing the first character to append. 1147e4b17023SJohn Marino * @param __last Iterator marking the end of the range. 1148e4b17023SJohn Marino * @return Reference to this string. 1149e4b17023SJohn Marino * 1150e4b17023SJohn Marino * Sets value of string to characters in the range [__first,__last). 1151e4b17023SJohn Marino */ 1152e4b17023SJohn Marino template<class _InputIterator> 1153e4b17023SJohn Marino basic_string& 1154e4b17023SJohn Marino assign(_InputIterator __first, _InputIterator __last) 1155e4b17023SJohn Marino { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } 1156e4b17023SJohn Marino 1157e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 1158e4b17023SJohn Marino /** 1159e4b17023SJohn Marino * @brief Set value to an initializer_list of characters. 1160e4b17023SJohn Marino * @param __l The initializer_list of characters to assign. 1161e4b17023SJohn Marino * @return Reference to this string. 1162e4b17023SJohn Marino */ 1163e4b17023SJohn Marino basic_string& 1164e4b17023SJohn Marino assign(initializer_list<_CharT> __l) 1165e4b17023SJohn Marino { return this->assign(__l.begin(), __l.size()); } 1166e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__ 1167e4b17023SJohn Marino 1168e4b17023SJohn Marino /** 1169e4b17023SJohn Marino * @brief Insert multiple characters. 1170e4b17023SJohn Marino * @param __p Iterator referencing location in string to insert at. 1171e4b17023SJohn Marino * @param __n Number of characters to insert 1172e4b17023SJohn Marino * @param __c The character to insert. 1173e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1174e4b17023SJohn Marino * 1175e4b17023SJohn Marino * Inserts @a __n copies of character @a __c starting at the 1176e4b17023SJohn Marino * position referenced by iterator @a __p. If adding 1177e4b17023SJohn Marino * characters causes the length to exceed max_size(), 1178e4b17023SJohn Marino * length_error is thrown. The value of the string doesn't 1179e4b17023SJohn Marino * change if an error is thrown. 1180e4b17023SJohn Marino */ 1181e4b17023SJohn Marino void 1182e4b17023SJohn Marino insert(iterator __p, size_type __n, _CharT __c) 1183e4b17023SJohn Marino { this->replace(__p, __p, __n, __c); } 1184e4b17023SJohn Marino 1185e4b17023SJohn Marino /** 1186e4b17023SJohn Marino * @brief Insert a range of characters. 1187e4b17023SJohn Marino * @param __p Iterator referencing location in string to insert at. 1188e4b17023SJohn Marino * @param __beg Start of range. 1189e4b17023SJohn Marino * @param __end End of range. 1190e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1191e4b17023SJohn Marino * 1192e4b17023SJohn Marino * Inserts characters in range [__beg,__end). If adding 1193e4b17023SJohn Marino * characters causes the length to exceed max_size(), 1194e4b17023SJohn Marino * length_error is thrown. The value of the string doesn't 1195e4b17023SJohn Marino * change if an error is thrown. 1196e4b17023SJohn Marino */ 1197e4b17023SJohn Marino template<class _InputIterator> 1198e4b17023SJohn Marino void 1199e4b17023SJohn Marino insert(iterator __p, _InputIterator __beg, _InputIterator __end) 1200e4b17023SJohn Marino { this->replace(__p, __p, __beg, __end); } 1201e4b17023SJohn Marino 1202e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 1203e4b17023SJohn Marino /** 1204e4b17023SJohn Marino * @brief Insert an initializer_list of characters. 1205e4b17023SJohn Marino * @param __p Iterator referencing location in string to insert at. 1206e4b17023SJohn Marino * @param __l The initializer_list of characters to insert. 1207e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1208e4b17023SJohn Marino */ 1209e4b17023SJohn Marino void 1210e4b17023SJohn Marino insert(iterator __p, initializer_list<_CharT> __l) 1211e4b17023SJohn Marino { 1212e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 1213e4b17023SJohn Marino this->insert(__p - _M_ibegin(), __l.begin(), __l.size()); 1214e4b17023SJohn Marino } 1215e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__ 1216e4b17023SJohn Marino 1217e4b17023SJohn Marino /** 1218e4b17023SJohn Marino * @brief Insert value of a string. 1219e4b17023SJohn Marino * @param __pos1 Iterator referencing location in string to insert at. 1220e4b17023SJohn Marino * @param __str The string to insert. 1221e4b17023SJohn Marino * @return Reference to this string. 1222e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1223e4b17023SJohn Marino * 1224e4b17023SJohn Marino * Inserts value of @a __str starting at @a __pos1. If adding 1225e4b17023SJohn Marino * characters causes the length to exceed max_size(), 1226e4b17023SJohn Marino * length_error is thrown. The value of the string doesn't 1227e4b17023SJohn Marino * change if an error is thrown. 1228e4b17023SJohn Marino */ 1229e4b17023SJohn Marino basic_string& 1230e4b17023SJohn Marino insert(size_type __pos1, const basic_string& __str) 1231e4b17023SJohn Marino { return this->insert(__pos1, __str, size_type(0), __str.size()); } 1232e4b17023SJohn Marino 1233e4b17023SJohn Marino /** 1234e4b17023SJohn Marino * @brief Insert a substring. 1235e4b17023SJohn Marino * @param __pos1 Iterator referencing location in string to insert at. 1236e4b17023SJohn Marino * @param __str The string to insert. 1237e4b17023SJohn Marino * @param __pos2 Start of characters in str to insert. 1238e4b17023SJohn Marino * @param __n Number of characters to insert. 1239e4b17023SJohn Marino * @return Reference to this string. 1240e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1241e4b17023SJohn Marino * @throw std::out_of_range If @a pos1 > size() or 1242e4b17023SJohn Marino * @a __pos2 > @a str.size(). 1243e4b17023SJohn Marino * 1244e4b17023SJohn Marino * Starting at @a pos1, insert @a __n character of @a __str 1245e4b17023SJohn Marino * beginning with @a __pos2. If adding characters causes the 1246e4b17023SJohn Marino * length to exceed max_size(), length_error is thrown. If @a 1247e4b17023SJohn Marino * __pos1 is beyond the end of this string or @a __pos2 is 1248e4b17023SJohn Marino * beyond the end of @a __str, out_of_range is thrown. The 1249e4b17023SJohn Marino * value of the string doesn't change if an error is thrown. 1250e4b17023SJohn Marino */ 1251e4b17023SJohn Marino basic_string& 1252e4b17023SJohn Marino insert(size_type __pos1, const basic_string& __str, 1253e4b17023SJohn Marino size_type __pos2, size_type __n) 1254e4b17023SJohn Marino { return this->insert(__pos1, __str._M_data() 1255e4b17023SJohn Marino + __str._M_check(__pos2, "basic_string::insert"), 1256e4b17023SJohn Marino __str._M_limit(__pos2, __n)); } 1257e4b17023SJohn Marino 1258e4b17023SJohn Marino /** 1259e4b17023SJohn Marino * @brief Insert a C substring. 1260e4b17023SJohn Marino * @param __pos Iterator referencing location in string to insert at. 1261e4b17023SJohn Marino * @param __s The C string to insert. 1262e4b17023SJohn Marino * @param __n The number of characters to insert. 1263e4b17023SJohn Marino * @return Reference to this string. 1264e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1265e4b17023SJohn Marino * @throw std::out_of_range If @a __pos is beyond the end of this 1266e4b17023SJohn Marino * string. 1267e4b17023SJohn Marino * 1268e4b17023SJohn Marino * Inserts the first @a __n characters of @a __s starting at @a 1269e4b17023SJohn Marino * __pos. If adding characters causes the length to exceed 1270e4b17023SJohn Marino * max_size(), length_error is thrown. If @a __pos is beyond 1271e4b17023SJohn Marino * end(), out_of_range is thrown. The value of the string 1272e4b17023SJohn Marino * doesn't change if an error is thrown. 1273e4b17023SJohn Marino */ 1274e4b17023SJohn Marino basic_string& 1275e4b17023SJohn Marino insert(size_type __pos, const _CharT* __s, size_type __n); 1276e4b17023SJohn Marino 1277e4b17023SJohn Marino /** 1278e4b17023SJohn Marino * @brief Insert a C string. 1279e4b17023SJohn Marino * @param __pos Iterator referencing location in string to insert at. 1280e4b17023SJohn Marino * @param __s The C string to insert. 1281e4b17023SJohn Marino * @return Reference to this string. 1282e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1283e4b17023SJohn Marino * @throw std::out_of_range If @a pos is beyond the end of this 1284e4b17023SJohn Marino * string. 1285e4b17023SJohn Marino * 1286e4b17023SJohn Marino * Inserts the first @a n characters of @a __s starting at @a __pos. If 1287e4b17023SJohn Marino * adding characters causes the length to exceed max_size(), 1288e4b17023SJohn Marino * length_error is thrown. If @a __pos is beyond end(), out_of_range is 1289e4b17023SJohn Marino * thrown. The value of the string doesn't change if an error is 1290e4b17023SJohn Marino * thrown. 1291e4b17023SJohn Marino */ 1292e4b17023SJohn Marino basic_string& 1293e4b17023SJohn Marino insert(size_type __pos, const _CharT* __s) 1294e4b17023SJohn Marino { 1295e4b17023SJohn Marino __glibcxx_requires_string(__s); 1296e4b17023SJohn Marino return this->insert(__pos, __s, traits_type::length(__s)); 1297e4b17023SJohn Marino } 1298e4b17023SJohn Marino 1299e4b17023SJohn Marino /** 1300e4b17023SJohn Marino * @brief Insert multiple characters. 1301e4b17023SJohn Marino * @param __pos Index in string to insert at. 1302e4b17023SJohn Marino * @param __n Number of characters to insert 1303e4b17023SJohn Marino * @param __c The character to insert. 1304e4b17023SJohn Marino * @return Reference to this string. 1305e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1306e4b17023SJohn Marino * @throw std::out_of_range If @a __pos is beyond the end of this 1307e4b17023SJohn Marino * string. 1308e4b17023SJohn Marino * 1309e4b17023SJohn Marino * Inserts @a __n copies of character @a __c starting at index 1310e4b17023SJohn Marino * @a __pos. If adding characters causes the length to exceed 1311e4b17023SJohn Marino * max_size(), length_error is thrown. If @a __pos > length(), 1312e4b17023SJohn Marino * out_of_range is thrown. The value of the string doesn't 1313e4b17023SJohn Marino * change if an error is thrown. 1314e4b17023SJohn Marino */ 1315e4b17023SJohn Marino basic_string& 1316e4b17023SJohn Marino insert(size_type __pos, size_type __n, _CharT __c) 1317e4b17023SJohn Marino { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), 1318e4b17023SJohn Marino size_type(0), __n, __c); } 1319e4b17023SJohn Marino 1320e4b17023SJohn Marino /** 1321e4b17023SJohn Marino * @brief Insert one character. 1322e4b17023SJohn Marino * @param __p Iterator referencing position in string to insert at. 1323e4b17023SJohn Marino * @param __c The character to insert. 1324e4b17023SJohn Marino * @return Iterator referencing newly inserted char. 1325e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1326e4b17023SJohn Marino * 1327e4b17023SJohn Marino * Inserts character @a __c at position referenced by @a __p. 1328e4b17023SJohn Marino * If adding character causes the length to exceed max_size(), 1329e4b17023SJohn Marino * length_error is thrown. If @a __p is beyond end of string, 1330e4b17023SJohn Marino * out_of_range is thrown. The value of the string doesn't 1331e4b17023SJohn Marino * change if an error is thrown. 1332e4b17023SJohn Marino */ 1333e4b17023SJohn Marino iterator 1334e4b17023SJohn Marino insert(iterator __p, _CharT __c) 1335e4b17023SJohn Marino { 1336e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 1337e4b17023SJohn Marino const size_type __pos = __p - _M_ibegin(); 1338e4b17023SJohn Marino _M_replace_aux(__pos, size_type(0), size_type(1), __c); 1339e4b17023SJohn Marino _M_rep()->_M_set_leaked(); 1340e4b17023SJohn Marino return iterator(_M_data() + __pos); 1341e4b17023SJohn Marino } 1342e4b17023SJohn Marino 1343e4b17023SJohn Marino /** 1344e4b17023SJohn Marino * @brief Remove characters. 1345e4b17023SJohn Marino * @param __pos Index of first character to remove (default 0). 1346e4b17023SJohn Marino * @param __n Number of characters to remove (default remainder). 1347e4b17023SJohn Marino * @return Reference to this string. 1348e4b17023SJohn Marino * @throw std::out_of_range If @a pos is beyond the end of this 1349e4b17023SJohn Marino * string. 1350e4b17023SJohn Marino * 1351e4b17023SJohn Marino * Removes @a __n characters from this string starting at @a 1352e4b17023SJohn Marino * __pos. The length of the string is reduced by @a __n. If 1353e4b17023SJohn Marino * there are < @a __n characters to remove, the remainder of 1354e4b17023SJohn Marino * the string is truncated. If @a __p is beyond end of string, 1355e4b17023SJohn Marino * out_of_range is thrown. The value of the string doesn't 1356e4b17023SJohn Marino * change if an error is thrown. 1357e4b17023SJohn Marino */ 1358e4b17023SJohn Marino basic_string& 1359e4b17023SJohn Marino erase(size_type __pos = 0, size_type __n = npos) 1360e4b17023SJohn Marino { 1361e4b17023SJohn Marino _M_mutate(_M_check(__pos, "basic_string::erase"), 1362e4b17023SJohn Marino _M_limit(__pos, __n), size_type(0)); 1363e4b17023SJohn Marino return *this; 1364e4b17023SJohn Marino } 1365e4b17023SJohn Marino 1366e4b17023SJohn Marino /** 1367e4b17023SJohn Marino * @brief Remove one character. 1368e4b17023SJohn Marino * @param __position Iterator referencing the character to remove. 1369e4b17023SJohn Marino * @return iterator referencing same location after removal. 1370e4b17023SJohn Marino * 1371e4b17023SJohn Marino * Removes the character at @a __position from this string. The value 1372e4b17023SJohn Marino * of the string doesn't change if an error is thrown. 1373e4b17023SJohn Marino */ 1374e4b17023SJohn Marino iterator 1375e4b17023SJohn Marino erase(iterator __position) 1376e4b17023SJohn Marino { 1377e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() 1378e4b17023SJohn Marino && __position < _M_iend()); 1379e4b17023SJohn Marino const size_type __pos = __position - _M_ibegin(); 1380e4b17023SJohn Marino _M_mutate(__pos, size_type(1), size_type(0)); 1381e4b17023SJohn Marino _M_rep()->_M_set_leaked(); 1382e4b17023SJohn Marino return iterator(_M_data() + __pos); 1383e4b17023SJohn Marino } 1384e4b17023SJohn Marino 1385e4b17023SJohn Marino /** 1386e4b17023SJohn Marino * @brief Remove a range of characters. 1387e4b17023SJohn Marino * @param __first Iterator referencing the first character to remove. 1388e4b17023SJohn Marino * @param __last Iterator referencing the end of the range. 1389e4b17023SJohn Marino * @return Iterator referencing location of first after removal. 1390e4b17023SJohn Marino * 1391e4b17023SJohn Marino * Removes the characters in the range [first,last) from this string. 1392e4b17023SJohn Marino * The value of the string doesn't change if an error is thrown. 1393e4b17023SJohn Marino */ 1394e4b17023SJohn Marino iterator 1395e4b17023SJohn Marino erase(iterator __first, iterator __last); 1396e4b17023SJohn Marino 1397e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 1398e4b17023SJohn Marino /** 1399e4b17023SJohn Marino * @brief Remove the last character. 1400e4b17023SJohn Marino * 1401e4b17023SJohn Marino * The string must be non-empty. 1402e4b17023SJohn Marino */ 1403e4b17023SJohn Marino void 1404e4b17023SJohn Marino pop_back() 1405e4b17023SJohn Marino { erase(size()-1, 1); } 1406e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__ 1407e4b17023SJohn Marino 1408e4b17023SJohn Marino /** 1409e4b17023SJohn Marino * @brief Replace characters with value from another string. 1410e4b17023SJohn Marino * @param __pos Index of first character to replace. 1411e4b17023SJohn Marino * @param __n Number of characters to be replaced. 1412e4b17023SJohn Marino * @param __str String to insert. 1413e4b17023SJohn Marino * @return Reference to this string. 1414e4b17023SJohn Marino * @throw std::out_of_range If @a pos is beyond the end of this 1415e4b17023SJohn Marino * string. 1416e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1417e4b17023SJohn Marino * 1418e4b17023SJohn Marino * Removes the characters in the range [__pos,__pos+__n) from 1419e4b17023SJohn Marino * this string. In place, the value of @a __str is inserted. 1420e4b17023SJohn Marino * If @a __pos is beyond end of string, out_of_range is thrown. 1421e4b17023SJohn Marino * If the length of the result exceeds max_size(), length_error 1422e4b17023SJohn Marino * is thrown. The value of the string doesn't change if an 1423e4b17023SJohn Marino * error is thrown. 1424e4b17023SJohn Marino */ 1425e4b17023SJohn Marino basic_string& 1426e4b17023SJohn Marino replace(size_type __pos, size_type __n, const basic_string& __str) 1427e4b17023SJohn Marino { return this->replace(__pos, __n, __str._M_data(), __str.size()); } 1428e4b17023SJohn Marino 1429e4b17023SJohn Marino /** 1430e4b17023SJohn Marino * @brief Replace characters with value from another string. 1431e4b17023SJohn Marino * @param __pos1 Index of first character to replace. 1432e4b17023SJohn Marino * @param __n1 Number of characters to be replaced. 1433e4b17023SJohn Marino * @param __str String to insert. 1434e4b17023SJohn Marino * @param __pos2 Index of first character of str to use. 1435e4b17023SJohn Marino * @param __n2 Number of characters from str to use. 1436e4b17023SJohn Marino * @return Reference to this string. 1437e4b17023SJohn Marino * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > 1438e4b17023SJohn Marino * __str.size(). 1439e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1440e4b17023SJohn Marino * 1441e4b17023SJohn Marino * Removes the characters in the range [__pos1,__pos1 + n) from this 1442e4b17023SJohn Marino * string. In place, the value of @a __str is inserted. If @a __pos is 1443e4b17023SJohn Marino * beyond end of string, out_of_range is thrown. If the length of the 1444e4b17023SJohn Marino * result exceeds max_size(), length_error is thrown. The value of the 1445e4b17023SJohn Marino * string doesn't change if an error is thrown. 1446e4b17023SJohn Marino */ 1447e4b17023SJohn Marino basic_string& 1448e4b17023SJohn Marino replace(size_type __pos1, size_type __n1, const basic_string& __str, 1449e4b17023SJohn Marino size_type __pos2, size_type __n2) 1450e4b17023SJohn Marino { return this->replace(__pos1, __n1, __str._M_data() 1451e4b17023SJohn Marino + __str._M_check(__pos2, "basic_string::replace"), 1452e4b17023SJohn Marino __str._M_limit(__pos2, __n2)); } 1453e4b17023SJohn Marino 1454e4b17023SJohn Marino /** 1455e4b17023SJohn Marino * @brief Replace characters with value of a C substring. 1456e4b17023SJohn Marino * @param __pos Index of first character to replace. 1457e4b17023SJohn Marino * @param __n1 Number of characters to be replaced. 1458e4b17023SJohn Marino * @param __s C string to insert. 1459e4b17023SJohn Marino * @param __n2 Number of characters from @a s to use. 1460e4b17023SJohn Marino * @return Reference to this string. 1461e4b17023SJohn Marino * @throw std::out_of_range If @a pos1 > size(). 1462e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1463e4b17023SJohn Marino * 1464e4b17023SJohn Marino * Removes the characters in the range [__pos,__pos + __n1) 1465e4b17023SJohn Marino * from this string. In place, the first @a __n2 characters of 1466e4b17023SJohn Marino * @a __s are inserted, or all of @a __s if @a __n2 is too large. If 1467e4b17023SJohn Marino * @a __pos is beyond end of string, out_of_range is thrown. If 1468e4b17023SJohn Marino * the length of result exceeds max_size(), length_error is 1469e4b17023SJohn Marino * thrown. The value of the string doesn't change if an error 1470e4b17023SJohn Marino * is thrown. 1471e4b17023SJohn Marino */ 1472e4b17023SJohn Marino basic_string& 1473e4b17023SJohn Marino replace(size_type __pos, size_type __n1, const _CharT* __s, 1474e4b17023SJohn Marino size_type __n2); 1475e4b17023SJohn Marino 1476e4b17023SJohn Marino /** 1477e4b17023SJohn Marino * @brief Replace characters with value of a C string. 1478e4b17023SJohn Marino * @param __pos Index of first character to replace. 1479e4b17023SJohn Marino * @param __n1 Number of characters to be replaced. 1480e4b17023SJohn Marino * @param __s C string to insert. 1481e4b17023SJohn Marino * @return Reference to this string. 1482e4b17023SJohn Marino * @throw std::out_of_range If @a pos > size(). 1483e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1484e4b17023SJohn Marino * 1485e4b17023SJohn Marino * Removes the characters in the range [__pos,__pos + __n1) 1486e4b17023SJohn Marino * from this string. In place, the characters of @a __s are 1487e4b17023SJohn Marino * inserted. If @a __pos is beyond end of string, out_of_range 1488e4b17023SJohn Marino * is thrown. If the length of result exceeds max_size(), 1489e4b17023SJohn Marino * length_error is thrown. The value of the string doesn't 1490e4b17023SJohn Marino * change if an error is thrown. 1491e4b17023SJohn Marino */ 1492e4b17023SJohn Marino basic_string& 1493e4b17023SJohn Marino replace(size_type __pos, size_type __n1, const _CharT* __s) 1494e4b17023SJohn Marino { 1495e4b17023SJohn Marino __glibcxx_requires_string(__s); 1496e4b17023SJohn Marino return this->replace(__pos, __n1, __s, traits_type::length(__s)); 1497e4b17023SJohn Marino } 1498e4b17023SJohn Marino 1499e4b17023SJohn Marino /** 1500e4b17023SJohn Marino * @brief Replace characters with multiple characters. 1501e4b17023SJohn Marino * @param __pos Index of first character to replace. 1502e4b17023SJohn Marino * @param __n1 Number of characters to be replaced. 1503e4b17023SJohn Marino * @param __n2 Number of characters to insert. 1504e4b17023SJohn Marino * @param __c Character to insert. 1505e4b17023SJohn Marino * @return Reference to this string. 1506e4b17023SJohn Marino * @throw std::out_of_range If @a __pos > size(). 1507e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1508e4b17023SJohn Marino * 1509e4b17023SJohn Marino * Removes the characters in the range [pos,pos + n1) from this 1510e4b17023SJohn Marino * string. In place, @a __n2 copies of @a __c are inserted. 1511e4b17023SJohn Marino * If @a __pos is beyond end of string, out_of_range is thrown. 1512e4b17023SJohn Marino * If the length of result exceeds max_size(), length_error is 1513e4b17023SJohn Marino * thrown. The value of the string doesn't change if an error 1514e4b17023SJohn Marino * is thrown. 1515e4b17023SJohn Marino */ 1516e4b17023SJohn Marino basic_string& 1517e4b17023SJohn Marino replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) 1518e4b17023SJohn Marino { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), 1519e4b17023SJohn Marino _M_limit(__pos, __n1), __n2, __c); } 1520e4b17023SJohn Marino 1521e4b17023SJohn Marino /** 1522e4b17023SJohn Marino * @brief Replace range of characters with string. 1523e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace. 1524e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace. 1525e4b17023SJohn Marino * @param __str String value to insert. 1526e4b17023SJohn Marino * @return Reference to this string. 1527e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1528e4b17023SJohn Marino * 1529e4b17023SJohn Marino * Removes the characters in the range [__i1,__i2). In place, 1530e4b17023SJohn Marino * the value of @a __str is inserted. If the length of result 1531e4b17023SJohn Marino * exceeds max_size(), length_error is thrown. The value of 1532e4b17023SJohn Marino * the string doesn't change if an error is thrown. 1533e4b17023SJohn Marino */ 1534e4b17023SJohn Marino basic_string& 1535e4b17023SJohn Marino replace(iterator __i1, iterator __i2, const basic_string& __str) 1536e4b17023SJohn Marino { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } 1537e4b17023SJohn Marino 1538e4b17023SJohn Marino /** 1539e4b17023SJohn Marino * @brief Replace range of characters with C substring. 1540e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace. 1541e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace. 1542e4b17023SJohn Marino * @param __s C string value to insert. 1543e4b17023SJohn Marino * @param __n Number of characters from s to insert. 1544e4b17023SJohn Marino * @return Reference to this string. 1545e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1546e4b17023SJohn Marino * 1547e4b17023SJohn Marino * Removes the characters in the range [__i1,__i2). In place, 1548e4b17023SJohn Marino * the first @a __n characters of @a __s are inserted. If the 1549e4b17023SJohn Marino * length of result exceeds max_size(), length_error is thrown. 1550e4b17023SJohn Marino * The value of the string doesn't change if an error is 1551e4b17023SJohn Marino * thrown. 1552e4b17023SJohn Marino */ 1553e4b17023SJohn Marino basic_string& 1554e4b17023SJohn Marino replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) 1555e4b17023SJohn Marino { 1556e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1557e4b17023SJohn Marino && __i2 <= _M_iend()); 1558e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); 1559e4b17023SJohn Marino } 1560e4b17023SJohn Marino 1561e4b17023SJohn Marino /** 1562e4b17023SJohn Marino * @brief Replace range of characters with C string. 1563e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace. 1564e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace. 1565e4b17023SJohn Marino * @param __s C string value to insert. 1566e4b17023SJohn Marino * @return Reference to this string. 1567e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1568e4b17023SJohn Marino * 1569e4b17023SJohn Marino * Removes the characters in the range [__i1,__i2). In place, 1570e4b17023SJohn Marino * the characters of @a __s are inserted. If the length of 1571e4b17023SJohn Marino * result exceeds max_size(), length_error is thrown. The 1572e4b17023SJohn Marino * value of the string doesn't change if an error is thrown. 1573e4b17023SJohn Marino */ 1574e4b17023SJohn Marino basic_string& 1575e4b17023SJohn Marino replace(iterator __i1, iterator __i2, const _CharT* __s) 1576e4b17023SJohn Marino { 1577e4b17023SJohn Marino __glibcxx_requires_string(__s); 1578e4b17023SJohn Marino return this->replace(__i1, __i2, __s, traits_type::length(__s)); 1579e4b17023SJohn Marino } 1580e4b17023SJohn Marino 1581e4b17023SJohn Marino /** 1582e4b17023SJohn Marino * @brief Replace range of characters with multiple characters 1583e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace. 1584e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace. 1585e4b17023SJohn Marino * @param __n Number of characters to insert. 1586e4b17023SJohn Marino * @param __c Character to insert. 1587e4b17023SJohn Marino * @return Reference to this string. 1588e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1589e4b17023SJohn Marino * 1590e4b17023SJohn Marino * Removes the characters in the range [__i1,__i2). In place, 1591e4b17023SJohn Marino * @a __n copies of @a __c are inserted. If the length of 1592e4b17023SJohn Marino * result exceeds max_size(), length_error is thrown. The 1593e4b17023SJohn Marino * value of the string doesn't change if an error is thrown. 1594e4b17023SJohn Marino */ 1595e4b17023SJohn Marino basic_string& 1596e4b17023SJohn Marino replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) 1597e4b17023SJohn Marino { 1598e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1599e4b17023SJohn Marino && __i2 <= _M_iend()); 1600e4b17023SJohn Marino return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); 1601e4b17023SJohn Marino } 1602e4b17023SJohn Marino 1603e4b17023SJohn Marino /** 1604e4b17023SJohn Marino * @brief Replace range of characters with range. 1605e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace. 1606e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace. 1607e4b17023SJohn Marino * @param __k1 Iterator referencing start of range to insert. 1608e4b17023SJohn Marino * @param __k2 Iterator referencing end of range to insert. 1609e4b17023SJohn Marino * @return Reference to this string. 1610e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1611e4b17023SJohn Marino * 1612e4b17023SJohn Marino * Removes the characters in the range [__i1,__i2). In place, 1613e4b17023SJohn Marino * characters in the range [__k1,__k2) are inserted. If the 1614e4b17023SJohn Marino * length of result exceeds max_size(), length_error is thrown. 1615e4b17023SJohn Marino * The value of the string doesn't change if an error is 1616e4b17023SJohn Marino * thrown. 1617e4b17023SJohn Marino */ 1618e4b17023SJohn Marino template<class _InputIterator> 1619e4b17023SJohn Marino basic_string& 1620e4b17023SJohn Marino replace(iterator __i1, iterator __i2, 1621e4b17023SJohn Marino _InputIterator __k1, _InputIterator __k2) 1622e4b17023SJohn Marino { 1623e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1624e4b17023SJohn Marino && __i2 <= _M_iend()); 1625e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2); 1626e4b17023SJohn Marino typedef typename std::__is_integer<_InputIterator>::__type _Integral; 1627e4b17023SJohn Marino return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); 1628e4b17023SJohn Marino } 1629e4b17023SJohn Marino 1630e4b17023SJohn Marino // Specializations for the common case of pointer and iterator: 1631e4b17023SJohn Marino // useful to avoid the overhead of temporary buffering in _M_replace. 1632e4b17023SJohn Marino basic_string& 1633e4b17023SJohn Marino replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) 1634e4b17023SJohn Marino { 1635e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1636e4b17023SJohn Marino && __i2 <= _M_iend()); 1637e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2); 1638e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1639e4b17023SJohn Marino __k1, __k2 - __k1); 1640e4b17023SJohn Marino } 1641e4b17023SJohn Marino 1642e4b17023SJohn Marino basic_string& 1643e4b17023SJohn Marino replace(iterator __i1, iterator __i2, 1644e4b17023SJohn Marino const _CharT* __k1, const _CharT* __k2) 1645e4b17023SJohn Marino { 1646e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1647e4b17023SJohn Marino && __i2 <= _M_iend()); 1648e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2); 1649e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1650e4b17023SJohn Marino __k1, __k2 - __k1); 1651e4b17023SJohn Marino } 1652e4b17023SJohn Marino 1653e4b17023SJohn Marino basic_string& 1654e4b17023SJohn Marino replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) 1655e4b17023SJohn Marino { 1656e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1657e4b17023SJohn Marino && __i2 <= _M_iend()); 1658e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2); 1659e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1660e4b17023SJohn Marino __k1.base(), __k2 - __k1); 1661e4b17023SJohn Marino } 1662e4b17023SJohn Marino 1663e4b17023SJohn Marino basic_string& 1664e4b17023SJohn Marino replace(iterator __i1, iterator __i2, 1665e4b17023SJohn Marino const_iterator __k1, const_iterator __k2) 1666e4b17023SJohn Marino { 1667e4b17023SJohn Marino _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1668e4b17023SJohn Marino && __i2 <= _M_iend()); 1669e4b17023SJohn Marino __glibcxx_requires_valid_range(__k1, __k2); 1670e4b17023SJohn Marino return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1671e4b17023SJohn Marino __k1.base(), __k2 - __k1); 1672e4b17023SJohn Marino } 1673e4b17023SJohn Marino 1674e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 1675e4b17023SJohn Marino /** 1676e4b17023SJohn Marino * @brief Replace range of characters with initializer_list. 1677e4b17023SJohn Marino * @param __i1 Iterator referencing start of range to replace. 1678e4b17023SJohn Marino * @param __i2 Iterator referencing end of range to replace. 1679e4b17023SJohn Marino * @param __l The initializer_list of characters to insert. 1680e4b17023SJohn Marino * @return Reference to this string. 1681e4b17023SJohn Marino * @throw std::length_error If new length exceeds @c max_size(). 1682e4b17023SJohn Marino * 1683e4b17023SJohn Marino * Removes the characters in the range [__i1,__i2). In place, 1684e4b17023SJohn Marino * characters in the range [__k1,__k2) are inserted. If the 1685e4b17023SJohn Marino * length of result exceeds max_size(), length_error is thrown. 1686e4b17023SJohn Marino * The value of the string doesn't change if an error is 1687e4b17023SJohn Marino * thrown. 1688e4b17023SJohn Marino */ 1689e4b17023SJohn Marino basic_string& replace(iterator __i1, iterator __i2, 1690e4b17023SJohn Marino initializer_list<_CharT> __l) 1691e4b17023SJohn Marino { return this->replace(__i1, __i2, __l.begin(), __l.end()); } 1692e4b17023SJohn Marino #endif // __GXX_EXPERIMENTAL_CXX0X__ 1693e4b17023SJohn Marino 1694e4b17023SJohn Marino private: 1695e4b17023SJohn Marino template<class _Integer> 1696e4b17023SJohn Marino basic_string& 1697e4b17023SJohn Marino _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n, 1698e4b17023SJohn Marino _Integer __val, __true_type) 1699e4b17023SJohn Marino { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } 1700e4b17023SJohn Marino 1701e4b17023SJohn Marino template<class _InputIterator> 1702e4b17023SJohn Marino basic_string& 1703e4b17023SJohn Marino _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1, 1704e4b17023SJohn Marino _InputIterator __k2, __false_type); 1705e4b17023SJohn Marino 1706e4b17023SJohn Marino basic_string& 1707e4b17023SJohn Marino _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, 1708e4b17023SJohn Marino _CharT __c); 1709e4b17023SJohn Marino 1710e4b17023SJohn Marino basic_string& 1711e4b17023SJohn Marino _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s, 1712e4b17023SJohn Marino size_type __n2); 1713e4b17023SJohn Marino 1714e4b17023SJohn Marino // _S_construct_aux is used to implement the 21.3.1 para 15 which 1715e4b17023SJohn Marino // requires special behaviour if _InIter is an integral type 1716e4b17023SJohn Marino template<class _InIterator> 1717e4b17023SJohn Marino static _CharT* 1718e4b17023SJohn Marino _S_construct_aux(_InIterator __beg, _InIterator __end, 1719e4b17023SJohn Marino const _Alloc& __a, __false_type) 1720e4b17023SJohn Marino { 1721e4b17023SJohn Marino typedef typename iterator_traits<_InIterator>::iterator_category _Tag; 1722e4b17023SJohn Marino return _S_construct(__beg, __end, __a, _Tag()); 1723e4b17023SJohn Marino } 1724e4b17023SJohn Marino 1725e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 1726e4b17023SJohn Marino // 438. Ambiguity in the "do the right thing" clause 1727e4b17023SJohn Marino template<class _Integer> 1728e4b17023SJohn Marino static _CharT* 1729e4b17023SJohn Marino _S_construct_aux(_Integer __beg, _Integer __end, 1730e4b17023SJohn Marino const _Alloc& __a, __true_type) 1731e4b17023SJohn Marino { return _S_construct_aux_2(static_cast<size_type>(__beg), 1732e4b17023SJohn Marino __end, __a); } 1733e4b17023SJohn Marino 1734e4b17023SJohn Marino static _CharT* 1735e4b17023SJohn Marino _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a) 1736e4b17023SJohn Marino { return _S_construct(__req, __c, __a); } 1737e4b17023SJohn Marino 1738e4b17023SJohn Marino template<class _InIterator> 1739e4b17023SJohn Marino static _CharT* 1740e4b17023SJohn Marino _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a) 1741e4b17023SJohn Marino { 1742e4b17023SJohn Marino typedef typename std::__is_integer<_InIterator>::__type _Integral; 1743e4b17023SJohn Marino return _S_construct_aux(__beg, __end, __a, _Integral()); 1744e4b17023SJohn Marino } 1745e4b17023SJohn Marino 1746e4b17023SJohn Marino // For Input Iterators, used in istreambuf_iterators, etc. 1747e4b17023SJohn Marino template<class _InIterator> 1748e4b17023SJohn Marino static _CharT* 1749e4b17023SJohn Marino _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, 1750e4b17023SJohn Marino input_iterator_tag); 1751e4b17023SJohn Marino 1752e4b17023SJohn Marino // For forward_iterators up to random_access_iterators, used for 1753e4b17023SJohn Marino // string::iterator, _CharT*, etc. 1754e4b17023SJohn Marino template<class _FwdIterator> 1755e4b17023SJohn Marino static _CharT* 1756e4b17023SJohn Marino _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a, 1757e4b17023SJohn Marino forward_iterator_tag); 1758e4b17023SJohn Marino 1759e4b17023SJohn Marino static _CharT* 1760e4b17023SJohn Marino _S_construct(size_type __req, _CharT __c, const _Alloc& __a); 1761e4b17023SJohn Marino 1762e4b17023SJohn Marino public: 1763e4b17023SJohn Marino 1764e4b17023SJohn Marino /** 1765e4b17023SJohn Marino * @brief Copy substring into C string. 1766e4b17023SJohn Marino * @param __s C string to copy value into. 1767e4b17023SJohn Marino * @param __n Number of characters to copy. 1768e4b17023SJohn Marino * @param __pos Index of first character to copy. 1769e4b17023SJohn Marino * @return Number of characters actually copied 1770e4b17023SJohn Marino * @throw std::out_of_range If __pos > size(). 1771e4b17023SJohn Marino * 1772e4b17023SJohn Marino * Copies up to @a __n characters starting at @a __pos into the 1773e4b17023SJohn Marino * C string @a __s. If @a __pos is %greater than size(), 1774e4b17023SJohn Marino * out_of_range is thrown. 1775e4b17023SJohn Marino */ 1776e4b17023SJohn Marino size_type 1777e4b17023SJohn Marino copy(_CharT* __s, size_type __n, size_type __pos = 0) const; 1778e4b17023SJohn Marino 1779e4b17023SJohn Marino /** 1780e4b17023SJohn Marino * @brief Swap contents with another string. 1781e4b17023SJohn Marino * @param __s String to swap with. 1782e4b17023SJohn Marino * 1783e4b17023SJohn Marino * Exchanges the contents of this string with that of @a __s in constant 1784e4b17023SJohn Marino * time. 1785e4b17023SJohn Marino */ 1786e4b17023SJohn Marino void 1787e4b17023SJohn Marino swap(basic_string& __s); 1788e4b17023SJohn Marino 1789e4b17023SJohn Marino // String operations: 1790e4b17023SJohn Marino /** 1791e4b17023SJohn Marino * @brief Return const pointer to null-terminated contents. 1792e4b17023SJohn Marino * 1793e4b17023SJohn Marino * This is a handle to internal data. Do not modify or dire things may 1794e4b17023SJohn Marino * happen. 1795e4b17023SJohn Marino */ 1796e4b17023SJohn Marino const _CharT* 1797e4b17023SJohn Marino c_str() const _GLIBCXX_NOEXCEPT 1798e4b17023SJohn Marino { return _M_data(); } 1799e4b17023SJohn Marino 1800e4b17023SJohn Marino /** 1801e4b17023SJohn Marino * @brief Return const pointer to contents. 1802e4b17023SJohn Marino * 1803e4b17023SJohn Marino * This is a handle to internal data. Do not modify or dire things may 1804e4b17023SJohn Marino * happen. 1805e4b17023SJohn Marino */ 1806e4b17023SJohn Marino const _CharT* 1807e4b17023SJohn Marino data() const _GLIBCXX_NOEXCEPT 1808e4b17023SJohn Marino { return _M_data(); } 1809e4b17023SJohn Marino 1810e4b17023SJohn Marino /** 1811e4b17023SJohn Marino * @brief Return copy of allocator used to construct this string. 1812e4b17023SJohn Marino */ 1813e4b17023SJohn Marino allocator_type 1814e4b17023SJohn Marino get_allocator() const _GLIBCXX_NOEXCEPT 1815e4b17023SJohn Marino { return _M_dataplus; } 1816e4b17023SJohn Marino 1817e4b17023SJohn Marino /** 1818e4b17023SJohn Marino * @brief Find position of a C substring. 1819e4b17023SJohn Marino * @param __s C string to locate. 1820e4b17023SJohn Marino * @param __pos Index of character to search from. 1821e4b17023SJohn Marino * @param __n Number of characters from @a s to search for. 1822e4b17023SJohn Marino * @return Index of start of first occurrence. 1823e4b17023SJohn Marino * 1824e4b17023SJohn Marino * Starting from @a __pos, searches forward for the first @a 1825e4b17023SJohn Marino * __n characters in @a __s within this string. If found, 1826e4b17023SJohn Marino * returns the index where it begins. If not found, returns 1827e4b17023SJohn Marino * npos. 1828e4b17023SJohn Marino */ 1829e4b17023SJohn Marino size_type 1830e4b17023SJohn Marino find(const _CharT* __s, size_type __pos, size_type __n) const; 1831e4b17023SJohn Marino 1832e4b17023SJohn Marino /** 1833e4b17023SJohn Marino * @brief Find position of a string. 1834e4b17023SJohn Marino * @param __str String to locate. 1835e4b17023SJohn Marino * @param __pos Index of character to search from (default 0). 1836e4b17023SJohn Marino * @return Index of start of first occurrence. 1837e4b17023SJohn Marino * 1838e4b17023SJohn Marino * Starting from @a __pos, searches forward for value of @a __str within 1839e4b17023SJohn Marino * this string. If found, returns the index where it begins. If not 1840e4b17023SJohn Marino * found, returns npos. 1841e4b17023SJohn Marino */ 1842e4b17023SJohn Marino size_type 1843e4b17023SJohn Marino find(const basic_string& __str, size_type __pos = 0) const 1844e4b17023SJohn Marino _GLIBCXX_NOEXCEPT 1845e4b17023SJohn Marino { return this->find(__str.data(), __pos, __str.size()); } 1846e4b17023SJohn Marino 1847e4b17023SJohn Marino /** 1848e4b17023SJohn Marino * @brief Find position of a C string. 1849e4b17023SJohn Marino * @param __s C string to locate. 1850e4b17023SJohn Marino * @param __pos Index of character to search from (default 0). 1851e4b17023SJohn Marino * @return Index of start of first occurrence. 1852e4b17023SJohn Marino * 1853e4b17023SJohn Marino * Starting from @a __pos, searches forward for the value of @a 1854e4b17023SJohn Marino * __s within this string. If found, returns the index where 1855e4b17023SJohn Marino * it begins. If not found, returns npos. 1856e4b17023SJohn Marino */ 1857e4b17023SJohn Marino size_type 1858e4b17023SJohn Marino find(const _CharT* __s, size_type __pos = 0) const 1859e4b17023SJohn Marino { 1860e4b17023SJohn Marino __glibcxx_requires_string(__s); 1861e4b17023SJohn Marino return this->find(__s, __pos, traits_type::length(__s)); 1862e4b17023SJohn Marino } 1863e4b17023SJohn Marino 1864e4b17023SJohn Marino /** 1865e4b17023SJohn Marino * @brief Find position of a character. 1866e4b17023SJohn Marino * @param __c Character to locate. 1867e4b17023SJohn Marino * @param __pos Index of character to search from (default 0). 1868e4b17023SJohn Marino * @return Index of first occurrence. 1869e4b17023SJohn Marino * 1870e4b17023SJohn Marino * Starting from @a __pos, searches forward for @a __c within 1871e4b17023SJohn Marino * this string. If found, returns the index where it was 1872e4b17023SJohn Marino * found. If not found, returns npos. 1873e4b17023SJohn Marino */ 1874e4b17023SJohn Marino size_type 1875e4b17023SJohn Marino find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; 1876e4b17023SJohn Marino 1877e4b17023SJohn Marino /** 1878e4b17023SJohn Marino * @brief Find last position of a string. 1879e4b17023SJohn Marino * @param __str String to locate. 1880e4b17023SJohn Marino * @param __pos Index of character to search back from (default end). 1881e4b17023SJohn Marino * @return Index of start of last occurrence. 1882e4b17023SJohn Marino * 1883e4b17023SJohn Marino * Starting from @a __pos, searches backward for value of @a 1884e4b17023SJohn Marino * __str within this string. If found, returns the index where 1885e4b17023SJohn Marino * it begins. If not found, returns npos. 1886e4b17023SJohn Marino */ 1887e4b17023SJohn Marino size_type 1888e4b17023SJohn Marino rfind(const basic_string& __str, size_type __pos = npos) const 1889e4b17023SJohn Marino _GLIBCXX_NOEXCEPT 1890e4b17023SJohn Marino { return this->rfind(__str.data(), __pos, __str.size()); } 1891e4b17023SJohn Marino 1892e4b17023SJohn Marino /** 1893e4b17023SJohn Marino * @brief Find last position of a C substring. 1894e4b17023SJohn Marino * @param __s C string to locate. 1895e4b17023SJohn Marino * @param __pos Index of character to search back from. 1896e4b17023SJohn Marino * @param __n Number of characters from s to search for. 1897e4b17023SJohn Marino * @return Index of start of last occurrence. 1898e4b17023SJohn Marino * 1899e4b17023SJohn Marino * Starting from @a __pos, searches backward for the first @a 1900e4b17023SJohn Marino * __n characters in @a __s within this string. If found, 1901e4b17023SJohn Marino * returns the index where it begins. If not found, returns 1902e4b17023SJohn Marino * npos. 1903e4b17023SJohn Marino */ 1904e4b17023SJohn Marino size_type 1905e4b17023SJohn Marino rfind(const _CharT* __s, size_type __pos, size_type __n) const; 1906e4b17023SJohn Marino 1907e4b17023SJohn Marino /** 1908e4b17023SJohn Marino * @brief Find last position of a C string. 1909e4b17023SJohn Marino * @param __s C string to locate. 1910e4b17023SJohn Marino * @param __pos Index of character to start search at (default end). 1911e4b17023SJohn Marino * @return Index of start of last occurrence. 1912e4b17023SJohn Marino * 1913e4b17023SJohn Marino * Starting from @a __pos, searches backward for the value of 1914e4b17023SJohn Marino * @a __s within this string. If found, returns the index 1915e4b17023SJohn Marino * where it begins. If not found, returns npos. 1916e4b17023SJohn Marino */ 1917e4b17023SJohn Marino size_type 1918e4b17023SJohn Marino rfind(const _CharT* __s, size_type __pos = npos) const 1919e4b17023SJohn Marino { 1920e4b17023SJohn Marino __glibcxx_requires_string(__s); 1921e4b17023SJohn Marino return this->rfind(__s, __pos, traits_type::length(__s)); 1922e4b17023SJohn Marino } 1923e4b17023SJohn Marino 1924e4b17023SJohn Marino /** 1925e4b17023SJohn Marino * @brief Find last position of a character. 1926e4b17023SJohn Marino * @param __c Character to locate. 1927e4b17023SJohn Marino * @param __pos Index of character to search back from (default end). 1928e4b17023SJohn Marino * @return Index of last occurrence. 1929e4b17023SJohn Marino * 1930e4b17023SJohn Marino * Starting from @a __pos, searches backward for @a __c within 1931e4b17023SJohn Marino * this string. If found, returns the index where it was 1932e4b17023SJohn Marino * found. If not found, returns npos. 1933e4b17023SJohn Marino */ 1934e4b17023SJohn Marino size_type 1935e4b17023SJohn Marino rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; 1936e4b17023SJohn Marino 1937e4b17023SJohn Marino /** 1938e4b17023SJohn Marino * @brief Find position of a character of string. 1939e4b17023SJohn Marino * @param __str String containing characters to locate. 1940e4b17023SJohn Marino * @param __pos Index of character to search from (default 0). 1941e4b17023SJohn Marino * @return Index of first occurrence. 1942e4b17023SJohn Marino * 1943e4b17023SJohn Marino * Starting from @a __pos, searches forward for one of the 1944e4b17023SJohn Marino * characters of @a __str within this string. If found, 1945e4b17023SJohn Marino * returns the index where it was found. If not found, returns 1946e4b17023SJohn Marino * npos. 1947e4b17023SJohn Marino */ 1948e4b17023SJohn Marino size_type 1949e4b17023SJohn Marino find_first_of(const basic_string& __str, size_type __pos = 0) const 1950e4b17023SJohn Marino _GLIBCXX_NOEXCEPT 1951e4b17023SJohn Marino { return this->find_first_of(__str.data(), __pos, __str.size()); } 1952e4b17023SJohn Marino 1953e4b17023SJohn Marino /** 1954e4b17023SJohn Marino * @brief Find position of a character of C substring. 1955e4b17023SJohn Marino * @param __s String containing characters to locate. 1956e4b17023SJohn Marino * @param __pos Index of character to search from. 1957e4b17023SJohn Marino * @param __n Number of characters from s to search for. 1958e4b17023SJohn Marino * @return Index of first occurrence. 1959e4b17023SJohn Marino * 1960e4b17023SJohn Marino * Starting from @a __pos, searches forward for one of the 1961e4b17023SJohn Marino * first @a __n characters of @a __s within this string. If 1962e4b17023SJohn Marino * found, returns the index where it was found. If not found, 1963e4b17023SJohn Marino * returns npos. 1964e4b17023SJohn Marino */ 1965e4b17023SJohn Marino size_type 1966e4b17023SJohn Marino find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; 1967e4b17023SJohn Marino 1968e4b17023SJohn Marino /** 1969e4b17023SJohn Marino * @brief Find position of a character of C string. 1970e4b17023SJohn Marino * @param __s String containing characters to locate. 1971e4b17023SJohn Marino * @param __pos Index of character to search from (default 0). 1972e4b17023SJohn Marino * @return Index of first occurrence. 1973e4b17023SJohn Marino * 1974e4b17023SJohn Marino * Starting from @a __pos, searches forward for one of the 1975e4b17023SJohn Marino * characters of @a __s within this string. If found, returns 1976e4b17023SJohn Marino * the index where it was found. If not found, returns npos. 1977e4b17023SJohn Marino */ 1978e4b17023SJohn Marino size_type 1979e4b17023SJohn Marino find_first_of(const _CharT* __s, size_type __pos = 0) const 1980e4b17023SJohn Marino { 1981e4b17023SJohn Marino __glibcxx_requires_string(__s); 1982e4b17023SJohn Marino return this->find_first_of(__s, __pos, traits_type::length(__s)); 1983e4b17023SJohn Marino } 1984e4b17023SJohn Marino 1985e4b17023SJohn Marino /** 1986e4b17023SJohn Marino * @brief Find position of a character. 1987e4b17023SJohn Marino * @param __c Character to locate. 1988e4b17023SJohn Marino * @param __pos Index of character to search from (default 0). 1989e4b17023SJohn Marino * @return Index of first occurrence. 1990e4b17023SJohn Marino * 1991e4b17023SJohn Marino * Starting from @a __pos, searches forward for the character 1992e4b17023SJohn Marino * @a __c within this string. If found, returns the index 1993e4b17023SJohn Marino * where it was found. If not found, returns npos. 1994e4b17023SJohn Marino * 1995e4b17023SJohn Marino * Note: equivalent to find(__c, __pos). 1996e4b17023SJohn Marino */ 1997e4b17023SJohn Marino size_type 1998e4b17023SJohn Marino find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 1999e4b17023SJohn Marino { return this->find(__c, __pos); } 2000e4b17023SJohn Marino 2001e4b17023SJohn Marino /** 2002e4b17023SJohn Marino * @brief Find last position of a character of string. 2003e4b17023SJohn Marino * @param __str String containing characters to locate. 2004e4b17023SJohn Marino * @param __pos Index of character to search back from (default end). 2005e4b17023SJohn Marino * @return Index of last occurrence. 2006e4b17023SJohn Marino * 2007e4b17023SJohn Marino * Starting from @a __pos, searches backward for one of the 2008e4b17023SJohn Marino * characters of @a __str within this string. If found, 2009e4b17023SJohn Marino * returns the index where it was found. If not found, returns 2010e4b17023SJohn Marino * npos. 2011e4b17023SJohn Marino */ 2012e4b17023SJohn Marino size_type 2013e4b17023SJohn Marino find_last_of(const basic_string& __str, size_type __pos = npos) const 2014e4b17023SJohn Marino _GLIBCXX_NOEXCEPT 2015e4b17023SJohn Marino { return this->find_last_of(__str.data(), __pos, __str.size()); } 2016e4b17023SJohn Marino 2017e4b17023SJohn Marino /** 2018e4b17023SJohn Marino * @brief Find last position of a character of C substring. 2019e4b17023SJohn Marino * @param __s C string containing characters to locate. 2020e4b17023SJohn Marino * @param __pos Index of character to search back from. 2021e4b17023SJohn Marino * @param __n Number of characters from s to search for. 2022e4b17023SJohn Marino * @return Index of last occurrence. 2023e4b17023SJohn Marino * 2024e4b17023SJohn Marino * Starting from @a __pos, searches backward for one of the 2025e4b17023SJohn Marino * first @a __n characters of @a __s within this string. If 2026e4b17023SJohn Marino * found, returns the index where it was found. If not found, 2027e4b17023SJohn Marino * returns npos. 2028e4b17023SJohn Marino */ 2029e4b17023SJohn Marino size_type 2030e4b17023SJohn Marino find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; 2031e4b17023SJohn Marino 2032e4b17023SJohn Marino /** 2033e4b17023SJohn Marino * @brief Find last position of a character of C string. 2034e4b17023SJohn Marino * @param __s C string containing characters to locate. 2035e4b17023SJohn Marino * @param __pos Index of character to search back from (default end). 2036e4b17023SJohn Marino * @return Index of last occurrence. 2037e4b17023SJohn Marino * 2038e4b17023SJohn Marino * Starting from @a __pos, searches backward for one of the 2039e4b17023SJohn Marino * characters of @a __s within this string. If found, returns 2040e4b17023SJohn Marino * the index where it was found. If not found, returns npos. 2041e4b17023SJohn Marino */ 2042e4b17023SJohn Marino size_type 2043e4b17023SJohn Marino find_last_of(const _CharT* __s, size_type __pos = npos) const 2044e4b17023SJohn Marino { 2045e4b17023SJohn Marino __glibcxx_requires_string(__s); 2046e4b17023SJohn Marino return this->find_last_of(__s, __pos, traits_type::length(__s)); 2047e4b17023SJohn Marino } 2048e4b17023SJohn Marino 2049e4b17023SJohn Marino /** 2050e4b17023SJohn Marino * @brief Find last position of a character. 2051e4b17023SJohn Marino * @param __c Character to locate. 2052e4b17023SJohn Marino * @param __pos Index of character to search back from (default end). 2053e4b17023SJohn Marino * @return Index of last occurrence. 2054e4b17023SJohn Marino * 2055e4b17023SJohn Marino * Starting from @a __pos, searches backward for @a __c within 2056e4b17023SJohn Marino * this string. If found, returns the index where it was 2057e4b17023SJohn Marino * found. If not found, returns npos. 2058e4b17023SJohn Marino * 2059e4b17023SJohn Marino * Note: equivalent to rfind(__c, __pos). 2060e4b17023SJohn Marino */ 2061e4b17023SJohn Marino size_type 2062e4b17023SJohn Marino find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT 2063e4b17023SJohn Marino { return this->rfind(__c, __pos); } 2064e4b17023SJohn Marino 2065e4b17023SJohn Marino /** 2066e4b17023SJohn Marino * @brief Find position of a character not in string. 2067e4b17023SJohn Marino * @param __str String containing characters to avoid. 2068e4b17023SJohn Marino * @param __pos Index of character to search from (default 0). 2069e4b17023SJohn Marino * @return Index of first occurrence. 2070e4b17023SJohn Marino * 2071e4b17023SJohn Marino * Starting from @a __pos, searches forward for a character not contained 2072e4b17023SJohn Marino * in @a __str within this string. If found, returns the index where it 2073e4b17023SJohn Marino * was found. If not found, returns npos. 2074e4b17023SJohn Marino */ 2075e4b17023SJohn Marino size_type 2076e4b17023SJohn Marino find_first_not_of(const basic_string& __str, size_type __pos = 0) const 2077e4b17023SJohn Marino _GLIBCXX_NOEXCEPT 2078e4b17023SJohn Marino { return this->find_first_not_of(__str.data(), __pos, __str.size()); } 2079e4b17023SJohn Marino 2080e4b17023SJohn Marino /** 2081e4b17023SJohn Marino * @brief Find position of a character not in C substring. 2082e4b17023SJohn Marino * @param __s C string containing characters to avoid. 2083e4b17023SJohn Marino * @param __pos Index of character to search from. 2084e4b17023SJohn Marino * @param __n Number of characters from __s to consider. 2085e4b17023SJohn Marino * @return Index of first occurrence. 2086e4b17023SJohn Marino * 2087e4b17023SJohn Marino * Starting from @a __pos, searches forward for a character not 2088e4b17023SJohn Marino * contained in the first @a __n characters of @a __s within 2089e4b17023SJohn Marino * this string. If found, returns the index where it was 2090e4b17023SJohn Marino * found. If not found, returns npos. 2091e4b17023SJohn Marino */ 2092e4b17023SJohn Marino size_type 2093e4b17023SJohn Marino find_first_not_of(const _CharT* __s, size_type __pos, 2094e4b17023SJohn Marino size_type __n) const; 2095e4b17023SJohn Marino 2096e4b17023SJohn Marino /** 2097e4b17023SJohn Marino * @brief Find position of a character not in C string. 2098e4b17023SJohn Marino * @param __s C string containing characters to avoid. 2099e4b17023SJohn Marino * @param __pos Index of character to search from (default 0). 2100e4b17023SJohn Marino * @return Index of first occurrence. 2101e4b17023SJohn Marino * 2102e4b17023SJohn Marino * Starting from @a __pos, searches forward for a character not 2103e4b17023SJohn Marino * contained in @a __s within this string. If found, returns 2104e4b17023SJohn Marino * the index where it was found. If not found, returns npos. 2105e4b17023SJohn Marino */ 2106e4b17023SJohn Marino size_type 2107e4b17023SJohn Marino find_first_not_of(const _CharT* __s, size_type __pos = 0) const 2108e4b17023SJohn Marino { 2109e4b17023SJohn Marino __glibcxx_requires_string(__s); 2110e4b17023SJohn Marino return this->find_first_not_of(__s, __pos, traits_type::length(__s)); 2111e4b17023SJohn Marino } 2112e4b17023SJohn Marino 2113e4b17023SJohn Marino /** 2114e4b17023SJohn Marino * @brief Find position of a different character. 2115e4b17023SJohn Marino * @param __c Character to avoid. 2116e4b17023SJohn Marino * @param __pos Index of character to search from (default 0). 2117e4b17023SJohn Marino * @return Index of first occurrence. 2118e4b17023SJohn Marino * 2119e4b17023SJohn Marino * Starting from @a __pos, searches forward for a character 2120e4b17023SJohn Marino * other than @a __c within this string. If found, returns the 2121e4b17023SJohn Marino * index where it was found. If not found, returns npos. 2122e4b17023SJohn Marino */ 2123e4b17023SJohn Marino size_type 2124e4b17023SJohn Marino find_first_not_of(_CharT __c, size_type __pos = 0) const 2125e4b17023SJohn Marino _GLIBCXX_NOEXCEPT; 2126e4b17023SJohn Marino 2127e4b17023SJohn Marino /** 2128e4b17023SJohn Marino * @brief Find last position of a character not in string. 2129e4b17023SJohn Marino * @param __str String containing characters to avoid. 2130e4b17023SJohn Marino * @param __pos Index of character to search back from (default end). 2131e4b17023SJohn Marino * @return Index of last occurrence. 2132e4b17023SJohn Marino * 2133e4b17023SJohn Marino * Starting from @a __pos, searches backward for a character 2134e4b17023SJohn Marino * not contained in @a __str within this string. If found, 2135e4b17023SJohn Marino * returns the index where it was found. If not found, returns 2136e4b17023SJohn Marino * npos. 2137e4b17023SJohn Marino */ 2138e4b17023SJohn Marino size_type 2139e4b17023SJohn Marino find_last_not_of(const basic_string& __str, size_type __pos = npos) const 2140e4b17023SJohn Marino _GLIBCXX_NOEXCEPT 2141e4b17023SJohn Marino { return this->find_last_not_of(__str.data(), __pos, __str.size()); } 2142e4b17023SJohn Marino 2143e4b17023SJohn Marino /** 2144e4b17023SJohn Marino * @brief Find last position of a character not in C substring. 2145e4b17023SJohn Marino * @param __s C string containing characters to avoid. 2146e4b17023SJohn Marino * @param __pos Index of character to search back from. 2147e4b17023SJohn Marino * @param __n Number of characters from s to consider. 2148e4b17023SJohn Marino * @return Index of last occurrence. 2149e4b17023SJohn Marino * 2150e4b17023SJohn Marino * Starting from @a __pos, searches backward for a character not 2151e4b17023SJohn Marino * contained in the first @a __n characters of @a __s within this string. 2152e4b17023SJohn Marino * If found, returns the index where it was found. If not found, 2153e4b17023SJohn Marino * returns npos. 2154e4b17023SJohn Marino */ 2155e4b17023SJohn Marino size_type 2156e4b17023SJohn Marino find_last_not_of(const _CharT* __s, size_type __pos, 2157e4b17023SJohn Marino size_type __n) const; 2158e4b17023SJohn Marino /** 2159e4b17023SJohn Marino * @brief Find last position of a character not in C string. 2160e4b17023SJohn Marino * @param __s C string containing characters to avoid. 2161e4b17023SJohn Marino * @param __pos Index of character to search back from (default end). 2162e4b17023SJohn Marino * @return Index of last occurrence. 2163e4b17023SJohn Marino * 2164e4b17023SJohn Marino * Starting from @a __pos, searches backward for a character 2165e4b17023SJohn Marino * not contained in @a __s within this string. If found, 2166e4b17023SJohn Marino * returns the index where it was found. If not found, returns 2167e4b17023SJohn Marino * npos. 2168e4b17023SJohn Marino */ 2169e4b17023SJohn Marino size_type 2170e4b17023SJohn Marino find_last_not_of(const _CharT* __s, size_type __pos = npos) const 2171e4b17023SJohn Marino { 2172e4b17023SJohn Marino __glibcxx_requires_string(__s); 2173e4b17023SJohn Marino return this->find_last_not_of(__s, __pos, traits_type::length(__s)); 2174e4b17023SJohn Marino } 2175e4b17023SJohn Marino 2176e4b17023SJohn Marino /** 2177e4b17023SJohn Marino * @brief Find last position of a different character. 2178e4b17023SJohn Marino * @param __c Character to avoid. 2179e4b17023SJohn Marino * @param __pos Index of character to search back from (default end). 2180e4b17023SJohn Marino * @return Index of last occurrence. 2181e4b17023SJohn Marino * 2182e4b17023SJohn Marino * Starting from @a __pos, searches backward for a character other than 2183e4b17023SJohn Marino * @a __c within this string. If found, returns the index where it was 2184e4b17023SJohn Marino * found. If not found, returns npos. 2185e4b17023SJohn Marino */ 2186e4b17023SJohn Marino size_type 2187e4b17023SJohn Marino find_last_not_of(_CharT __c, size_type __pos = npos) const 2188e4b17023SJohn Marino _GLIBCXX_NOEXCEPT; 2189e4b17023SJohn Marino 2190e4b17023SJohn Marino /** 2191e4b17023SJohn Marino * @brief Get a substring. 2192e4b17023SJohn Marino * @param __pos Index of first character (default 0). 2193e4b17023SJohn Marino * @param __n Number of characters in substring (default remainder). 2194e4b17023SJohn Marino * @return The new string. 2195e4b17023SJohn Marino * @throw std::out_of_range If __pos > size(). 2196e4b17023SJohn Marino * 2197e4b17023SJohn Marino * Construct and return a new string using the @a __n 2198e4b17023SJohn Marino * characters starting at @a __pos. If the string is too 2199e4b17023SJohn Marino * short, use the remainder of the characters. If @a __pos is 2200e4b17023SJohn Marino * beyond the end of the string, out_of_range is thrown. 2201e4b17023SJohn Marino */ 2202e4b17023SJohn Marino basic_string 2203e4b17023SJohn Marino substr(size_type __pos = 0, size_type __n = npos) const 2204e4b17023SJohn Marino { return basic_string(*this, 2205e4b17023SJohn Marino _M_check(__pos, "basic_string::substr"), __n); } 2206e4b17023SJohn Marino 2207e4b17023SJohn Marino /** 2208e4b17023SJohn Marino * @brief Compare to a string. 2209e4b17023SJohn Marino * @param __str String to compare against. 2210e4b17023SJohn Marino * @return Integer < 0, 0, or > 0. 2211e4b17023SJohn Marino * 2212e4b17023SJohn Marino * Returns an integer < 0 if this string is ordered before @a 2213e4b17023SJohn Marino * __str, 0 if their values are equivalent, or > 0 if this 2214e4b17023SJohn Marino * string is ordered after @a __str. Determines the effective 2215e4b17023SJohn Marino * length rlen of the strings to compare as the smallest of 2216e4b17023SJohn Marino * size() and str.size(). The function then compares the two 2217e4b17023SJohn Marino * strings by calling traits::compare(data(), str.data(),rlen). 2218e4b17023SJohn Marino * If the result of the comparison is nonzero returns it, 2219e4b17023SJohn Marino * otherwise the shorter one is ordered first. 2220e4b17023SJohn Marino */ 2221e4b17023SJohn Marino int 2222e4b17023SJohn Marino compare(const basic_string& __str) const 2223e4b17023SJohn Marino { 2224e4b17023SJohn Marino const size_type __size = this->size(); 2225e4b17023SJohn Marino const size_type __osize = __str.size(); 2226e4b17023SJohn Marino const size_type __len = std::min(__size, __osize); 2227e4b17023SJohn Marino 2228e4b17023SJohn Marino int __r = traits_type::compare(_M_data(), __str.data(), __len); 2229e4b17023SJohn Marino if (!__r) 2230e4b17023SJohn Marino __r = _S_compare(__size, __osize); 2231e4b17023SJohn Marino return __r; 2232e4b17023SJohn Marino } 2233e4b17023SJohn Marino 2234e4b17023SJohn Marino /** 2235e4b17023SJohn Marino * @brief Compare substring to a string. 2236e4b17023SJohn Marino * @param __pos Index of first character of substring. 2237e4b17023SJohn Marino * @param __n Number of characters in substring. 2238e4b17023SJohn Marino * @param __str String to compare against. 2239e4b17023SJohn Marino * @return Integer < 0, 0, or > 0. 2240e4b17023SJohn Marino * 2241e4b17023SJohn Marino * Form the substring of this string from the @a __n characters 2242e4b17023SJohn Marino * starting at @a __pos. Returns an integer < 0 if the 2243e4b17023SJohn Marino * substring is ordered before @a __str, 0 if their values are 2244e4b17023SJohn Marino * equivalent, or > 0 if the substring is ordered after @a 2245e4b17023SJohn Marino * __str. Determines the effective length rlen of the strings 2246e4b17023SJohn Marino * to compare as the smallest of the length of the substring 2247e4b17023SJohn Marino * and @a __str.size(). The function then compares the two 2248e4b17023SJohn Marino * strings by calling 2249e4b17023SJohn Marino * traits::compare(substring.data(),str.data(),rlen). If the 2250e4b17023SJohn Marino * result of the comparison is nonzero returns it, otherwise 2251e4b17023SJohn Marino * the shorter one is ordered first. 2252e4b17023SJohn Marino */ 2253e4b17023SJohn Marino int 2254e4b17023SJohn Marino compare(size_type __pos, size_type __n, const basic_string& __str) const; 2255e4b17023SJohn Marino 2256e4b17023SJohn Marino /** 2257e4b17023SJohn Marino * @brief Compare substring to a substring. 2258e4b17023SJohn Marino * @param __pos1 Index of first character of substring. 2259e4b17023SJohn Marino * @param __n1 Number of characters in substring. 2260e4b17023SJohn Marino * @param __str String to compare against. 2261e4b17023SJohn Marino * @param __pos2 Index of first character of substring of str. 2262e4b17023SJohn Marino * @param __n2 Number of characters in substring of str. 2263e4b17023SJohn Marino * @return Integer < 0, 0, or > 0. 2264e4b17023SJohn Marino * 2265e4b17023SJohn Marino * Form the substring of this string from the @a __n1 2266e4b17023SJohn Marino * characters starting at @a __pos1. Form the substring of @a 2267e4b17023SJohn Marino * __str from the @a __n2 characters starting at @a __pos2. 2268e4b17023SJohn Marino * Returns an integer < 0 if this substring is ordered before 2269e4b17023SJohn Marino * the substring of @a __str, 0 if their values are equivalent, 2270e4b17023SJohn Marino * or > 0 if this substring is ordered after the substring of 2271e4b17023SJohn Marino * @a __str. Determines the effective length rlen of the 2272e4b17023SJohn Marino * strings to compare as the smallest of the lengths of the 2273e4b17023SJohn Marino * substrings. The function then compares the two strings by 2274e4b17023SJohn Marino * calling 2275e4b17023SJohn Marino * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). 2276e4b17023SJohn Marino * If the result of the comparison is nonzero returns it, 2277e4b17023SJohn Marino * otherwise the shorter one is ordered first. 2278e4b17023SJohn Marino */ 2279e4b17023SJohn Marino int 2280e4b17023SJohn Marino compare(size_type __pos1, size_type __n1, const basic_string& __str, 2281e4b17023SJohn Marino size_type __pos2, size_type __n2) const; 2282e4b17023SJohn Marino 2283e4b17023SJohn Marino /** 2284e4b17023SJohn Marino * @brief Compare to a C string. 2285e4b17023SJohn Marino * @param __s C string to compare against. 2286e4b17023SJohn Marino * @return Integer < 0, 0, or > 0. 2287e4b17023SJohn Marino * 2288e4b17023SJohn Marino * Returns an integer < 0 if this string is ordered before @a __s, 0 if 2289e4b17023SJohn Marino * their values are equivalent, or > 0 if this string is ordered after 2290e4b17023SJohn Marino * @a __s. Determines the effective length rlen of the strings to 2291e4b17023SJohn Marino * compare as the smallest of size() and the length of a string 2292e4b17023SJohn Marino * constructed from @a __s. The function then compares the two strings 2293e4b17023SJohn Marino * by calling traits::compare(data(),s,rlen). If the result of the 2294e4b17023SJohn Marino * comparison is nonzero returns it, otherwise the shorter one is 2295e4b17023SJohn Marino * ordered first. 2296e4b17023SJohn Marino */ 2297e4b17023SJohn Marino int 2298e4b17023SJohn Marino compare(const _CharT* __s) const; 2299e4b17023SJohn Marino 2300e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 2301e4b17023SJohn Marino // 5 String::compare specification questionable 2302e4b17023SJohn Marino /** 2303e4b17023SJohn Marino * @brief Compare substring to a C string. 2304e4b17023SJohn Marino * @param __pos Index of first character of substring. 2305e4b17023SJohn Marino * @param __n1 Number of characters in substring. 2306e4b17023SJohn Marino * @param __s C string to compare against. 2307e4b17023SJohn Marino * @return Integer < 0, 0, or > 0. 2308e4b17023SJohn Marino * 2309e4b17023SJohn Marino * Form the substring of this string from the @a __n1 2310e4b17023SJohn Marino * characters starting at @a pos. Returns an integer < 0 if 2311e4b17023SJohn Marino * the substring is ordered before @a __s, 0 if their values 2312e4b17023SJohn Marino * are equivalent, or > 0 if the substring is ordered after @a 2313e4b17023SJohn Marino * __s. Determines the effective length rlen of the strings to 2314e4b17023SJohn Marino * compare as the smallest of the length of the substring and 2315e4b17023SJohn Marino * the length of a string constructed from @a __s. The 2316e4b17023SJohn Marino * function then compares the two string by calling 2317e4b17023SJohn Marino * traits::compare(substring.data(),__s,rlen). If the result of 2318e4b17023SJohn Marino * the comparison is nonzero returns it, otherwise the shorter 2319e4b17023SJohn Marino * one is ordered first. 2320e4b17023SJohn Marino */ 2321e4b17023SJohn Marino int 2322e4b17023SJohn Marino compare(size_type __pos, size_type __n1, const _CharT* __s) const; 2323e4b17023SJohn Marino 2324e4b17023SJohn Marino /** 2325e4b17023SJohn Marino * @brief Compare substring against a character %array. 2326e4b17023SJohn Marino * @param __pos Index of first character of substring. 2327e4b17023SJohn Marino * @param __n1 Number of characters in substring. 2328e4b17023SJohn Marino * @param __s character %array to compare against. 2329e4b17023SJohn Marino * @param __n2 Number of characters of s. 2330e4b17023SJohn Marino * @return Integer < 0, 0, or > 0. 2331e4b17023SJohn Marino * 2332e4b17023SJohn Marino * Form the substring of this string from the @a __n1 2333e4b17023SJohn Marino * characters starting at @a __pos. Form a string from the 2334e4b17023SJohn Marino * first @a __n2 characters of @a __s. Returns an integer < 0 2335e4b17023SJohn Marino * if this substring is ordered before the string from @a __s, 2336e4b17023SJohn Marino * 0 if their values are equivalent, or > 0 if this substring 2337e4b17023SJohn Marino * is ordered after the string from @a __s. Determines the 2338e4b17023SJohn Marino * effective length rlen of the strings to compare as the 2339e4b17023SJohn Marino * smallest of the length of the substring and @a __n2. The 2340e4b17023SJohn Marino * function then compares the two strings by calling 2341e4b17023SJohn Marino * traits::compare(substring.data(),s,rlen). If the result of 2342e4b17023SJohn Marino * the comparison is nonzero returns it, otherwise the shorter 2343e4b17023SJohn Marino * one is ordered first. 2344e4b17023SJohn Marino * 2345e4b17023SJohn Marino * NB: s must have at least n2 characters, '\\0' has 2346e4b17023SJohn Marino * no special meaning. 2347e4b17023SJohn Marino */ 2348e4b17023SJohn Marino int 2349e4b17023SJohn Marino compare(size_type __pos, size_type __n1, const _CharT* __s, 2350e4b17023SJohn Marino size_type __n2) const; 2351e4b17023SJohn Marino }; 2352e4b17023SJohn Marino 2353e4b17023SJohn Marino // operator+ 2354e4b17023SJohn Marino /** 2355e4b17023SJohn Marino * @brief Concatenate two strings. 2356e4b17023SJohn Marino * @param __lhs First string. 2357e4b17023SJohn Marino * @param __rhs Last string. 2358e4b17023SJohn Marino * @return New string with value of @a __lhs followed by @a __rhs. 2359e4b17023SJohn Marino */ 2360e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2361e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc> 2362e4b17023SJohn Marino operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2363e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2364e4b17023SJohn Marino { 2365e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc> __str(__lhs); 2366e4b17023SJohn Marino __str.append(__rhs); 2367e4b17023SJohn Marino return __str; 2368e4b17023SJohn Marino } 2369e4b17023SJohn Marino 2370e4b17023SJohn Marino /** 2371e4b17023SJohn Marino * @brief Concatenate C string and string. 2372e4b17023SJohn Marino * @param __lhs First string. 2373e4b17023SJohn Marino * @param __rhs Last string. 2374e4b17023SJohn Marino * @return New string with value of @a __lhs followed by @a __rhs. 2375e4b17023SJohn Marino */ 2376e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2377e4b17023SJohn Marino basic_string<_CharT,_Traits,_Alloc> 2378e4b17023SJohn Marino operator+(const _CharT* __lhs, 2379e4b17023SJohn Marino const basic_string<_CharT,_Traits,_Alloc>& __rhs); 2380e4b17023SJohn Marino 2381e4b17023SJohn Marino /** 2382e4b17023SJohn Marino * @brief Concatenate character and string. 2383e4b17023SJohn Marino * @param __lhs First string. 2384e4b17023SJohn Marino * @param __rhs Last string. 2385e4b17023SJohn Marino * @return New string with @a __lhs followed by @a __rhs. 2386e4b17023SJohn Marino */ 2387e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2388e4b17023SJohn Marino basic_string<_CharT,_Traits,_Alloc> 2389e4b17023SJohn Marino operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs); 2390e4b17023SJohn Marino 2391e4b17023SJohn Marino /** 2392e4b17023SJohn Marino * @brief Concatenate string and C string. 2393e4b17023SJohn Marino * @param __lhs First string. 2394e4b17023SJohn Marino * @param __rhs Last string. 2395e4b17023SJohn Marino * @return New string with @a __lhs followed by @a __rhs. 2396e4b17023SJohn Marino */ 2397e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2398e4b17023SJohn Marino inline basic_string<_CharT, _Traits, _Alloc> 2399e4b17023SJohn Marino operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2400e4b17023SJohn Marino const _CharT* __rhs) 2401e4b17023SJohn Marino { 2402e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc> __str(__lhs); 2403e4b17023SJohn Marino __str.append(__rhs); 2404e4b17023SJohn Marino return __str; 2405e4b17023SJohn Marino } 2406e4b17023SJohn Marino 2407e4b17023SJohn Marino /** 2408e4b17023SJohn Marino * @brief Concatenate string and character. 2409e4b17023SJohn Marino * @param __lhs First string. 2410e4b17023SJohn Marino * @param __rhs Last string. 2411e4b17023SJohn Marino * @return New string with @a __lhs followed by @a __rhs. 2412e4b17023SJohn Marino */ 2413e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2414e4b17023SJohn Marino inline basic_string<_CharT, _Traits, _Alloc> 2415e4b17023SJohn Marino operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) 2416e4b17023SJohn Marino { 2417e4b17023SJohn Marino typedef basic_string<_CharT, _Traits, _Alloc> __string_type; 2418e4b17023SJohn Marino typedef typename __string_type::size_type __size_type; 2419e4b17023SJohn Marino __string_type __str(__lhs); 2420e4b17023SJohn Marino __str.append(__size_type(1), __rhs); 2421e4b17023SJohn Marino return __str; 2422e4b17023SJohn Marino } 2423e4b17023SJohn Marino 2424e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 2425e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2426e4b17023SJohn Marino inline basic_string<_CharT, _Traits, _Alloc> 2427e4b17023SJohn Marino operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, 2428e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2429e4b17023SJohn Marino { return std::move(__lhs.append(__rhs)); } 2430e4b17023SJohn Marino 2431e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2432e4b17023SJohn Marino inline basic_string<_CharT, _Traits, _Alloc> 2433e4b17023SJohn Marino operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2434e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc>&& __rhs) 2435e4b17023SJohn Marino { return std::move(__rhs.insert(0, __lhs)); } 2436e4b17023SJohn Marino 2437e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2438e4b17023SJohn Marino inline basic_string<_CharT, _Traits, _Alloc> 2439e4b17023SJohn Marino operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, 2440e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc>&& __rhs) 2441e4b17023SJohn Marino { 2442e4b17023SJohn Marino const auto __size = __lhs.size() + __rhs.size(); 2443e4b17023SJohn Marino const bool __cond = (__size > __lhs.capacity() 2444e4b17023SJohn Marino && __size <= __rhs.capacity()); 2445e4b17023SJohn Marino return __cond ? std::move(__rhs.insert(0, __lhs)) 2446e4b17023SJohn Marino : std::move(__lhs.append(__rhs)); 2447e4b17023SJohn Marino } 2448e4b17023SJohn Marino 2449e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2450e4b17023SJohn Marino inline basic_string<_CharT, _Traits, _Alloc> 2451e4b17023SJohn Marino operator+(const _CharT* __lhs, 2452e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc>&& __rhs) 2453e4b17023SJohn Marino { return std::move(__rhs.insert(0, __lhs)); } 2454e4b17023SJohn Marino 2455e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2456e4b17023SJohn Marino inline basic_string<_CharT, _Traits, _Alloc> 2457e4b17023SJohn Marino operator+(_CharT __lhs, 2458e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc>&& __rhs) 2459e4b17023SJohn Marino { return std::move(__rhs.insert(0, 1, __lhs)); } 2460e4b17023SJohn Marino 2461e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2462e4b17023SJohn Marino inline basic_string<_CharT, _Traits, _Alloc> 2463e4b17023SJohn Marino operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, 2464e4b17023SJohn Marino const _CharT* __rhs) 2465e4b17023SJohn Marino { return std::move(__lhs.append(__rhs)); } 2466e4b17023SJohn Marino 2467e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2468e4b17023SJohn Marino inline basic_string<_CharT, _Traits, _Alloc> 2469e4b17023SJohn Marino operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, 2470e4b17023SJohn Marino _CharT __rhs) 2471e4b17023SJohn Marino { return std::move(__lhs.append(1, __rhs)); } 2472e4b17023SJohn Marino #endif 2473e4b17023SJohn Marino 2474e4b17023SJohn Marino // operator == 2475e4b17023SJohn Marino /** 2476e4b17023SJohn Marino * @brief Test equivalence of two strings. 2477e4b17023SJohn Marino * @param __lhs First string. 2478e4b17023SJohn Marino * @param __rhs Second string. 2479e4b17023SJohn Marino * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 2480e4b17023SJohn Marino */ 2481e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2482e4b17023SJohn Marino inline bool 2483e4b17023SJohn Marino operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2484e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2485e4b17023SJohn Marino { return __lhs.compare(__rhs) == 0; } 2486e4b17023SJohn Marino 2487e4b17023SJohn Marino template<typename _CharT> 2488e4b17023SJohn Marino inline 2489e4b17023SJohn Marino typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type 2490e4b17023SJohn Marino operator==(const basic_string<_CharT>& __lhs, 2491e4b17023SJohn Marino const basic_string<_CharT>& __rhs) 2492e4b17023SJohn Marino { return (__lhs.size() == __rhs.size() 2493e4b17023SJohn Marino && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), 2494e4b17023SJohn Marino __lhs.size())); } 2495e4b17023SJohn Marino 2496e4b17023SJohn Marino /** 2497e4b17023SJohn Marino * @brief Test equivalence of C string and string. 2498e4b17023SJohn Marino * @param __lhs C string. 2499e4b17023SJohn Marino * @param __rhs String. 2500e4b17023SJohn Marino * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. 2501e4b17023SJohn Marino */ 2502e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2503e4b17023SJohn Marino inline bool 2504e4b17023SJohn Marino operator==(const _CharT* __lhs, 2505e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2506e4b17023SJohn Marino { return __rhs.compare(__lhs) == 0; } 2507e4b17023SJohn Marino 2508e4b17023SJohn Marino /** 2509e4b17023SJohn Marino * @brief Test equivalence of string and C string. 2510e4b17023SJohn Marino * @param __lhs String. 2511e4b17023SJohn Marino * @param __rhs C string. 2512e4b17023SJohn Marino * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 2513e4b17023SJohn Marino */ 2514e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2515e4b17023SJohn Marino inline bool 2516e4b17023SJohn Marino operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2517e4b17023SJohn Marino const _CharT* __rhs) 2518e4b17023SJohn Marino { return __lhs.compare(__rhs) == 0; } 2519e4b17023SJohn Marino 2520e4b17023SJohn Marino // operator != 2521e4b17023SJohn Marino /** 2522e4b17023SJohn Marino * @brief Test difference of two strings. 2523e4b17023SJohn Marino * @param __lhs First string. 2524e4b17023SJohn Marino * @param __rhs Second string. 2525e4b17023SJohn Marino * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 2526e4b17023SJohn Marino */ 2527e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2528e4b17023SJohn Marino inline bool 2529e4b17023SJohn Marino operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2530e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2531e4b17023SJohn Marino { return !(__lhs == __rhs); } 2532e4b17023SJohn Marino 2533e4b17023SJohn Marino /** 2534e4b17023SJohn Marino * @brief Test difference of C string and string. 2535e4b17023SJohn Marino * @param __lhs C string. 2536e4b17023SJohn Marino * @param __rhs String. 2537e4b17023SJohn Marino * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. 2538e4b17023SJohn Marino */ 2539e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2540e4b17023SJohn Marino inline bool 2541e4b17023SJohn Marino operator!=(const _CharT* __lhs, 2542e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2543e4b17023SJohn Marino { return !(__lhs == __rhs); } 2544e4b17023SJohn Marino 2545e4b17023SJohn Marino /** 2546e4b17023SJohn Marino * @brief Test difference of string and C string. 2547e4b17023SJohn Marino * @param __lhs String. 2548e4b17023SJohn Marino * @param __rhs C string. 2549e4b17023SJohn Marino * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 2550e4b17023SJohn Marino */ 2551e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2552e4b17023SJohn Marino inline bool 2553e4b17023SJohn Marino operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2554e4b17023SJohn Marino const _CharT* __rhs) 2555e4b17023SJohn Marino { return !(__lhs == __rhs); } 2556e4b17023SJohn Marino 2557e4b17023SJohn Marino // operator < 2558e4b17023SJohn Marino /** 2559e4b17023SJohn Marino * @brief Test if string precedes string. 2560e4b17023SJohn Marino * @param __lhs First string. 2561e4b17023SJohn Marino * @param __rhs Second string. 2562e4b17023SJohn Marino * @return True if @a __lhs precedes @a __rhs. False otherwise. 2563e4b17023SJohn Marino */ 2564e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2565e4b17023SJohn Marino inline bool 2566e4b17023SJohn Marino operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2567e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2568e4b17023SJohn Marino { return __lhs.compare(__rhs) < 0; } 2569e4b17023SJohn Marino 2570e4b17023SJohn Marino /** 2571e4b17023SJohn Marino * @brief Test if string precedes C string. 2572e4b17023SJohn Marino * @param __lhs String. 2573e4b17023SJohn Marino * @param __rhs C string. 2574e4b17023SJohn Marino * @return True if @a __lhs precedes @a __rhs. False otherwise. 2575e4b17023SJohn Marino */ 2576e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2577e4b17023SJohn Marino inline bool 2578e4b17023SJohn Marino operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2579e4b17023SJohn Marino const _CharT* __rhs) 2580e4b17023SJohn Marino { return __lhs.compare(__rhs) < 0; } 2581e4b17023SJohn Marino 2582e4b17023SJohn Marino /** 2583e4b17023SJohn Marino * @brief Test if C string precedes string. 2584e4b17023SJohn Marino * @param __lhs C string. 2585e4b17023SJohn Marino * @param __rhs String. 2586e4b17023SJohn Marino * @return True if @a __lhs precedes @a __rhs. False otherwise. 2587e4b17023SJohn Marino */ 2588e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2589e4b17023SJohn Marino inline bool 2590e4b17023SJohn Marino operator<(const _CharT* __lhs, 2591e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2592e4b17023SJohn Marino { return __rhs.compare(__lhs) > 0; } 2593e4b17023SJohn Marino 2594e4b17023SJohn Marino // operator > 2595e4b17023SJohn Marino /** 2596e4b17023SJohn Marino * @brief Test if string follows string. 2597e4b17023SJohn Marino * @param __lhs First string. 2598e4b17023SJohn Marino * @param __rhs Second string. 2599e4b17023SJohn Marino * @return True if @a __lhs follows @a __rhs. False otherwise. 2600e4b17023SJohn Marino */ 2601e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2602e4b17023SJohn Marino inline bool 2603e4b17023SJohn Marino operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2604e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2605e4b17023SJohn Marino { return __lhs.compare(__rhs) > 0; } 2606e4b17023SJohn Marino 2607e4b17023SJohn Marino /** 2608e4b17023SJohn Marino * @brief Test if string follows C string. 2609e4b17023SJohn Marino * @param __lhs String. 2610e4b17023SJohn Marino * @param __rhs C string. 2611e4b17023SJohn Marino * @return True if @a __lhs follows @a __rhs. False otherwise. 2612e4b17023SJohn Marino */ 2613e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2614e4b17023SJohn Marino inline bool 2615e4b17023SJohn Marino operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2616e4b17023SJohn Marino const _CharT* __rhs) 2617e4b17023SJohn Marino { return __lhs.compare(__rhs) > 0; } 2618e4b17023SJohn Marino 2619e4b17023SJohn Marino /** 2620e4b17023SJohn Marino * @brief Test if C string follows string. 2621e4b17023SJohn Marino * @param __lhs C string. 2622e4b17023SJohn Marino * @param __rhs String. 2623e4b17023SJohn Marino * @return True if @a __lhs follows @a __rhs. False otherwise. 2624e4b17023SJohn Marino */ 2625e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2626e4b17023SJohn Marino inline bool 2627e4b17023SJohn Marino operator>(const _CharT* __lhs, 2628e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2629e4b17023SJohn Marino { return __rhs.compare(__lhs) < 0; } 2630e4b17023SJohn Marino 2631e4b17023SJohn Marino // operator <= 2632e4b17023SJohn Marino /** 2633e4b17023SJohn Marino * @brief Test if string doesn't follow string. 2634e4b17023SJohn Marino * @param __lhs First string. 2635e4b17023SJohn Marino * @param __rhs Second string. 2636e4b17023SJohn Marino * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 2637e4b17023SJohn Marino */ 2638e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2639e4b17023SJohn Marino inline bool 2640e4b17023SJohn Marino operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2641e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2642e4b17023SJohn Marino { return __lhs.compare(__rhs) <= 0; } 2643e4b17023SJohn Marino 2644e4b17023SJohn Marino /** 2645e4b17023SJohn Marino * @brief Test if string doesn't follow C string. 2646e4b17023SJohn Marino * @param __lhs String. 2647e4b17023SJohn Marino * @param __rhs C string. 2648e4b17023SJohn Marino * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 2649e4b17023SJohn Marino */ 2650e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2651e4b17023SJohn Marino inline bool 2652e4b17023SJohn Marino operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2653e4b17023SJohn Marino const _CharT* __rhs) 2654e4b17023SJohn Marino { return __lhs.compare(__rhs) <= 0; } 2655e4b17023SJohn Marino 2656e4b17023SJohn Marino /** 2657e4b17023SJohn Marino * @brief Test if C string doesn't follow string. 2658e4b17023SJohn Marino * @param __lhs C string. 2659e4b17023SJohn Marino * @param __rhs String. 2660e4b17023SJohn Marino * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 2661e4b17023SJohn Marino */ 2662e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2663e4b17023SJohn Marino inline bool 2664e4b17023SJohn Marino operator<=(const _CharT* __lhs, 2665e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2666e4b17023SJohn Marino { return __rhs.compare(__lhs) >= 0; } 2667e4b17023SJohn Marino 2668e4b17023SJohn Marino // operator >= 2669e4b17023SJohn Marino /** 2670e4b17023SJohn Marino * @brief Test if string doesn't precede string. 2671e4b17023SJohn Marino * @param __lhs First string. 2672e4b17023SJohn Marino * @param __rhs Second string. 2673e4b17023SJohn Marino * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 2674e4b17023SJohn Marino */ 2675e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2676e4b17023SJohn Marino inline bool 2677e4b17023SJohn Marino operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2678e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2679e4b17023SJohn Marino { return __lhs.compare(__rhs) >= 0; } 2680e4b17023SJohn Marino 2681e4b17023SJohn Marino /** 2682e4b17023SJohn Marino * @brief Test if string doesn't precede C string. 2683e4b17023SJohn Marino * @param __lhs String. 2684e4b17023SJohn Marino * @param __rhs C string. 2685e4b17023SJohn Marino * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 2686e4b17023SJohn Marino */ 2687e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2688e4b17023SJohn Marino inline bool 2689e4b17023SJohn Marino operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, 2690e4b17023SJohn Marino const _CharT* __rhs) 2691e4b17023SJohn Marino { return __lhs.compare(__rhs) >= 0; } 2692e4b17023SJohn Marino 2693e4b17023SJohn Marino /** 2694e4b17023SJohn Marino * @brief Test if C string doesn't precede string. 2695e4b17023SJohn Marino * @param __lhs C string. 2696e4b17023SJohn Marino * @param __rhs String. 2697e4b17023SJohn Marino * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 2698e4b17023SJohn Marino */ 2699e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2700e4b17023SJohn Marino inline bool 2701e4b17023SJohn Marino operator>=(const _CharT* __lhs, 2702e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __rhs) 2703e4b17023SJohn Marino { return __rhs.compare(__lhs) <= 0; } 2704e4b17023SJohn Marino 2705e4b17023SJohn Marino /** 2706e4b17023SJohn Marino * @brief Swap contents of two strings. 2707e4b17023SJohn Marino * @param __lhs First string. 2708e4b17023SJohn Marino * @param __rhs Second string. 2709e4b17023SJohn Marino * 2710e4b17023SJohn Marino * Exchanges the contents of @a __lhs and @a __rhs in constant time. 2711e4b17023SJohn Marino */ 2712e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2713e4b17023SJohn Marino inline void 2714e4b17023SJohn Marino swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, 2715e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc>& __rhs) 2716e4b17023SJohn Marino { __lhs.swap(__rhs); } 2717e4b17023SJohn Marino 2718e4b17023SJohn Marino /** 2719e4b17023SJohn Marino * @brief Read stream into a string. 2720e4b17023SJohn Marino * @param __is Input stream. 2721e4b17023SJohn Marino * @param __str Buffer to store into. 2722e4b17023SJohn Marino * @return Reference to the input stream. 2723e4b17023SJohn Marino * 2724e4b17023SJohn Marino * Stores characters from @a __is into @a __str until whitespace is 2725e4b17023SJohn Marino * found, the end of the stream is encountered, or str.max_size() 2726e4b17023SJohn Marino * is reached. If is.width() is non-zero, that is the limit on the 2727e4b17023SJohn Marino * number of characters stored into @a __str. Any previous 2728e4b17023SJohn Marino * contents of @a __str are erased. 2729e4b17023SJohn Marino */ 2730e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2731e4b17023SJohn Marino basic_istream<_CharT, _Traits>& 2732e4b17023SJohn Marino operator>>(basic_istream<_CharT, _Traits>& __is, 2733e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc>& __str); 2734e4b17023SJohn Marino 2735e4b17023SJohn Marino template<> 2736e4b17023SJohn Marino basic_istream<char>& 2737e4b17023SJohn Marino operator>>(basic_istream<char>& __is, basic_string<char>& __str); 2738e4b17023SJohn Marino 2739e4b17023SJohn Marino /** 2740e4b17023SJohn Marino * @brief Write string to a stream. 2741e4b17023SJohn Marino * @param __os Output stream. 2742e4b17023SJohn Marino * @param __str String to write out. 2743e4b17023SJohn Marino * @return Reference to the output stream. 2744e4b17023SJohn Marino * 2745e4b17023SJohn Marino * Output characters of @a __str into os following the same rules as for 2746e4b17023SJohn Marino * writing a C string. 2747e4b17023SJohn Marino */ 2748e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2749e4b17023SJohn Marino inline basic_ostream<_CharT, _Traits>& 2750e4b17023SJohn Marino operator<<(basic_ostream<_CharT, _Traits>& __os, 2751e4b17023SJohn Marino const basic_string<_CharT, _Traits, _Alloc>& __str) 2752e4b17023SJohn Marino { 2753e4b17023SJohn Marino // _GLIBCXX_RESOLVE_LIB_DEFECTS 2754e4b17023SJohn Marino // 586. string inserter not a formatted function 2755e4b17023SJohn Marino return __ostream_insert(__os, __str.data(), __str.size()); 2756e4b17023SJohn Marino } 2757e4b17023SJohn Marino 2758e4b17023SJohn Marino /** 2759e4b17023SJohn Marino * @brief Read a line from stream into a string. 2760e4b17023SJohn Marino * @param __is Input stream. 2761e4b17023SJohn Marino * @param __str Buffer to store into. 2762e4b17023SJohn Marino * @param __delim Character marking end of line. 2763e4b17023SJohn Marino * @return Reference to the input stream. 2764e4b17023SJohn Marino * 2765e4b17023SJohn Marino * Stores characters from @a __is into @a __str until @a __delim is 2766e4b17023SJohn Marino * found, the end of the stream is encountered, or str.max_size() 2767*95d28233SJohn Marino * is reached. Any previous contents of @a __str are erased. If 2768*95d28233SJohn Marino * @a __delim is encountered, it is extracted but not stored into 2769*95d28233SJohn Marino * @a __str. 2770e4b17023SJohn Marino */ 2771e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2772e4b17023SJohn Marino basic_istream<_CharT, _Traits>& 2773e4b17023SJohn Marino getline(basic_istream<_CharT, _Traits>& __is, 2774e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim); 2775e4b17023SJohn Marino 2776e4b17023SJohn Marino /** 2777e4b17023SJohn Marino * @brief Read a line from stream into a string. 2778e4b17023SJohn Marino * @param __is Input stream. 2779e4b17023SJohn Marino * @param __str Buffer to store into. 2780e4b17023SJohn Marino * @return Reference to the input stream. 2781e4b17023SJohn Marino * 2782e4b17023SJohn Marino * Stores characters from is into @a __str until '\n' is 2783e4b17023SJohn Marino * found, the end of the stream is encountered, or str.max_size() 2784*95d28233SJohn Marino * is reached. Any previous contents of @a __str are erased. If 2785*95d28233SJohn Marino * end of line is encountered, it is extracted but not stored into 2786*95d28233SJohn Marino * @a __str. 2787e4b17023SJohn Marino */ 2788e4b17023SJohn Marino template<typename _CharT, typename _Traits, typename _Alloc> 2789e4b17023SJohn Marino inline basic_istream<_CharT, _Traits>& 2790e4b17023SJohn Marino getline(basic_istream<_CharT, _Traits>& __is, 2791e4b17023SJohn Marino basic_string<_CharT, _Traits, _Alloc>& __str) 2792e4b17023SJohn Marino { return getline(__is, __str, __is.widen('\n')); } 2793e4b17023SJohn Marino 2794e4b17023SJohn Marino template<> 2795e4b17023SJohn Marino basic_istream<char>& 2796e4b17023SJohn Marino getline(basic_istream<char>& __in, basic_string<char>& __str, 2797e4b17023SJohn Marino char __delim); 2798e4b17023SJohn Marino 2799e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 2800e4b17023SJohn Marino template<> 2801e4b17023SJohn Marino basic_istream<wchar_t>& 2802e4b17023SJohn Marino getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str, 2803e4b17023SJohn Marino wchar_t __delim); 2804e4b17023SJohn Marino #endif 2805e4b17023SJohn Marino 2806e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 2807e4b17023SJohn Marino } // namespace 2808e4b17023SJohn Marino 2809e4b17023SJohn Marino #if (defined(__GXX_EXPERIMENTAL_CXX0X__) && defined(_GLIBCXX_USE_C99) \ 2810e4b17023SJohn Marino && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) 2811e4b17023SJohn Marino 2812e4b17023SJohn Marino #include <ext/string_conversions.h> 2813e4b17023SJohn Marino 2814e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 2815e4b17023SJohn Marino { 2816e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 2817e4b17023SJohn Marino 2818e4b17023SJohn Marino // 21.4 Numeric Conversions [string.conversions]. 2819e4b17023SJohn Marino inline int 2820e4b17023SJohn Marino stoi(const string& __str, size_t* __idx = 0, int __base = 10) 2821e4b17023SJohn Marino { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), 2822e4b17023SJohn Marino __idx, __base); } 2823e4b17023SJohn Marino 2824e4b17023SJohn Marino inline long 2825e4b17023SJohn Marino stol(const string& __str, size_t* __idx = 0, int __base = 10) 2826e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), 2827e4b17023SJohn Marino __idx, __base); } 2828e4b17023SJohn Marino 2829e4b17023SJohn Marino inline unsigned long 2830e4b17023SJohn Marino stoul(const string& __str, size_t* __idx = 0, int __base = 10) 2831e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), 2832e4b17023SJohn Marino __idx, __base); } 2833e4b17023SJohn Marino 2834e4b17023SJohn Marino inline long long 2835e4b17023SJohn Marino stoll(const string& __str, size_t* __idx = 0, int __base = 10) 2836e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), 2837e4b17023SJohn Marino __idx, __base); } 2838e4b17023SJohn Marino 2839e4b17023SJohn Marino inline unsigned long long 2840e4b17023SJohn Marino stoull(const string& __str, size_t* __idx = 0, int __base = 10) 2841e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), 2842e4b17023SJohn Marino __idx, __base); } 2843e4b17023SJohn Marino 2844e4b17023SJohn Marino // NB: strtof vs strtod. 2845e4b17023SJohn Marino inline float 2846e4b17023SJohn Marino stof(const string& __str, size_t* __idx = 0) 2847e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } 2848e4b17023SJohn Marino 2849e4b17023SJohn Marino inline double 2850e4b17023SJohn Marino stod(const string& __str, size_t* __idx = 0) 2851e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } 2852e4b17023SJohn Marino 2853e4b17023SJohn Marino inline long double 2854e4b17023SJohn Marino stold(const string& __str, size_t* __idx = 0) 2855e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } 2856e4b17023SJohn Marino 2857e4b17023SJohn Marino // NB: (v)snprintf vs sprintf. 2858e4b17023SJohn Marino 2859e4b17023SJohn Marino // DR 1261. 2860e4b17023SJohn Marino inline string 2861e4b17023SJohn Marino to_string(int __val) 2862e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int), 2863e4b17023SJohn Marino "%d", __val); } 2864e4b17023SJohn Marino 2865e4b17023SJohn Marino inline string 2866e4b17023SJohn Marino to_string(unsigned __val) 2867e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 2868e4b17023SJohn Marino 4 * sizeof(unsigned), 2869e4b17023SJohn Marino "%u", __val); } 2870e4b17023SJohn Marino 2871e4b17023SJohn Marino inline string 2872e4b17023SJohn Marino to_string(long __val) 2873e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(long), 2874e4b17023SJohn Marino "%ld", __val); } 2875e4b17023SJohn Marino 2876e4b17023SJohn Marino inline string 2877e4b17023SJohn Marino to_string(unsigned long __val) 2878e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 2879e4b17023SJohn Marino 4 * sizeof(unsigned long), 2880e4b17023SJohn Marino "%lu", __val); } 2881e4b17023SJohn Marino 2882e4b17023SJohn Marino inline string 2883e4b17023SJohn Marino to_string(long long __val) 2884e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 2885e4b17023SJohn Marino 4 * sizeof(long long), 2886e4b17023SJohn Marino "%lld", __val); } 2887e4b17023SJohn Marino 2888e4b17023SJohn Marino inline string 2889e4b17023SJohn Marino to_string(unsigned long long __val) 2890e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 2891e4b17023SJohn Marino 4 * sizeof(unsigned long long), 2892e4b17023SJohn Marino "%llu", __val); } 2893e4b17023SJohn Marino 2894e4b17023SJohn Marino inline string 2895e4b17023SJohn Marino to_string(float __val) 2896e4b17023SJohn Marino { 2897e4b17023SJohn Marino const int __n = 2898e4b17023SJohn Marino __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; 2899e4b17023SJohn Marino return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, 2900e4b17023SJohn Marino "%f", __val); 2901e4b17023SJohn Marino } 2902e4b17023SJohn Marino 2903e4b17023SJohn Marino inline string 2904e4b17023SJohn Marino to_string(double __val) 2905e4b17023SJohn Marino { 2906e4b17023SJohn Marino const int __n = 2907e4b17023SJohn Marino __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; 2908e4b17023SJohn Marino return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, 2909e4b17023SJohn Marino "%f", __val); 2910e4b17023SJohn Marino } 2911e4b17023SJohn Marino 2912e4b17023SJohn Marino inline string 2913e4b17023SJohn Marino to_string(long double __val) 2914e4b17023SJohn Marino { 2915e4b17023SJohn Marino const int __n = 2916e4b17023SJohn Marino __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; 2917e4b17023SJohn Marino return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, 2918e4b17023SJohn Marino "%Lf", __val); 2919e4b17023SJohn Marino } 2920e4b17023SJohn Marino 2921e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 2922e4b17023SJohn Marino inline int 2923e4b17023SJohn Marino stoi(const wstring& __str, size_t* __idx = 0, int __base = 10) 2924e4b17023SJohn Marino { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), 2925e4b17023SJohn Marino __idx, __base); } 2926e4b17023SJohn Marino 2927e4b17023SJohn Marino inline long 2928e4b17023SJohn Marino stol(const wstring& __str, size_t* __idx = 0, int __base = 10) 2929e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), 2930e4b17023SJohn Marino __idx, __base); } 2931e4b17023SJohn Marino 2932e4b17023SJohn Marino inline unsigned long 2933e4b17023SJohn Marino stoul(const wstring& __str, size_t* __idx = 0, int __base = 10) 2934e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), 2935e4b17023SJohn Marino __idx, __base); } 2936e4b17023SJohn Marino 2937e4b17023SJohn Marino inline long long 2938e4b17023SJohn Marino stoll(const wstring& __str, size_t* __idx = 0, int __base = 10) 2939e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), 2940e4b17023SJohn Marino __idx, __base); } 2941e4b17023SJohn Marino 2942e4b17023SJohn Marino inline unsigned long long 2943e4b17023SJohn Marino stoull(const wstring& __str, size_t* __idx = 0, int __base = 10) 2944e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), 2945e4b17023SJohn Marino __idx, __base); } 2946e4b17023SJohn Marino 2947e4b17023SJohn Marino // NB: wcstof vs wcstod. 2948e4b17023SJohn Marino inline float 2949e4b17023SJohn Marino stof(const wstring& __str, size_t* __idx = 0) 2950e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } 2951e4b17023SJohn Marino 2952e4b17023SJohn Marino inline double 2953e4b17023SJohn Marino stod(const wstring& __str, size_t* __idx = 0) 2954e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } 2955e4b17023SJohn Marino 2956e4b17023SJohn Marino inline long double 2957e4b17023SJohn Marino stold(const wstring& __str, size_t* __idx = 0) 2958e4b17023SJohn Marino { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } 2959e4b17023SJohn Marino 2960e4b17023SJohn Marino // DR 1261. 2961e4b17023SJohn Marino inline wstring 2962e4b17023SJohn Marino to_wstring(int __val) 2963e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(int), 2964e4b17023SJohn Marino L"%d", __val); } 2965e4b17023SJohn Marino 2966e4b17023SJohn Marino inline wstring 2967e4b17023SJohn Marino to_wstring(unsigned __val) 2968e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 2969e4b17023SJohn Marino 4 * sizeof(unsigned), 2970e4b17023SJohn Marino L"%u", __val); } 2971e4b17023SJohn Marino 2972e4b17023SJohn Marino inline wstring 2973e4b17023SJohn Marino to_wstring(long __val) 2974e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 4 * sizeof(long), 2975e4b17023SJohn Marino L"%ld", __val); } 2976e4b17023SJohn Marino 2977e4b17023SJohn Marino inline wstring 2978e4b17023SJohn Marino to_wstring(unsigned long __val) 2979e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 2980e4b17023SJohn Marino 4 * sizeof(unsigned long), 2981e4b17023SJohn Marino L"%lu", __val); } 2982e4b17023SJohn Marino 2983e4b17023SJohn Marino inline wstring 2984e4b17023SJohn Marino to_wstring(long long __val) 2985e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 2986e4b17023SJohn Marino 4 * sizeof(long long), 2987e4b17023SJohn Marino L"%lld", __val); } 2988e4b17023SJohn Marino 2989e4b17023SJohn Marino inline wstring 2990e4b17023SJohn Marino to_wstring(unsigned long long __val) 2991e4b17023SJohn Marino { return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, 2992e4b17023SJohn Marino 4 * sizeof(unsigned long long), 2993e4b17023SJohn Marino L"%llu", __val); } 2994e4b17023SJohn Marino 2995e4b17023SJohn Marino inline wstring 2996e4b17023SJohn Marino to_wstring(float __val) 2997e4b17023SJohn Marino { 2998e4b17023SJohn Marino const int __n = 2999e4b17023SJohn Marino __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; 3000e4b17023SJohn Marino return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, 3001e4b17023SJohn Marino L"%f", __val); 3002e4b17023SJohn Marino } 3003e4b17023SJohn Marino 3004e4b17023SJohn Marino inline wstring 3005e4b17023SJohn Marino to_wstring(double __val) 3006e4b17023SJohn Marino { 3007e4b17023SJohn Marino const int __n = 3008e4b17023SJohn Marino __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; 3009e4b17023SJohn Marino return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, 3010e4b17023SJohn Marino L"%f", __val); 3011e4b17023SJohn Marino } 3012e4b17023SJohn Marino 3013e4b17023SJohn Marino inline wstring 3014e4b17023SJohn Marino to_wstring(long double __val) 3015e4b17023SJohn Marino { 3016e4b17023SJohn Marino const int __n = 3017e4b17023SJohn Marino __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; 3018e4b17023SJohn Marino return __gnu_cxx::__to_xstring<wstring>(&std::vswprintf, __n, 3019e4b17023SJohn Marino L"%Lf", __val); 3020e4b17023SJohn Marino } 3021e4b17023SJohn Marino #endif 3022e4b17023SJohn Marino 3023e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 3024e4b17023SJohn Marino } // namespace 3025e4b17023SJohn Marino 3026e4b17023SJohn Marino #endif /* __GXX_EXPERIMENTAL_CXX0X__ && _GLIBCXX_USE_C99 ... */ 3027e4b17023SJohn Marino 3028e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__ 3029e4b17023SJohn Marino 3030e4b17023SJohn Marino #include <bits/functional_hash.h> 3031e4b17023SJohn Marino 3032e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 3033e4b17023SJohn Marino { 3034e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 3035e4b17023SJohn Marino 3036e4b17023SJohn Marino // DR 1182. 3037e4b17023SJohn Marino 3038e4b17023SJohn Marino #ifndef _GLIBCXX_COMPATIBILITY_CXX0X 3039e4b17023SJohn Marino /// std::hash specialization for string. 3040e4b17023SJohn Marino template<> 3041e4b17023SJohn Marino struct hash<string> 3042e4b17023SJohn Marino : public __hash_base<size_t, string> 3043e4b17023SJohn Marino { 3044e4b17023SJohn Marino size_t 3045e4b17023SJohn Marino operator()(const string& __s) const noexcept 3046e4b17023SJohn Marino { return std::_Hash_impl::hash(__s.data(), __s.length()); } 3047e4b17023SJohn Marino }; 3048e4b17023SJohn Marino 3049e4b17023SJohn Marino #ifdef _GLIBCXX_USE_WCHAR_T 3050e4b17023SJohn Marino /// std::hash specialization for wstring. 3051e4b17023SJohn Marino template<> 3052e4b17023SJohn Marino struct hash<wstring> 3053e4b17023SJohn Marino : public __hash_base<size_t, wstring> 3054e4b17023SJohn Marino { 3055e4b17023SJohn Marino size_t 3056e4b17023SJohn Marino operator()(const wstring& __s) const noexcept 3057e4b17023SJohn Marino { return std::_Hash_impl::hash(__s.data(), 3058e4b17023SJohn Marino __s.length() * sizeof(wchar_t)); } 3059e4b17023SJohn Marino }; 3060e4b17023SJohn Marino #endif 3061e4b17023SJohn Marino #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */ 3062e4b17023SJohn Marino 3063e4b17023SJohn Marino #ifdef _GLIBCXX_USE_C99_STDINT_TR1 3064e4b17023SJohn Marino /// std::hash specialization for u16string. 3065e4b17023SJohn Marino template<> 3066e4b17023SJohn Marino struct hash<u16string> 3067e4b17023SJohn Marino : public __hash_base<size_t, u16string> 3068e4b17023SJohn Marino { 3069e4b17023SJohn Marino size_t 3070e4b17023SJohn Marino operator()(const u16string& __s) const noexcept 3071e4b17023SJohn Marino { return std::_Hash_impl::hash(__s.data(), 3072e4b17023SJohn Marino __s.length() * sizeof(char16_t)); } 3073e4b17023SJohn Marino }; 3074e4b17023SJohn Marino 3075e4b17023SJohn Marino /// std::hash specialization for u32string. 3076e4b17023SJohn Marino template<> 3077e4b17023SJohn Marino struct hash<u32string> 3078e4b17023SJohn Marino : public __hash_base<size_t, u32string> 3079e4b17023SJohn Marino { 3080e4b17023SJohn Marino size_t 3081e4b17023SJohn Marino operator()(const u32string& __s) const noexcept 3082e4b17023SJohn Marino { return std::_Hash_impl::hash(__s.data(), 3083e4b17023SJohn Marino __s.length() * sizeof(char32_t)); } 3084e4b17023SJohn Marino }; 3085e4b17023SJohn Marino #endif 3086e4b17023SJohn Marino 3087e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 3088e4b17023SJohn Marino } // namespace 3089e4b17023SJohn Marino 3090e4b17023SJohn Marino #endif /* __GXX_EXPERIMENTAL_CXX0X__ */ 3091e4b17023SJohn Marino 3092e4b17023SJohn Marino #endif /* _BASIC_STRING_H */ 3093