1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/tools/stlport/stl/_string_workaround.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,733 @@
1.4 +/*
1.5 + * Copyright (c) 2004
1.6 + * Francois Dumont
1.7 + *
1.8 + * This material is provided "as is", with absolutely no warranty expressed
1.9 + * or implied. Any use is at your own risk.
1.10 + *
1.11 + * Permission to use or copy this software for any purpose is hereby granted
1.12 + * without fee, provided the above notices are retained on all copies.
1.13 + * Permission to modify the code and to distribute modified code is granted,
1.14 + * provided the above notices are retained, and a notice that the code was
1.15 + * modified is included with the above copyright notice.
1.16 + *
1.17 + */
1.18 +
1.19 +//Included from _string.h, no need for macro guarding.
1.20 +
1.21 +_STLP_BEGIN_NAMESPACE
1.22 +
1.23 +#if defined (_STLP_DEBUG)
1.24 +# define basic_string _STLP_NON_DBG_NAME(str)
1.25 +_STLP_MOVE_TO_PRIV_NAMESPACE
1.26 +#endif
1.27 +
1.28 +#define _STLP_NO_MEM_T_STRING_BASE _STLP_PRIV _STLP_NO_MEM_T_NAME(str)<_CharT, _Traits, _Alloc>
1.29 +
1.30 +template <class _CharT, class _Traits, class _Alloc>
1.31 +class basic_string : public _STLP_NO_MEM_T_STRING_BASE
1.32 +#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && \
1.33 + !defined (basic_string)
1.34 + , public __stlport_class<basic_string<_CharT, _Traits, _Alloc> >
1.35 +#endif
1.36 +{
1.37 +protected: // Protected members inherited from base.
1.38 + typedef basic_string<_CharT, _Traits, _Alloc> _Self;
1.39 + typedef _STLP_NO_MEM_T_STRING_BASE _Base;
1.40 + typedef typename _Base::_Char_Is_POD _Char_Is_POD;
1.41 +
1.42 +public:
1.43 +
1.44 + __IMPORT_WITH_REVERSE_ITERATORS(_Base)
1.45 +
1.46 + typedef typename _Base::_Iterator_category _Iterator_category;
1.47 + typedef typename _Base::traits_type traits_type;
1.48 + typedef typename _Base::_Reserve_t _Reserve_t;
1.49 +
1.50 +public: // Constructor, destructor, assignment.
1.51 + explicit basic_string(const allocator_type& __a = allocator_type())
1.52 + : _STLP_NO_MEM_T_STRING_BASE(__a) {}
1.53 +
1.54 + basic_string(_Reserve_t __r, size_t __n,
1.55 + const allocator_type& __a = allocator_type())
1.56 + : _STLP_NO_MEM_T_STRING_BASE(__r, __n, __a) {}
1.57 +
1.58 + basic_string(const _Self& __s)
1.59 + : _STLP_NO_MEM_T_STRING_BASE(__s) {}
1.60 +
1.61 + basic_string(const _Self& __s, size_type __pos, size_type __n = npos,
1.62 + const allocator_type& __a = allocator_type())
1.63 + : _STLP_NO_MEM_T_STRING_BASE(__s, __pos, __n, __a) {}
1.64 +
1.65 + basic_string(const _CharT* __s, size_type __n,
1.66 + const allocator_type& __a = allocator_type())
1.67 + : _STLP_NO_MEM_T_STRING_BASE(__s, __n, __a) {}
1.68 +
1.69 + basic_string(const _CharT* __s,
1.70 + const allocator_type& __a = allocator_type())
1.71 + : _STLP_NO_MEM_T_STRING_BASE(__s, __a) {}
1.72 +
1.73 + basic_string(size_type __n, _CharT __c,
1.74 + const allocator_type& __a = allocator_type())
1.75 + : _STLP_NO_MEM_T_STRING_BASE(__n, __c, __a) {}
1.76 +
1.77 + basic_string(__move_source<_Self> src)
1.78 + : _STLP_NO_MEM_T_STRING_BASE(__move_source<_Base>(src.get())) {}
1.79 +
1.80 + // Check to see if _InputIterator is an integer type. If so, then
1.81 + // it can't be an iterator.
1.82 +#if !(defined(__MRC__) || (defined(__SC__) && !defined(__DMC__))) //*ty 04/30/2001 - mpw compilers choke on this ctor
1.83 + template <class _InputIterator>
1.84 + basic_string(_InputIterator __f, _InputIterator __l,
1.85 + const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)
1.86 + : _STLP_NO_MEM_T_STRING_BASE(_Base::_CalledFromWorkaround_t(), __a) {
1.87 + typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
1.88 + _M_initialize_dispatch(__f, __l, _Integral());
1.89 + }
1.90 +# if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
1.91 + template <class _InputIterator>
1.92 + basic_string(_InputIterator __f, _InputIterator __l)
1.93 + : _STLP_NO_MEM_T_STRING_BASE(_Base::_CalledFromWorkaround_t(), allocator_type()) {
1.94 + typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
1.95 + _M_initialize_dispatch(__f, __l, _Integral());
1.96 + }
1.97 +# endif
1.98 +#endif /* !__MRC__ || (__SC__ && !__DMC__) */
1.99 +
1.100 + _Self& operator=(const _Self& __s) {
1.101 + _Base::operator=(__s);
1.102 + return *this;
1.103 + }
1.104 +
1.105 + _Self& operator=(const _CharT* __s) {
1.106 + _Base::operator=(__s);
1.107 + return *this;
1.108 + }
1.109 +
1.110 + _Self& operator=(_CharT __c) {
1.111 + _Base::operator=(__c);
1.112 + return *this;
1.113 + }
1.114 +
1.115 +private:
1.116 + template <class _InputIter>
1.117 + void _M_range_initialize(_InputIter __f, _InputIter __l,
1.118 + const input_iterator_tag &__tag) {
1.119 + this->_M_allocate_block();
1.120 + this->_M_construct_null(this->_M_Finish());
1.121 + _STLP_TRY {
1.122 + _M_appendT(__f, __l, __tag);
1.123 + }
1.124 + _STLP_UNWIND(this->_M_destroy_range())
1.125 + }
1.126 +
1.127 + template <class _ForwardIter>
1.128 + void _M_range_initialize(_ForwardIter __f, _ForwardIter __l,
1.129 + const forward_iterator_tag &) {
1.130 + difference_type __n = distance(__f, __l);
1.131 + this->_M_allocate_block(__n + 1);
1.132 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
1.133 + if (this->_M_using_static_buf()) {
1.134 + _M_copyT(__f, __l, this->_M_Start());
1.135 + this->_M_finish = this->_M_Start() + __n;
1.136 + }
1.137 + else
1.138 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
1.139 + this->_M_finish = uninitialized_copy(__f, __l, this->_M_Start());
1.140 + this->_M_terminate_string();
1.141 + }
1.142 +
1.143 + template <class _InputIter>
1.144 + void _M_range_initializeT(_InputIter __f, _InputIter __l) {
1.145 + _M_range_initialize(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
1.146 + }
1.147 +
1.148 + template <class _Integer>
1.149 + void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {
1.150 + this->_M_allocate_block(__n + 1);
1.151 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
1.152 + if (this->_M_using_static_buf()) {
1.153 + _Traits::assign(this->_M_Start(), __n, __x);
1.154 + this->_M_finish = this->_M_Start() + __n;
1.155 + }
1.156 + else
1.157 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
1.158 + this->_M_finish = uninitialized_fill_n(this->_M_Start(), __n, __x);
1.159 + this->_M_terminate_string();
1.160 + }
1.161 +
1.162 + template <class _InputIter>
1.163 + void _M_initialize_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) {
1.164 + _M_range_initializeT(__f, __l);
1.165 + }
1.166 +
1.167 +public: // Append, operator+=, push_back.
1.168 + _Self& operator+=(const _Self& __s) {
1.169 + _Base::operator+=(__s);
1.170 + return *this;
1.171 + }
1.172 + _Self& operator+=(const _CharT* __s) {
1.173 + _STLP_FIX_LITERAL_BUG(__s)
1.174 + _Base::operator+=(__s);
1.175 + return *this;
1.176 + }
1.177 + _Self& operator+=(_CharT __c) {
1.178 + _Base::operator+=(__c);
1.179 + return *this;
1.180 + }
1.181 +
1.182 + _Self& append(const _Self& __s) {
1.183 + _Base::append(__s);
1.184 + return *this;
1.185 + }
1.186 +
1.187 + _Self& append(const _Self& __s,
1.188 + size_type __pos, size_type __n) {
1.189 + _Base::append(__s, __pos, __n);
1.190 + return *this;
1.191 + }
1.192 +
1.193 + _Self& append(const _CharT* __s, size_type __n) {
1.194 + _STLP_FIX_LITERAL_BUG(__s)
1.195 + _Base::append(__s, __n);
1.196 + return *this;
1.197 + }
1.198 + _Self& append(const _CharT* __s) {
1.199 + _STLP_FIX_LITERAL_BUG(__s)
1.200 + _Base::append(__s);
1.201 + return *this;
1.202 + }
1.203 + _Self& append(size_type __n, _CharT __c) {
1.204 + _Base::append(__n, __c);
1.205 + return *this;
1.206 + }
1.207 +
1.208 + // Check to see if _InputIterator is an integer type. If so, then
1.209 + // it can't be an iterator.
1.210 + template <class _InputIter>
1.211 + _Self& append(_InputIter __first, _InputIter __last) {
1.212 + typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
1.213 + return _M_append_dispatch(__first, __last, _Integral());
1.214 + }
1.215 +
1.216 +#if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
1.217 + //See equivalent assign method remark.
1.218 + _Self& append(const _CharT* __f, const _CharT* __l) {
1.219 + _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
1.220 + _Base::append(__f, __l);
1.221 + return *this;
1.222 + }
1.223 +#endif
1.224 +
1.225 +private: // Helper functions for append.
1.226 +
1.227 + template <class _InputIter>
1.228 + _Self& _M_appendT(_InputIter __first, _InputIter __last,
1.229 + const input_iterator_tag &) {
1.230 + for ( ; __first != __last ; ++__first)
1.231 + _Base::push_back(*__first);
1.232 + return *this;
1.233 + }
1.234 +
1.235 + template <class _ForwardIter>
1.236 + _Self& _M_appendT(_ForwardIter __first, _ForwardIter __last,
1.237 + const forward_iterator_tag &) {
1.238 + if (__first != __last) {
1.239 + const size_type __old_size = this->size();
1.240 + difference_type __n = distance(__first, __last);
1.241 + if (__STATIC_CAST(size_type,__n) > max_size() || __old_size > max_size() - __STATIC_CAST(size_type,__n))
1.242 + this->_M_throw_length_error();
1.243 + if (__old_size + __n > capacity()) {
1.244 + const size_type __len = __old_size +
1.245 + (max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;
1.246 + pointer __new_start = this->_M_end_of_storage.allocate(__len);
1.247 + pointer __new_finish = __new_start;
1.248 + _STLP_TRY {
1.249 + __new_finish = uninitialized_copy(this->_M_Start(), this->_M_Finish(), __new_start);
1.250 + __new_finish = uninitialized_copy(__first, __last, __new_finish);
1.251 + _M_construct_null(__new_finish);
1.252 + }
1.253 + _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
1.254 + this->_M_end_of_storage.deallocate(__new_start,__len)))
1.255 + this->_M_destroy_range();
1.256 + this->_M_deallocate_block();
1.257 + this->_M_reset(__new_start, __new_finish, __new_start + __len);
1.258 + }
1.259 + else {
1.260 + _ForwardIter __f1 = __first;
1.261 + ++__f1;
1.262 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
1.263 + if (this->_M_using_static_buf())
1.264 + _M_copyT(__f1, __last, this->_M_Finish() + 1);
1.265 + else
1.266 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
1.267 + uninitialized_copy(__f1, __last, this->_M_Finish() + 1);
1.268 + _STLP_TRY {
1.269 + this->_M_construct_null(this->_M_Finish() + __n);
1.270 + }
1.271 + _STLP_UNWIND(this->_M_destroy_ptr_range(this->_M_Finish() + 1, this->_M_Finish() + __n))
1.272 + _Traits::assign(*this->_M_finish, *__first);
1.273 + this->_M_finish += __n;
1.274 + }
1.275 + }
1.276 + return *this;
1.277 + }
1.278 +
1.279 + template <class _Integer>
1.280 + _Self& _M_append_dispatch(_Integer __n, _Integer __x, const __true_type& /*Integral*/) {
1.281 + return append((size_type) __n, (_CharT) __x);
1.282 + }
1.283 +
1.284 + template <class _InputIter>
1.285 + _Self& _M_append_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*Integral*/) {
1.286 + return _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
1.287 + }
1.288 +
1.289 +public: // Assign
1.290 +
1.291 + _Self& assign(const _Self& __s) {
1.292 + _Base::assign(__s);
1.293 + return *this;
1.294 + }
1.295 +
1.296 + _Self& assign(const _Self& __s,
1.297 + size_type __pos, size_type __n) {
1.298 + _Base::assign(__s, __pos, __n);
1.299 + return *this;
1.300 + }
1.301 +
1.302 + _Self& assign(const _CharT* __s, size_type __n) {
1.303 + _STLP_FIX_LITERAL_BUG(__s)
1.304 + _Base::assign(__s, __n);
1.305 + return *this;
1.306 + }
1.307 +
1.308 + _Self& assign(const _CharT* __s) {
1.309 + _STLP_FIX_LITERAL_BUG(__s)
1.310 + _Base::assign(__s);
1.311 + return *this;
1.312 + }
1.313 +
1.314 + _Self& assign(size_type __n, _CharT __c) {
1.315 + _Base::assign(__n, __c);
1.316 + return *this;
1.317 + }
1.318 +
1.319 +private: // Helper functions for assign.
1.320 +
1.321 + template <class _Integer>
1.322 + _Self& _M_assign_dispatch(_Integer __n, _Integer __x, const __true_type& /*_Integral*/) {
1.323 + return assign((size_type) __n, (_CharT) __x);
1.324 + }
1.325 +
1.326 + template <class _InputIter>
1.327 + _Self& _M_assign_dispatch(_InputIter __f, _InputIter __l, const __false_type& /*_Integral*/) {
1.328 + pointer __cur = this->_M_Start();
1.329 + while (__f != __l && __cur != this->_M_Finish()) {
1.330 + _Traits::assign(*__cur, *__f);
1.331 + ++__f;
1.332 + ++__cur;
1.333 + }
1.334 + if (__f == __l)
1.335 + _Base::erase(__cur, this->_M_Finish());
1.336 + else
1.337 + _M_appendT(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
1.338 + return *this;
1.339 + }
1.340 +
1.341 +public:
1.342 + // Check to see if _InputIterator is an integer type. If so, then
1.343 + // it can't be an iterator.
1.344 + template <class _InputIter>
1.345 + _Self& assign(_InputIter __first, _InputIter __last) {
1.346 + typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
1.347 + return _M_assign_dispatch(__first, __last, _Integral());
1.348 + }
1.349 +
1.350 +#if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
1.351 + /* This method is not part of the standard and is a specialization of the
1.352 + * template method assign. It is only granted for convenience to call assign
1.353 + * with mixed parameters iterator and const_iterator.
1.354 + */
1.355 + _Self& assign(const _CharT* __f, const _CharT* __l) {
1.356 + _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
1.357 + _Base::assign(__f, __l);
1.358 + return *this;
1.359 + }
1.360 +#endif
1.361 +
1.362 +public: // Insert
1.363 +
1.364 + _Self& insert(size_type __pos, const _Self& __s) {
1.365 + _Base::insert(__pos, __s);
1.366 + return *this;
1.367 + }
1.368 +
1.369 + _Self& insert(size_type __pos, const _Self& __s,
1.370 + size_type __beg, size_type __n) {
1.371 + _Base::insert(__pos, __s, __beg, __n);
1.372 + return *this;
1.373 + }
1.374 + _Self& insert(size_type __pos, const _CharT* __s, size_type __n) {
1.375 + _STLP_FIX_LITERAL_BUG(__s)
1.376 + _Base::insert(__pos, __s, __n);
1.377 + return *this;
1.378 + }
1.379 +
1.380 + _Self& insert(size_type __pos, const _CharT* __s) {
1.381 + _STLP_FIX_LITERAL_BUG(__s)
1.382 + _Base::insert(__pos, __s);
1.383 + return *this;
1.384 + }
1.385 +
1.386 + _Self& insert(size_type __pos, size_type __n, _CharT __c) {
1.387 + _Base::insert(__pos, __n, __c);
1.388 + return *this;
1.389 + }
1.390 +
1.391 + iterator insert(iterator __p, _CharT __c) {
1.392 + return _Base::insert(__p, __c);
1.393 + }
1.394 +
1.395 + void insert(iterator __p, size_t __n, _CharT __c) {
1.396 + _Base::insert(__p, __n, __c);
1.397 + }
1.398 +
1.399 + // Check to see if _InputIterator is an integer type. If so, then
1.400 + // it can't be an iterator.
1.401 + template <class _InputIter>
1.402 + void insert(iterator __p, _InputIter __first, _InputIter __last) {
1.403 + typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
1.404 + _M_insert_dispatch(__p, __first, __last, _Integral());
1.405 + }
1.406 +
1.407 +private: // Helper functions for insert.
1.408 +
1.409 + void _M_insert(iterator __p, const _CharT* __f, const _CharT* __l, bool __self_ref) {
1.410 + _STLP_FIX_LITERAL_BUG(__f)_STLP_FIX_LITERAL_BUG(__l)
1.411 + _Base::_M_insert(__p, __f, __l, __self_ref);
1.412 + }
1.413 +
1.414 + template <class _ForwardIter>
1.415 + void _M_insert_overflow(iterator __position, _ForwardIter __first, _ForwardIter __last,
1.416 + difference_type __n) {
1.417 + const size_type __old_size = this->size();
1.418 + const size_type __len = __old_size + (max)(__old_size, __STATIC_CAST(size_type,__n)) + 1;
1.419 + pointer __new_start = this->_M_end_of_storage.allocate(__len);
1.420 + pointer __new_finish = __new_start;
1.421 + _STLP_TRY {
1.422 + __new_finish = uninitialized_copy(this->_M_Start(), __position, __new_start);
1.423 + __new_finish = uninitialized_copy(__first, __last, __new_finish);
1.424 + __new_finish = uninitialized_copy(__position, this->_M_Finish(), __new_finish);
1.425 + this->_M_construct_null(__new_finish);
1.426 + }
1.427 + _STLP_UNWIND((_STLP_STD::_Destroy_Range(__new_start,__new_finish),
1.428 + this->_M_end_of_storage.deallocate(__new_start,__len)))
1.429 + this->_M_destroy_range();
1.430 + this->_M_deallocate_block();
1.431 + this->_M_reset(__new_start, __new_finish, __new_start + __len);
1.432 + }
1.433 +
1.434 + template <class _InputIter>
1.435 + void _M_insertT(iterator __p, _InputIter __first, _InputIter __last,
1.436 + const input_iterator_tag &) {
1.437 + for ( ; __first != __last; ++__first) {
1.438 + __p = insert(__p, *__first);
1.439 + ++__p;
1.440 + }
1.441 + }
1.442 +
1.443 + template <class _ForwardIter>
1.444 + void _M_insertT(iterator __position, _ForwardIter __first, _ForwardIter __last,
1.445 + const forward_iterator_tag &) {
1.446 + if (__first != __last) {
1.447 + difference_type __n = distance(__first, __last);
1.448 + if (this->_M_end_of_storage._M_data - this->_M_finish >= __n + 1) {
1.449 + const difference_type __elems_after = this->_M_finish - __position;
1.450 + if (__elems_after >= __n) {
1.451 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
1.452 + if (this->_M_using_static_buf())
1.453 + _Base::_M_copy((this->_M_Finish() - __n) + 1, this->_M_Finish() + 1, this->_M_Finish() + 1);
1.454 + else
1.455 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
1.456 + uninitialized_copy((this->_M_Finish() - __n) + 1, this->_M_Finish() + 1, this->_M_Finish() + 1);
1.457 + this->_M_finish += __n;
1.458 + _Traits::move(__position + __n, __position, (__elems_after - __n) + 1);
1.459 + _M_copyT(__first, __last, __position);
1.460 + }
1.461 + else {
1.462 + pointer __old_finish = this->_M_Finish();
1.463 + _ForwardIter __mid = __first;
1.464 + advance(__mid, __elems_after + 1);
1.465 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
1.466 + if (this->_M_using_static_buf())
1.467 + _M_copyT(__mid, __last, this->_M_Finish() + 1);
1.468 + else
1.469 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
1.470 + uninitialized_copy(__mid, __last, this->_M_Finish() + 1);
1.471 + this->_M_finish += __n - __elems_after;
1.472 + _STLP_TRY {
1.473 +#if defined (_STLP_USE_SHORT_STRING_OPTIM)
1.474 + if (this->_M_using_static_buf())
1.475 + _Base::_M_copy(__position, __old_finish + 1, this->_M_Finish());
1.476 + else
1.477 +#endif /* _STLP_USE_SHORT_STRING_OPTIM */
1.478 + uninitialized_copy(__position, __old_finish + 1, this->_M_Finish());
1.479 + this->_M_finish += __elems_after;
1.480 + }
1.481 + _STLP_UNWIND((this->_M_destroy_ptr_range(__old_finish + 1, this->_M_Finish()),
1.482 + this->_M_finish = __old_finish))
1.483 + _M_copyT(__first, __mid, __position);
1.484 + }
1.485 + }
1.486 + else {
1.487 + _M_insert_overflow(__position, __first, __last, __n);
1.488 + }
1.489 + }
1.490 + }
1.491 +
1.492 + template <class _Integer>
1.493 + void _M_insert_dispatch(iterator __p, _Integer __n, _Integer __x,
1.494 + const __true_type& /*Integral*/) {
1.495 + insert(__p, (size_type) __n, (_CharT) __x);
1.496 + }
1.497 +
1.498 + template <class _InputIter>
1.499 + void _M_insert_dispatch(iterator __p, _InputIter __first, _InputIter __last,
1.500 + const __false_type& /*Integral*/) {
1.501 + _STLP_FIX_LITERAL_BUG(__p)
1.502 + /*
1.503 + * Within the basic_string implementation we are only going to check for
1.504 + * self referencing if iterators are string iterators or _CharT pointers.
1.505 + * A user could encapsulate those iterator within their own iterator interface
1.506 + * and in this case lead to a bad behavior, this is a known limitation.
1.507 + */
1.508 + typedef typename _AreSameUnCVTypes<_InputIter, iterator>::_Ret _IsIterator;
1.509 + typedef typename _AreSameUnCVTypes<_InputIter, const_iterator>::_Ret _IsConstIterator;
1.510 + typedef typename _Lor2<_IsIterator, _IsConstIterator>::_Ret _CheckInside;
1.511 + _M_insert_aux(__p, __first, __last, _CheckInside());
1.512 + }
1.513 +
1.514 + template <class _RandomIter>
1.515 + void _M_insert_aux (iterator __p, _RandomIter __first, _RandomIter __last,
1.516 + const __true_type& /*_CheckInside*/) {
1.517 + _STLP_FIX_LITERAL_BUG(__p)
1.518 + _M_insert(__p, &(*__first), &(*__last), _Base::_M_inside(&(*__first)));
1.519 + }
1.520 +
1.521 + template<class _InputIter>
1.522 + void _M_insert_aux (iterator __p, _InputIter __first, _InputIter __last,
1.523 + const __false_type& /*_CheckInside*/) {
1.524 + _STLP_FIX_LITERAL_BUG(__p)
1.525 + _M_insertT(__p, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
1.526 + }
1.527 +
1.528 + template <class _InputIterator>
1.529 + void _M_copyT(_InputIterator __first, _InputIterator __last, pointer __result) {
1.530 + _STLP_FIX_LITERAL_BUG(__p)
1.531 + for ( ; __first != __last; ++__first, ++__result)
1.532 + _Traits::assign(*__result, *__first);
1.533 + }
1.534 +
1.535 +#if !defined (_STLP_NO_METHOD_SPECIALIZATION)
1.536 + void _M_copyT(const _CharT* __f, const _CharT* __l, _CharT* __res) {
1.537 + _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l) _STLP_FIX_LITERAL_BUG(__res)
1.538 + _Base::_M_copy(__f, __l, __res);
1.539 + }
1.540 +#endif
1.541 +
1.542 +public: // Erase.
1.543 +
1.544 + _Self& erase(size_type __pos = 0, size_type __n = npos) {
1.545 + _Base::erase(__pos, __n);
1.546 + return *this;
1.547 + }
1.548 +
1.549 + iterator erase(iterator __pos) {
1.550 + _STLP_FIX_LITERAL_BUG(__pos)
1.551 + return _Base::erase(__pos);
1.552 + }
1.553 +
1.554 + iterator erase(iterator __first, iterator __last) {
1.555 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.556 + return _Base::erase(__first, __last);
1.557 + }
1.558 +
1.559 +public: // Replace. (Conceptually equivalent
1.560 + // to erase followed by insert.)
1.561 + _Self& replace(size_type __pos, size_type __n, const _Self& __s) {
1.562 + _Base::replace(__pos, __n, __s);
1.563 + return *this;
1.564 + }
1.565 +
1.566 + _Self& replace(size_type __pos1, size_type __n1, const _Self& __s,
1.567 + size_type __pos2, size_type __n2) {
1.568 + _Base::replace(__pos1, __n1, __s, __pos2, __n2);
1.569 + return *this;
1.570 + }
1.571 +
1.572 + _Self& replace(size_type __pos, size_type __n1,
1.573 + const _CharT* __s, size_type __n2) {
1.574 + _STLP_FIX_LITERAL_BUG(__s)
1.575 + _Base::replace(__pos, __n1, __s, __n2);
1.576 + return *this;
1.577 + }
1.578 +
1.579 + _Self& replace(size_type __pos, size_type __n1, const _CharT* __s) {
1.580 + _STLP_FIX_LITERAL_BUG(__s)
1.581 + _Base::replace(__pos, __n1, __s);
1.582 + return *this;
1.583 + }
1.584 +
1.585 + _Self& replace(size_type __pos, size_type __n1,
1.586 + size_type __n2, _CharT __c) {
1.587 + _Base::replace(__pos, __n1, __n2, __c);
1.588 + return *this;
1.589 + }
1.590 +
1.591 + _Self& replace(iterator __first, iterator __last, const _Self& __s) {
1.592 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.593 + _Base::replace(__first, __last, __s);
1.594 + return *this;
1.595 + }
1.596 +
1.597 + _Self& replace(iterator __first, iterator __last,
1.598 + const _CharT* __s, size_type __n) {
1.599 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.600 + _STLP_FIX_LITERAL_BUG(__s)
1.601 + _Base::replace(__first, __last, __s, __n);
1.602 + return *this;
1.603 + }
1.604 +
1.605 + _Self& replace(iterator __first, iterator __last,
1.606 + const _CharT* __s) {
1.607 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.608 + _STLP_FIX_LITERAL_BUG(__s)
1.609 + _Base::replace(__first, __last, __s);
1.610 + return *this;
1.611 + }
1.612 +
1.613 + _Self& replace(iterator __first, iterator __last,
1.614 + size_type __n, _CharT __c) {
1.615 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.616 + _Base::replace(__first, __last, __n, __c);
1.617 + return *this;
1.618 + }
1.619 +
1.620 + // Check to see if _InputIter is an integer type. If so, then
1.621 + // it can't be an iterator.
1.622 + template <class _InputIter>
1.623 + _Self& replace(iterator __first, iterator __last,
1.624 + _InputIter __f, _InputIter __l) {
1.625 + _STLP_FIX_LITERAL_BUG(__first)_STLP_FIX_LITERAL_BUG(__last)
1.626 + typedef typename _IsIntegral<_InputIter>::_Ret _Integral;
1.627 + return _M_replace_dispatch(__first, __last, __f, __l, _Integral());
1.628 + }
1.629 +
1.630 +#if !defined (_STLP_NO_METHOD_SPECIALIZATION) && !defined (_STLP_NO_EXTENSIONS)
1.631 + _Self& replace(iterator __first, iterator __last,
1.632 + const _CharT* __f, const _CharT* __l) {
1.633 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.634 + _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
1.635 + _Base::replace(__first, __last, __f, __l);
1.636 + return *this;
1.637 + }
1.638 +#endif
1.639 +
1.640 +protected: // Helper functions for replace.
1.641 + _Self& _M_replace(iterator __first, iterator __last,
1.642 + const _CharT* __f, const _CharT* __l, bool __self_ref) {
1.643 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.644 + _STLP_FIX_LITERAL_BUG(__f) _STLP_FIX_LITERAL_BUG(__l)
1.645 + _Base::_M_replace(__first, __last, __f, __l, __self_ref);
1.646 + return *this;
1.647 + }
1.648 +
1.649 + template <class _Integer>
1.650 + _Self& _M_replace_dispatch(iterator __first, iterator __last,
1.651 + _Integer __n, _Integer __x, const __true_type& /*IsIntegral*/) {
1.652 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.653 + return replace(__first, __last, (size_type) __n, (_CharT) __x);
1.654 + }
1.655 +
1.656 + template <class _InputIter>
1.657 + _Self& _M_replace_dispatch(iterator __first, iterator __last,
1.658 + _InputIter __f, _InputIter __l, const __false_type& /*IsIntegral*/) {
1.659 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.660 + typedef typename _AreSameUnCVTypes<_InputIter, iterator>::_Ret _IsIterator;
1.661 + typedef typename _AreSameUnCVTypes<_InputIter, const_iterator>::_Ret _IsConstIterator;
1.662 + typedef typename _Lor2<_IsIterator, _IsConstIterator>::_Ret _CheckInside;
1.663 + return _M_replace_aux(__first, __last, __f, __l, _CheckInside());
1.664 + }
1.665 +
1.666 + template <class _RandomIter>
1.667 + _Self& _M_replace_aux(iterator __first, iterator __last,
1.668 + _RandomIter __f, _RandomIter __l, __true_type const& /*_CheckInside*/) {
1.669 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.670 + return _M_replace(__first, __last, &(*__f), &(*__l), _Base::_M_inside(&(*__f)));
1.671 + }
1.672 +
1.673 + template <class _InputIter>
1.674 + _Self& _M_replace_aux(iterator __first, iterator __last,
1.675 + _InputIter __f, _InputIter __l, __false_type const& /*_CheckInside*/) {
1.676 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.677 + return _M_replaceT(__first, __last, __f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIter));
1.678 + }
1.679 +
1.680 + template <class _InputIter>
1.681 + _Self& _M_replaceT(iterator __first, iterator __last,
1.682 + _InputIter __f, _InputIter __l, const input_iterator_tag&__ite_tag) {
1.683 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.684 + for ( ; __first != __last && __f != __l; ++__first, ++__f)
1.685 + _Traits::assign(*__first, *__f);
1.686 + if (__f == __l)
1.687 + _Base::erase(__first, __last);
1.688 + else
1.689 + _M_insertT(__last, __f, __l, __ite_tag);
1.690 + return *this;
1.691 + }
1.692 +
1.693 + template <class _ForwardIter>
1.694 + _Self& _M_replaceT(iterator __first, iterator __last,
1.695 + _ForwardIter __f, _ForwardIter __l, const forward_iterator_tag &__ite_tag) {
1.696 + _STLP_FIX_LITERAL_BUG(__first) _STLP_FIX_LITERAL_BUG(__last)
1.697 + difference_type __n = distance(__f, __l);
1.698 + const difference_type __len = __last - __first;
1.699 + if (__len >= __n) {
1.700 + _M_copyT(__f, __l, __first);
1.701 + _Base::erase(__first + __n, __last);
1.702 + }
1.703 + else {
1.704 + _ForwardIter __m = __f;
1.705 + advance(__m, __len);
1.706 + _M_copyT(__f, __m, __first);
1.707 + _M_insertT(__last, __m, __l, __ite_tag);
1.708 + }
1.709 + return *this;
1.710 + }
1.711 +
1.712 +public: // Other modifier member functions.
1.713 +
1.714 + void swap(_Self& __s)
1.715 + { _Base::swap(__s); }
1.716 +
1.717 +public: // Substring.
1.718 +
1.719 + _Self substr(size_type __pos = 0, size_type __n = npos) const
1.720 + { return _Self(*this, __pos, __n, get_allocator()); }
1.721 +
1.722 +#if defined (_STLP_USE_TEMPLATE_EXPRESSION) && !defined (_STLP_DEBUG)
1.723 +# define _STLP_STRING_SUM_BASE _STLP_NO_MEM_T_STRING_BASE
1.724 +# include <stl/_string_sum_methods.h>
1.725 +# undef _STLP_STRING_SUM_BASE
1.726 +#endif
1.727 +};
1.728 +
1.729 +#undef _STLP_NO_MEM_T_STRING_BASE
1.730 +
1.731 +#if defined (basic_string)
1.732 +_STLP_MOVE_TO_STD_NAMESPACE
1.733 +# undef basic_string
1.734 +#endif
1.735 +
1.736 +_STLP_END_NAMESPACE