epoc32/include/tools/stlport/stl/_string_workaround.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
/*
williamr@2
     2
 * Copyright (c) 2004
williamr@2
     3
 * Francois Dumont
williamr@2
     4
 *
williamr@2
     5
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
     6
 * or implied. Any use is at your own risk.
williamr@2
     7
 *
williamr@2
     8
 * Permission to use or copy this software for any purpose is hereby granted
williamr@2
     9
 * without fee, provided the above notices are retained on all copies.
williamr@2
    10
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    11
 * provided the above notices are retained, and a notice that the code was
williamr@2
    12
 * modified is included with the above copyright notice.
williamr@2
    13
 *
williamr@2
    14
 */
williamr@2
    15
williamr@2
    16
//Included from _string.h, no need for macro guarding.
williamr@2
    17
williamr@2
    18
_STLP_BEGIN_NAMESPACE
williamr@2
    19
williamr@2
    20
#if defined (_STLP_DEBUG)
williamr@2
    21
#  define basic_string _STLP_NON_DBG_NAME(str)
williamr@2
    22
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@2
    23
#endif
williamr@2
    24
williamr@2
    25
#define _STLP_NO_MEM_T_STRING_BASE _STLP_PRIV _STLP_NO_MEM_T_NAME(str)<_CharT, _Traits, _Alloc>
williamr@2
    26
williamr@2
    27
template <class _CharT, class _Traits, class _Alloc>
williamr@2
    28
class basic_string : public _STLP_NO_MEM_T_STRING_BASE
williamr@2
    29
#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && \
williamr@2
    30
    !defined (basic_string)
williamr@2
    31
                   , public __stlport_class<basic_string<_CharT, _Traits, _Alloc> >
williamr@2
    32
#endif
williamr@2
    33
{
williamr@2
    34
protected:                        // Protected members inherited from base.
williamr@2
    35
  typedef basic_string<_CharT, _Traits, _Alloc> _Self;
williamr@2
    36
  typedef _STLP_NO_MEM_T_STRING_BASE _Base;
williamr@2
    37
  typedef typename _Base::_Char_Is_POD _Char_Is_POD;
williamr@2
    38
williamr@2
    39
public:
williamr@2
    40
williamr@2
    41
  __IMPORT_WITH_REVERSE_ITERATORS(_Base)
williamr@2
    42
williamr@2
    43
  typedef typename _Base::_Iterator_category _Iterator_category;
williamr@2
    44
  typedef typename _Base::traits_type traits_type;
williamr@2
    45
  typedef typename _Base::_Reserve_t _Reserve_t;
williamr@2
    46
williamr@2
    47
public:                         // Constructor, destructor, assignment.
williamr@2
    48
  explicit basic_string(const allocator_type& __a = allocator_type())
williamr@2
    49
    : _STLP_NO_MEM_T_STRING_BASE(__a) {}
williamr@2
    50
williamr@2
    51
  basic_string(_Reserve_t __r, size_t __n,
williamr@2
    52
               const allocator_type& __a = allocator_type())
williamr@2
    53
    : _STLP_NO_MEM_T_STRING_BASE(__r, __n, __a) {}
williamr@2
    54
williamr@2
    55
  basic_string(const _Self& __s)
williamr@2
    56
    : _STLP_NO_MEM_T_STRING_BASE(__s) {}
williamr@2
    57
williamr@2
    58
  basic_string(const _Self& __s, size_type __pos, size_type __n = npos,
williamr@2
    59
               const allocator_type& __a = allocator_type())
williamr@2
    60
    : _STLP_NO_MEM_T_STRING_BASE(__s, __pos, __n, __a) {}
williamr@2
    61
williamr@2
    62
  basic_string(const _CharT* __s, size_type __n,
williamr@2
    63
               const allocator_type& __a = allocator_type())
williamr@2
    64
    : _STLP_NO_MEM_T_STRING_BASE(__s, __n, __a) {}
williamr@2
    65
williamr@2
    66
  basic_string(const _CharT* __s,
williamr@2
    67
               const allocator_type& __a = allocator_type())
williamr@2
    68
    : _STLP_NO_MEM_T_STRING_BASE(__s, __a) {}
williamr@2
    69
williamr@2
    70
  basic_string(size_type __n, _CharT __c,
williamr@2
    71
               const allocator_type& __a = allocator_type())
williamr@2
    72
    : _STLP_NO_MEM_T_STRING_BASE(__n, __c, __a) {}
williamr@2
    73
williamr@2
    74
  basic_string(__move_source<_Self> src)
williamr@2
    75
    : _STLP_NO_MEM_T_STRING_BASE(__move_source<_Base>(src.get())) {}
williamr@2
    76
williamr@2
    77
  // Check to see if _InputIterator is an integer type.  If so, then
williamr@2
    78
  // it can't be an iterator.
williamr@2
    79
#if !(defined(__MRC__) || (defined(__SC__) && !defined(__DMC__))) //*ty 04/30/2001 - mpw compilers choke on this ctor
williamr@2
    80
  template <class _InputIterator>
williamr@2
    81
  basic_string(_InputIterator __f, _InputIterator __l,
williamr@2
    82
               const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)
williamr@2
    83
    : _STLP_NO_MEM_T_STRING_BASE(_Base::_CalledFromWorkaround_t(), __a) {
williamr@2
    84
    typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
williamr@2
    85
    _M_initialize_dispatch(__f, __l, _Integral());
williamr@2
    86
  }
williamr@2
    87
#  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
williamr@2
    88
  template <class _InputIterator>
williamr@2
    89
  basic_string(_InputIterator __f, _InputIterator __l)
williamr@2
    90
    : _STLP_NO_MEM_T_STRING_BASE(_Base::_CalledFromWorkaround_t(), allocator_type()) {
williamr@2
    91
    typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
williamr@2
    92
    _M_initialize_dispatch(__f, __l, _Integral());
williamr@2
    93
  }
williamr@2
    94
#  endif
williamr@2
    95
#endif /* !__MRC__ || (__SC__ && !__DMC__) */
williamr@2
    96
williamr@2
    97
  _Self& operator=(const _Self& __s) {
williamr@2
    98
    _Base::operator=(__s);
williamr@2
    99
    return *this;
williamr@2
   100
  }
williamr@2
   101
williamr@2
   102
  _Self& operator=(const _CharT* __s) {
williamr@2
   103
    _Base::operator=(__s);
williamr@2
   104
    return *this;
williamr@2
   105
  }
williamr@2
   106
williamr@2
   107
  _Self& operator=(_CharT __c) {
williamr@2
   108
    _Base::operator=(__c);
williamr@2
   109
    return *this;
williamr@2
   110
  }
williamr@2
   111
williamr@2
   112
private:
williamr@2
   113
  template <class _InputIter>
williamr@2
   114
  void _M_range_initialize(_InputIter __f, _InputIter __l,
williamr@2
   115
                           const input_iterator_tag &__tag) {
williamr@2
   116
    this->_M_allocate_block();
williamr@2
   117
    this->_M_construct_null(this->_M_Finish());
williamr@2
   118
    _STLP_TRY {
williamr@2
   119
      _M_appendT(__f, __l, __tag);
williamr@2
   120
    }
williamr@2
   121
    _STLP_UNWIND(this->_M_destroy_range())
williamr@2
   122
  }
williamr@2
   123
williamr@2
   124
  template <class _ForwardIter>
williamr@2
   125
  void _M_range_initialize(_ForwardIter __f, _ForwardIter __l,
williamr@2
   126
                           const forward_iterator_tag &) {
williamr@2
   127
    difference_type __n = distance(__f, __l);
williamr@2
   128
    this->_M_allocate_block(__n + 1);
williamr@2
   129
#if defined (_STLP_USE_SHORT_STRING_OPTIM)
williamr@2
   130
    if (this->_M_using_static_buf()) {
williamr@2
   131
      _M_copyT(__f, __l, this->_M_Start());
williamr@2
   132
      this->_M_finish = this->_M_Start() + __n;
williamr@2
   133
    }
williamr@2
   134
    else
williamr@2
   135
#endif /* _STLP_USE_SHORT_STRING_OPTIM */
williamr@2
   136
    this->_M_finish = uninitialized_copy(__f, __l, this->_M_Start());
williamr@2
   137
    this->_M_terminate_string();
williamr@2
   138
  }
williamr@2
   139
williamr@2
   140
  template <class _InputIter>
williamr@2
   141
  void _M_range_initializeT(_InputIter __f, _InputIter __l) {
williamr@2
   142
    _M_range_initialize(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
williamr@2
   143
  }
williamr@2
   144
williamr@2
   145
  template <class _Integer>
williamr@2
   146
  void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {
williamr@2
   147
    this->_M_allocate_block(__n + 1);
williamr@2
   148
#if defined (_STLP_USE_SHORT_STRING_OPTIM)
williamr@2
   149
    if (this->_M_using_static_buf()) {
williamr@2
   150
      _Traits::assign(this->_M_Start(), __n, __x);
williamr@2
   151
      this->_M_finish = this->_M_Start() + __n;
williamr@2
   152
    }
williamr@2
   153
    else
williamr@2
   154
#endif /* _STLP_USE_SHORT_STRING_OPTIM */
williamr@2
   155
    this->_M_finish = uninitialized_fill_n(this->_M_Start(), __n, __x);
williamr@2
   156
    this->_M_terminate_string();
williamr@2
   157
  }
williamr@2
   158
williamr@2
   159
  template <class _InputIter>
williamr@2
   160
  void _M_initialize_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) {
williamr@2
   161
    _M_range_initializeT(__f, __l);
williamr@2
   162
  }
williamr@2
   163
williamr@2
   164
public:                         // Append, operator+=, push_back.
williamr@2
   165
  _Self& operator+=(const _Self& __s) {
williamr@2
   166
    _Base::operator+=(__s);
williamr@2
   167
    return *this;
williamr@2
   168
  }
williamr@2
   169
  _Self& operator+=(const _CharT* __s) {
williamr@2
   170
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   171
    _Base::operator+=(__s);
williamr@2
   172
    return *this;
williamr@2
   173
  }
williamr@2
   174
  _Self& operator+=(_CharT __c) {
williamr@2
   175
    _Base::operator+=(__c);
williamr@2
   176
    return *this;
williamr@2
   177
  }
williamr@2
   178
williamr@2
   179
  _Self& append(const _Self& __s) {
williamr@2
   180
    _Base::append(__s);
williamr@2
   181
    return *this;
williamr@2
   182
  }
williamr@2
   183
williamr@2
   184
  _Self& append(const _Self& __s,
williamr@2
   185
                size_type __pos, size_type __n) {
williamr@2
   186
    _Base::append(__s, __pos, __n);
williamr@2
   187
    return *this;
williamr@2
   188
  }
williamr@2
   189
williamr@2
   190
  _Self& append(const _CharT* __s, size_type __n) {
williamr@2
   191
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   192
    _Base::append(__s, __n);
williamr@2
   193
    return *this;
williamr@2
   194
  }
williamr@2
   195
  _Self& append(const _CharT* __s) {
williamr@2
   196
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   197
    _Base::append(__s);
williamr@2
   198
    return *this;
williamr@2
   199
  }
williamr@2
   200
  _Self& append(size_type __n, _CharT __c) {
williamr@2
   201
    _Base::append(__n, __c);
williamr@2
   202
    return *this;
williamr@2
   203
  }
williamr@2
   204
williamr@2
   205
  // Check to see if _InputIterator is an integer type.  If so, then
williamr@2
   206
  // it can't be an iterator.
williamr@2
   207
  template <class _InputIter>
williamr@2
   208
  _Self& append(_InputIter __first, _InputIter __last) {
williamr@2
   209
    typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
williamr@2
   210
    return _M_append_dispatch(__first, __last, _Integral());
williamr@2
   211
  }
williamr@2
   212
williamr@2
   213
#if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
williamr@2
   214
  //See equivalent assign method remark.
williamr@2
   215
  _Self& append(const _CharT* __f, const _CharT* __l) {
williamr@2
   216
    _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
williamr@2
   217
    _Base::append(__f, __l);
williamr@2
   218
    return *this;
williamr@2
   219
  }
williamr@2
   220
#endif
williamr@2
   221
williamr@2
   222
private:                        // Helper functions for append.
williamr@2
   223
williamr@2
   224
  template <class _InputIter>
williamr@2
   225
  _Self& _M_appendT(_InputIter __first, _InputIter __last,
williamr@2
   226
                   const input_iterator_tag &) {
williamr@2
   227
    for ( ; __first != __last ; ++__first)
williamr@2
   228
      _Base::push_back(*__first);
williamr@2
   229
    return *this;
williamr@2
   230
  }
williamr@2
   231
williamr@2
   232
  template <class _ForwardIter>
williamr@2
   233
  _Self& _M_appendT(_ForwardIter __first, _ForwardIter __last,
williamr@2
   234
                    const forward_iterator_tag &)  {
williamr@2
   235
    if (__first != __last) {
williamr@2
   236
      const size_type __old_size = this->size();
williamr@2
   237
      difference_type __n = distance(__first, __last);
williamr@2
   238
      if (__STATIC_CAST(size_type,__n) > max_size() || __old_size > max_size() - __STATIC_CAST(size_type,__n))
williamr@2
   239
        this->_M_throw_length_error();
williamr@2
   240
      if (__old_size + __n > capacity()) {
williamr@2
   241
        const size_type __len = __old_size +
williamr@2
   242
          (max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;
williamr@2
   243
        pointer __new_start = this->_M_end_of_storage.allocate(__len);
williamr@2
   244
        pointer __new_finish = __new_start;
williamr@2
   245
        _STLP_TRY {
williamr@2
   246
          __new_finish = uninitialized_copy(this->_M_Start(), this->_M_Finish(), __new_start);
williamr@2
   247
          __new_finish = uninitialized_copy(__first, __last, __new_finish);
williamr@2
   248
          _M_construct_null(__new_finish);
williamr@2
   249
        }
williamr@2
   250
        _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
williamr@2
   251
          this->_M_end_of_storage.deallocate(__new_start,__len)))
williamr@2
   252
          this->_M_destroy_range();
williamr@2
   253
        this->_M_deallocate_block();
williamr@2
   254
        this->_M_reset(__new_start, __new_finish, __new_start + __len);
williamr@2
   255
      }
williamr@2
   256
      else {
williamr@2
   257
        _ForwardIter __f1 = __first;
williamr@2
   258
        ++__f1;
williamr@2
   259
#if defined (_STLP_USE_SHORT_STRING_OPTIM)
williamr@2
   260
        if (this->_M_using_static_buf())
williamr@2
   261
          _M_copyT(__f1, __last, this->_M_Finish() + 1);
williamr@2
   262
        else
williamr@2
   263
#endif /* _STLP_USE_SHORT_STRING_OPTIM */
williamr@2
   264
          uninitialized_copy(__f1, __last, this->_M_Finish() + 1);
williamr@2
   265
        _STLP_TRY {
williamr@2
   266
          this->_M_construct_null(this->_M_Finish() + __n);
williamr@2
   267
        }
williamr@2
   268
        _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_Finish() + 1, this->_M_Finish() + __n))
williamr@2
   269
        _Traits::assign(*this->_M_finish, *__first);
williamr@2
   270
        this->_M_finish += __n;
williamr@2
   271
      }
williamr@2
   272
    }
williamr@2
   273
    return *this;
williamr@2
   274
  }
williamr@2
   275
williamr@2
   276
  template <class _Integer>
williamr@2
   277
  _Self& _M_append_dispatch(_Integer __n, _Integer __x, const __true_type& /*Integral*/) {
williamr@2
   278
    return append((size_type) __n, (_CharT) __x);
williamr@2
   279
  }
williamr@2
   280
williamr@2
   281
  template <class _InputIter>
williamr@2
   282
  _Self& _M_append_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*Integral*/) {
williamr@2
   283
    return _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
williamr@2
   284
  }
williamr@2
   285
williamr@2
   286
public:                         // Assign
williamr@2
   287
williamr@2
   288
  _Self& assign(const _Self& __s) {
williamr@2
   289
    _Base::assign(__s);
williamr@2
   290
    return *this;
williamr@2
   291
  }
williamr@2
   292
williamr@2
   293
  _Self& assign(const _Self& __s,
williamr@2
   294
                size_type __pos, size_type __n) {
williamr@2
   295
    _Base::assign(__s, __pos, __n);
williamr@2
   296
    return *this;
williamr@2
   297
  }
williamr@2
   298
williamr@2
   299
  _Self& assign(const _CharT* __s, size_type __n) {
williamr@2
   300
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   301
    _Base::assign(__s, __n);
williamr@2
   302
    return *this;
williamr@2
   303
  }
williamr@2
   304
williamr@2
   305
  _Self& assign(const _CharT* __s) {
williamr@2
   306
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   307
    _Base::assign(__s);
williamr@2
   308
    return *this;
williamr@2
   309
  }
williamr@2
   310
williamr@2
   311
  _Self& assign(size_type __n, _CharT __c) {
williamr@2
   312
    _Base::assign(__n, __c);
williamr@2
   313
    return *this;
williamr@2
   314
  }
williamr@2
   315
williamr@2
   316
private:                        // Helper functions for assign.
williamr@2
   317
williamr@2
   318
  template <class _Integer>
williamr@2
   319
  _Self& _M_assign_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {
williamr@2
   320
    return assign((size_type) __n, (_CharT) __x);
williamr@2
   321
  }
williamr@2
   322
williamr@2
   323
  template <class _InputIter>
williamr@2
   324
  _Self& _M_assign_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/)  {
williamr@2
   325
    pointer __cur = this->_M_Start();
williamr@2
   326
    while (__f != __l && __cur != this->_M_Finish()) {
williamr@2
   327
      _Traits::assign(*__cur, *__f);
williamr@2
   328
      ++__f;
williamr@2
   329
      ++__cur;
williamr@2
   330
    }
williamr@2
   331
    if (__f == __l)
williamr@2
   332
      _Base::erase(__cur, this->_M_Finish());
williamr@2
   333
    else
williamr@2
   334
      _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
williamr@2
   335
    return *this;
williamr@2
   336
  }
williamr@2
   337
williamr@2
   338
public:
williamr@2
   339
  // Check to see if _InputIterator is an integer type.  If so, then
williamr@2
   340
  // it can't be an iterator.
williamr@2
   341
  template <class _InputIter>
williamr@2
   342
  _Self& assign(_InputIter __first, _InputIter __last) {
williamr@2
   343
    typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
williamr@2
   344
    return _M_assign_dispatch(__first, __last, _Integral());
williamr@2
   345
  }
williamr@2
   346
williamr@2
   347
#if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
williamr@2
   348
  /* This method is not part of the standard and is a specialization of the
williamr@2
   349
   * template method assign. It is only granted for convenience to call assign
williamr@2
   350
   * with mixed parameters iterator and const_iterator.
williamr@2
   351
   */
williamr@2
   352
  _Self& assign(const _CharT* __f, const _CharT* __l) {
williamr@2
   353
    _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
williamr@2
   354
    _Base::assign(__f, __l);
williamr@2
   355
    return *this;
williamr@2
   356
  }
williamr@2
   357
#endif
williamr@2
   358
williamr@2
   359
public:                         // Insert
williamr@2
   360
williamr@2
   361
  _Self& insert(size_type __pos, const _Self& __s) {
williamr@2
   362
    _Base::insert(__pos, __s);
williamr@2
   363
    return *this;
williamr@2
   364
  }
williamr@2
   365
williamr@2
   366
  _Self& insert(size_type __pos, const _Self& __s,
williamr@2
   367
                size_type __beg, size_type __n) {
williamr@2
   368
    _Base::insert(__pos, __s, __beg, __n);
williamr@2
   369
    return *this;
williamr@2
   370
  }
williamr@2
   371
  _Self& insert(size_type __pos, const _CharT* __s, size_type __n) {
williamr@2
   372
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   373
    _Base::insert(__pos, __s, __n);
williamr@2
   374
    return *this;
williamr@2
   375
  }
williamr@2
   376
williamr@2
   377
  _Self& insert(size_type __pos, const _CharT* __s) {
williamr@2
   378
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   379
    _Base::insert(__pos, __s);
williamr@2
   380
    return *this;
williamr@2
   381
  }
williamr@2
   382
williamr@2
   383
  _Self& insert(size_type __pos, size_type __n, _CharT __c) {
williamr@2
   384
    _Base::insert(__pos, __n, __c);
williamr@2
   385
    return *this;
williamr@2
   386
  }
williamr@2
   387
williamr@2
   388
  iterator insert(iterator __p, _CharT __c) {
williamr@2
   389
    return _Base::insert(__p, __c);
williamr@2
   390
  }
williamr@2
   391
williamr@2
   392
  void insert(iterator __p, size_t __n, _CharT __c) {
williamr@2
   393
    _Base::insert(__p, __n, __c);
williamr@2
   394
  }
williamr@2
   395
williamr@2
   396
  // Check to see if _InputIterator is an integer type.  If so, then
williamr@2
   397
  // it can't be an iterator.
williamr@2
   398
  template <class _InputIter>
williamr@2
   399
  void insert(iterator __p, _InputIter __first, _InputIter __last) {
williamr@2
   400
    typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
williamr@2
   401
    _M_insert_dispatch(__p, __first, __last, _Integral());
williamr@2
   402
  }
williamr@2
   403
williamr@2
   404
private:  // Helper functions for insert.
williamr@2
   405
williamr@2
   406
  void _M_insert(iterator __p, const _CharT* __f, const _CharT* __l, bool __self_ref) {
williamr@2
   407
    _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
williamr@2
   408
    _Base::_M_insert(__p, __f, __l, __self_ref);
williamr@2
   409
  }
williamr@2
   410
williamr@2
   411
  template <class _ForwardIter>
williamr@2
   412
  void _M_insert_overflow(iterator __position, _ForwardIter __first, _ForwardIter __last,
williamr@2
   413
                          difference_type __n) {
williamr@2
   414
    const size_type __old_size = this->size();
williamr@2
   415
    const size_type __len = __old_size + (max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;
williamr@2
   416
    pointer __new_start = this->_M_end_of_storage.allocate(__len);
williamr@2
   417
    pointer __new_finish = __new_start;
williamr@2
   418
    _STLP_TRY {
williamr@2
   419
      __new_finish = uninitialized_copy(this->_M_Start(), __position, __new_start);
williamr@2
   420
      __new_finish = uninitialized_copy(__first, __last, __new_finish);
williamr@2
   421
      __new_finish = uninitialized_copy(__position, this->_M_Finish(), __new_finish);
williamr@2
   422
      this->_M_construct_null(__new_finish);
williamr@2
   423
    }
williamr@2
   424
    _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
williamr@2
   425
                  this->_M_end_of_storage.deallocate(__new_start,__len)))
williamr@2
   426
    this->_M_destroy_range();
williamr@2
   427
    this->_M_deallocate_block();
williamr@2
   428
    this->_M_reset(__new_start, __new_finish, __new_start + __len);
williamr@2
   429
  }
williamr@2
   430
williamr@2
   431
  template <class _InputIter>
williamr@2
   432
  void _M_insertT(iterator __p, _InputIter __first, _InputIter __last,
williamr@2
   433
                  const input_iterator_tag &) {
williamr@2
   434
    for ( ; __first != __last; ++__first) {
williamr@2
   435
      __p = insert(__p, *__first);
williamr@2
   436
      ++__p;
williamr@2
   437
    }
williamr@2
   438
  }
williamr@2
   439
williamr@2
   440
  template <class _ForwardIter>
williamr@2
   441
  void _M_insertT(iterator __position, _ForwardIter __first, _ForwardIter __last,
williamr@2
   442
                  const forward_iterator_tag &) {
williamr@2
   443
    if (__first != __last) {
williamr@2
   444
      difference_type __n = distance(__first, __last);
williamr@2
   445
      if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
williamr@2
   446
        const difference_type __elems_after = this->_M_finish - __position;
williamr@2
   447
        if (__elems_after >= __n) {
williamr@2
   448
#if defined (_STLP_USE_SHORT_STRING_OPTIM)
williamr@2
   449
          if (this->_M_using_static_buf())
williamr@2
   450
            _Base::_M_copy((this->_M_Finish() - __n) + 1, this->_M_Finish() + 1, this->_M_Finish() + 1);
williamr@2
   451
          else
williamr@2
   452
#endif /* _STLP_USE_SHORT_STRING_OPTIM */
williamr@2
   453
          uninitialized_copy((this->_M_Finish() - __n) + 1, this->_M_Finish() + 1, this->_M_Finish() + 1);
williamr@2
   454
          this->_M_finish += __n;
williamr@2
   455
          _Traits::move(__position + __n, __position, (__elems_after - __n) + 1);
williamr@2
   456
          _M_copyT(__first, __last, __position);
williamr@2
   457
        }
williamr@2
   458
        else {
williamr@2
   459
          pointer __old_finish = this->_M_Finish();
williamr@2
   460
          _ForwardIter __mid = __first;
williamr@2
   461
          advance(__mid, __elems_after + 1);
williamr@2
   462
#if defined (_STLP_USE_SHORT_STRING_OPTIM)
williamr@2
   463
          if (this->_M_using_static_buf())
williamr@2
   464
            _M_copyT(__mid, __last, this->_M_Finish() + 1);
williamr@2
   465
          else
williamr@2
   466
#endif /* _STLP_USE_SHORT_STRING_OPTIM */
williamr@2
   467
          uninitialized_copy(__mid, __last, this->_M_Finish() + 1);
williamr@2
   468
          this->_M_finish += __n - __elems_after;
williamr@2
   469
          _STLP_TRY {
williamr@2
   470
#if defined (_STLP_USE_SHORT_STRING_OPTIM)
williamr@2
   471
            if (this->_M_using_static_buf())
williamr@2
   472
              _Base::_M_copy(__position, __old_finish + 1, this->_M_Finish());
williamr@2
   473
            else
williamr@2
   474
#endif /* _STLP_USE_SHORT_STRING_OPTIM */
williamr@2
   475
            uninitialized_copy(__position, __old_finish + 1, this->_M_Finish());
williamr@2
   476
            this->_M_finish += __elems_after;
williamr@2
   477
          }
williamr@2
   478
          _STLP_UNWIND((this->_M_destroy_ptr_range(__old_finish + 1, this->_M_Finish()),
williamr@2
   479
                        this->_M_finish = __old_finish))
williamr@2
   480
          _M_copyT(__first, __mid, __position);
williamr@2
   481
        }
williamr@2
   482
      }
williamr@2
   483
      else {
williamr@2
   484
        _M_insert_overflow(__position, __first, __last, __n);
williamr@2
   485
      }
williamr@2
   486
    }
williamr@2
   487
  }
williamr@2
   488
williamr@2
   489
  template <class _Integer>
williamr@2
   490
  void _M_insert_dispatch(iterator __p, _Integer __n, _Integer __x,
williamr@2
   491
                          const __true_type& /*Integral*/) {
williamr@2
   492
    insert(__p, (size_type) __n, (_CharT) __x);
williamr@2
   493
  }
williamr@2
   494
williamr@2
   495
  template <class _InputIter>
williamr@2
   496
  void _M_insert_dispatch(iterator __p, _InputIter __first, _InputIter __last,
williamr@2
   497
                          const __false_type& /*Integral*/) {
williamr@2
   498
    _STLP_FIX_LITERAL_BUG(__p)
williamr@2
   499
    /*
williamr@2
   500
     * Within the basic_string implementation we are only going to check for
williamr@2
   501
     * self referencing if iterators are string iterators or _CharT pointers.
williamr@2
   502
     * A user could encapsulate those iterator within their own iterator interface
williamr@2
   503
     * and in this case lead to a bad behavior, this is a known limitation.
williamr@2
   504
     */
williamr@2
   505
    typedef typename _AreSameUnCVTypes<_InputIter, iterator>::_Ret _IsIterator;
williamr@2
   506
    typedef typename _AreSameUnCVTypes<_InputIter, const_iterator>::_Ret _IsConstIterator;
williamr@2
   507
    typedef typename _Lor2<_IsIterator, _IsConstIterator>::_Ret _CheckInside;
williamr@2
   508
    _M_insert_aux(__p, __first, __last, _CheckInside());
williamr@2
   509
  }
williamr@2
   510
williamr@2
   511
  template <class _RandomIter>
williamr@2
   512
  void _M_insert_aux (iterator __p, _RandomIter __first, _RandomIter __last,
williamr@2
   513
                      const __true_type& /*_CheckInside*/) {
williamr@2
   514
    _STLP_FIX_LITERAL_BUG(__p)
williamr@2
   515
    _M_insert(__p, &(*__first), &(*__last), _Base::_M_inside(&(*__first)));
williamr@2
   516
  }
williamr@2
   517
williamr@2
   518
  template<class _InputIter>
williamr@2
   519
  void _M_insert_aux (iterator __p, _InputIter __first, _InputIter __last,
williamr@2
   520
                      const __false_type& /*_CheckInside*/) {
williamr@2
   521
    _STLP_FIX_LITERAL_BUG(__p)
williamr@2
   522
    _M_insertT(__p, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
williamr@2
   523
  }
williamr@2
   524
williamr@2
   525
  template <class _InputIterator>
williamr@2
   526
  void _M_copyT(_InputIterator __first, _InputIterator __last, pointer __result) {
williamr@2
   527
    _STLP_FIX_LITERAL_BUG(__p)
williamr@2
   528
    for ( ; __first != __last; ++__first, ++__result)
williamr@2
   529
      _Traits::assign(*__result, *__first);
williamr@2
   530
  }
williamr@2
   531
williamr@2
   532
#if !defined (_STLP_NO_METHOD_SPECIALIZATION)
williamr@2
   533
  void _M_copyT(const _CharT* __f, const _CharT* __l, _CharT* __res) {
williamr@2
   534
    _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) _STLP_FIX_LITERAL_BUG(__res)
williamr@2
   535
    _Base::_M_copy(__f, __l, __res);
williamr@2
   536
  }
williamr@2
   537
#endif
williamr@2
   538
williamr@2
   539
public:                         // Erase.
williamr@2
   540
williamr@2
   541
  _Self& erase(size_type __pos = 0, size_type __n = npos) {
williamr@2
   542
    _Base::erase(__pos, __n);
williamr@2
   543
    return *this;
williamr@2
   544
  }
williamr@2
   545
williamr@2
   546
  iterator erase(iterator __pos) {
williamr@2
   547
    _STLP_FIX_LITERAL_BUG(__pos)
williamr@2
   548
    return _Base::erase(__pos);
williamr@2
   549
  }
williamr@2
   550
williamr@2
   551
  iterator erase(iterator __first, iterator __last) {
williamr@2
   552
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   553
    return _Base::erase(__first, __last);
williamr@2
   554
  }
williamr@2
   555
williamr@2
   556
public:                         // Replace.  (Conceptually equivalent
williamr@2
   557
                                // to erase followed by insert.)
williamr@2
   558
  _Self& replace(size_type __pos, size_type __n, const _Self& __s) {
williamr@2
   559
    _Base::replace(__pos, __n, __s);
williamr@2
   560
    return *this;
williamr@2
   561
  }
williamr@2
   562
williamr@2
   563
  _Self& replace(size_type __pos1, size_type __n1, const _Self& __s,
williamr@2
   564
                 size_type __pos2, size_type __n2) {
williamr@2
   565
    _Base::replace(__pos1, __n1, __s, __pos2, __n2);
williamr@2
   566
    return *this;
williamr@2
   567
  }
williamr@2
   568
williamr@2
   569
  _Self& replace(size_type __pos, size_type __n1,
williamr@2
   570
                 const _CharT* __s, size_type __n2) {
williamr@2
   571
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   572
    _Base::replace(__pos, __n1, __s, __n2);
williamr@2
   573
    return *this;
williamr@2
   574
  }
williamr@2
   575
williamr@2
   576
  _Self& replace(size_type __pos, size_type __n1, const _CharT* __s) {
williamr@2
   577
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   578
    _Base::replace(__pos, __n1, __s);
williamr@2
   579
    return *this;
williamr@2
   580
  }
williamr@2
   581
williamr@2
   582
  _Self& replace(size_type __pos, size_type __n1,
williamr@2
   583
                 size_type __n2, _CharT __c) {
williamr@2
   584
    _Base::replace(__pos, __n1, __n2, __c);
williamr@2
   585
    return *this;
williamr@2
   586
  }
williamr@2
   587
williamr@2
   588
  _Self& replace(iterator __first, iterator __last, const _Self& __s) {
williamr@2
   589
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   590
    _Base::replace(__first, __last, __s);
williamr@2
   591
    return *this;
williamr@2
   592
  }
williamr@2
   593
williamr@2
   594
  _Self& replace(iterator __first, iterator __last,
williamr@2
   595
                 const _CharT* __s, size_type __n) {
williamr@2
   596
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   597
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   598
    _Base::replace(__first, __last, __s, __n);
williamr@2
   599
    return *this;
williamr@2
   600
  }
williamr@2
   601
williamr@2
   602
  _Self& replace(iterator __first, iterator __last,
williamr@2
   603
                 const _CharT* __s) {
williamr@2
   604
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   605
    _STLP_FIX_LITERAL_BUG(__s)
williamr@2
   606
    _Base::replace(__first, __last, __s);
williamr@2
   607
    return *this;
williamr@2
   608
  }
williamr@2
   609
williamr@2
   610
  _Self& replace(iterator __first, iterator __last,
williamr@2
   611
                 size_type __n, _CharT __c) {
williamr@2
   612
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   613
    _Base::replace(__first, __last, __n, __c);
williamr@2
   614
    return *this;
williamr@2
   615
  }
williamr@2
   616
williamr@2
   617
  // Check to see if _InputIter is an integer type.  If so, then
williamr@2
   618
  // it can't be an iterator.
williamr@2
   619
  template <class _InputIter>
williamr@2
   620
  _Self& replace(iterator __first, iterator __last,
williamr@2
   621
                 _InputIter __f, _InputIter __l) {
williamr@2
   622
    _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
williamr@2
   623
    typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
williamr@2
   624
    return _M_replace_dispatch(__first, __last, __f, __l,  _Integral());
williamr@2
   625
  }
williamr@2
   626
williamr@2
   627
#if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
williamr@2
   628
  _Self& replace(iterator __first, iterator __last,
williamr@2
   629
                 const _CharT* __f, const _CharT* __l) {
williamr@2
   630
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   631
    _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
williamr@2
   632
    _Base::replace(__first, __last, __f, __l);
williamr@2
   633
    return *this;
williamr@2
   634
  }
williamr@2
   635
#endif
williamr@2
   636
williamr@2
   637
protected:                        // Helper functions for replace.
williamr@2
   638
  _Self& _M_replace(iterator __first, iterator __last,
williamr@2
   639
                    const _CharT* __f, const _CharT* __l, bool __self_ref) {
williamr@2
   640
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   641
    _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
williamr@2
   642
    _Base::_M_replace(__first, __last, __f, __l, __self_ref);
williamr@2
   643
    return *this;
williamr@2
   644
  }
williamr@2
   645
williamr@2
   646
  template <class _Integer>
williamr@2
   647
  _Self& _M_replace_dispatch(iterator __first, iterator __last,
williamr@2
   648
                             _Integer __n, _Integer __x, const __true_type& /*IsIntegral*/) {
williamr@2
   649
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   650
    return replace(__first, __last, (size_type) __n, (_CharT) __x);
williamr@2
   651
  }
williamr@2
   652
williamr@2
   653
  template <class _InputIter>
williamr@2
   654
  _Self& _M_replace_dispatch(iterator __first, iterator __last,
williamr@2
   655
                             _InputIter __f, _InputIter __l, const __false_type& /*IsIntegral*/) {
williamr@2
   656
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   657
    typedef typename _AreSameUnCVTypes<_InputIter, iterator>::_Ret _IsIterator;
williamr@2
   658
    typedef typename _AreSameUnCVTypes<_InputIter, const_iterator>::_Ret _IsConstIterator;
williamr@2
   659
    typedef typename _Lor2<_IsIterator, _IsConstIterator>::_Ret _CheckInside;
williamr@2
   660
    return _M_replace_aux(__first, __last, __f, __l, _CheckInside());
williamr@2
   661
  }
williamr@2
   662
williamr@2
   663
  template <class _RandomIter>
williamr@2
   664
  _Self& _M_replace_aux(iterator __first, iterator __last,
williamr@2
   665
                        _RandomIter __f, _RandomIter __l, __true_type const& /*_CheckInside*/) {
williamr@2
   666
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   667
    return _M_replace(__first, __last, &(*__f), &(*__l), _Base::_M_inside(&(*__f)));
williamr@2
   668
  }
williamr@2
   669
williamr@2
   670
  template <class _InputIter>
williamr@2
   671
  _Self& _M_replace_aux(iterator __first, iterator __last,
williamr@2
   672
                     _InputIter __f, _InputIter __l, __false_type const& /*_CheckInside*/) {
williamr@2
   673
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   674
    return _M_replaceT(__first, __last, __f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
williamr@2
   675
  }
williamr@2
   676
williamr@2
   677
  template <class _InputIter>
williamr@2
   678
  _Self& _M_replaceT(iterator __first, iterator __last,
williamr@2
   679
                     _InputIter __f, _InputIter __l, const input_iterator_tag&__ite_tag) {
williamr@2
   680
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   681
    for ( ; __first != __last && __f != __l; ++__first, ++__f)
williamr@2
   682
      _Traits::assign(*__first, *__f);
williamr@2
   683
    if (__f == __l)
williamr@2
   684
      _Base::erase(__first, __last);
williamr@2
   685
    else
williamr@2
   686
      _M_insertT(__last, __f, __l, __ite_tag);
williamr@2
   687
    return *this;
williamr@2
   688
  }
williamr@2
   689
williamr@2
   690
  template <class _ForwardIter>
williamr@2
   691
  _Self& _M_replaceT(iterator __first, iterator __last,
williamr@2
   692
                     _ForwardIter __f, _ForwardIter __l, const forward_iterator_tag &__ite_tag) {
williamr@2
   693
    _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
williamr@2
   694
    difference_type __n = distance(__f, __l);
williamr@2
   695
    const difference_type __len = __last - __first;
williamr@2
   696
    if (__len >= __n) {
williamr@2
   697
      _M_copyT(__f, __l, __first);
williamr@2
   698
      _Base::erase(__first + __n, __last);
williamr@2
   699
    }
williamr@2
   700
    else {
williamr@2
   701
      _ForwardIter __m = __f;
williamr@2
   702
      advance(__m, __len);
williamr@2
   703
      _M_copyT(__f, __m, __first);
williamr@2
   704
      _M_insertT(__last, __m, __l, __ite_tag);
williamr@2
   705
    }
williamr@2
   706
    return *this;
williamr@2
   707
  }
williamr@2
   708
williamr@2
   709
public:                         // Other modifier member functions.
williamr@2
   710
williamr@2
   711
  void swap(_Self& __s)
williamr@2
   712
  { _Base::swap(__s); }
williamr@2
   713
williamr@2
   714
public:                         // Substring.
williamr@2
   715
williamr@2
   716
  _Self substr(size_type __pos = 0, size_type __n = npos) const
williamr@2
   717
  { return _Self(*this, __pos, __n, get_allocator()); }
williamr@2
   718
williamr@2
   719
#if defined (_STLP_USE_TEMPLATE_EXPRESSION) && !defined (_STLP_DEBUG)
williamr@2
   720
#  define _STLP_STRING_SUM_BASE _STLP_NO_MEM_T_STRING_BASE
williamr@2
   721
#  include <stl/_string_sum_methods.h>
williamr@2
   722
#  undef _STLP_STRING_SUM_BASE
williamr@2
   723
#endif
williamr@2
   724
};
williamr@2
   725
williamr@2
   726
#undef _STLP_NO_MEM_T_STRING_BASE
williamr@2
   727
williamr@2
   728
#if defined (basic_string)
williamr@2
   729
_STLP_MOVE_TO_STD_NAMESPACE
williamr@2
   730
#  undef basic_string
williamr@2
   731
#endif
williamr@2
   732
williamr@2
   733
_STLP_END_NAMESPACE