Merge from mainline (168000:168310).
[official-gcc/graphite-test-results.git] / libstdc++-v3 / include / ext / rc_string_base.h
blobb4037d60558a7c8a85d1c83a932c7c107ce177f5
1 // Reference-counted versatile string base -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 /** @file ext/rc_string_base.h
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{ext/vstring.h}
31 #ifndef _RC_STRING_BASE_H
32 #define _RC_STRING_BASE_H 1
34 #include <ext/atomicity.h>
35 #include <bits/stl_iterator_base_funcs.h>
37 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
39 /**
40 * Documentation? What's that?
41 * Nathan Myers <ncm@cantrip.org>.
43 * A string looks like this:
45 * @code
46 * [_Rep]
47 * _M_length
48 * [__rc_string_base<char_type>] _M_capacity
49 * _M_dataplus _M_refcount
50 * _M_p ----------------> unnamed array of char_type
51 * @endcode
53 * Where the _M_p points to the first character in the string, and
54 * you cast it to a pointer-to-_Rep and subtract 1 to get a
55 * pointer to the header.
57 * This approach has the enormous advantage that a string object
58 * requires only one allocation. All the ugliness is confined
59 * within a single pair of inline functions, which each compile to
60 * a single @a add instruction: _Rep::_M_refdata(), and
61 * __rc_string_base::_M_rep(); and the allocation function which gets a
62 * block of raw bytes and with room enough and constructs a _Rep
63 * object at the front.
65 * The reason you want _M_data pointing to the character array and
66 * not the _Rep is so that the debugger can see the string
67 * contents. (Probably we should add a non-inline member to get
68 * the _Rep for the debugger to use, so users can check the actual
69 * string length.)
71 * Note that the _Rep object is a POD so that you can have a
72 * static <em>empty string</em> _Rep object already @a constructed before
73 * static constructors have run. The reference-count encoding is
74 * chosen so that a 0 indicates one reference, so you never try to
75 * destroy the empty-string _Rep object.
77 * All but the last paragraph is considered pretty conventional
78 * for a C++ string implementation.
80 template<typename _CharT, typename _Traits, typename _Alloc>
81 class __rc_string_base
82 : protected __vstring_utility<_CharT, _Traits, _Alloc>
84 public:
85 typedef _Traits traits_type;
86 typedef typename _Traits::char_type value_type;
87 typedef _Alloc allocator_type;
89 typedef __vstring_utility<_CharT, _Traits, _Alloc> _Util_Base;
90 typedef typename _Util_Base::_CharT_alloc_type _CharT_alloc_type;
91 typedef typename _CharT_alloc_type::size_type size_type;
93 private:
94 // _Rep: string representation
95 // Invariants:
96 // 1. String really contains _M_length + 1 characters: due to 21.3.4
97 // must be kept null-terminated.
98 // 2. _M_capacity >= _M_length
99 // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT).
100 // 3. _M_refcount has three states:
101 // -1: leaked, one reference, no ref-copies allowed, non-const.
102 // 0: one reference, non-const.
103 // n>0: n + 1 references, operations require a lock, const.
104 // 4. All fields == 0 is an empty string, given the extra storage
105 // beyond-the-end for a null terminator; thus, the shared
106 // empty string representation needs no constructor.
107 struct _Rep
109 union
111 struct
113 size_type _M_length;
114 size_type _M_capacity;
115 _Atomic_word _M_refcount;
116 } _M_info;
118 // Only for alignment purposes.
119 _CharT _M_align;
122 typedef typename _Alloc::template rebind<_Rep>::other _Rep_alloc_type;
124 _CharT*
125 _M_refdata() throw()
126 { return reinterpret_cast<_CharT*>(this + 1); }
128 _CharT*
129 _M_refcopy() throw()
131 __atomic_add_dispatch(&_M_info._M_refcount, 1);
132 return _M_refdata();
133 } // XXX MT
135 void
136 _M_set_length(size_type __n)
138 _M_info._M_refcount = 0; // One reference.
139 _M_info._M_length = __n;
140 // grrr. (per 21.3.4)
141 // You cannot leave those LWG people alone for a second.
142 traits_type::assign(_M_refdata()[__n], _CharT());
145 // Create & Destroy
146 static _Rep*
147 _S_create(size_type, size_type, const _Alloc&);
149 void
150 _M_destroy(const _Alloc&) throw();
152 _CharT*
153 _M_clone(const _Alloc&, size_type __res = 0);
156 struct _Rep_empty
157 : public _Rep
159 _CharT _M_terminal;
162 static _Rep_empty _S_empty_rep;
164 // The maximum number of individual char_type elements of an
165 // individual string is determined by _S_max_size. This is the
166 // value that will be returned by max_size(). (Whereas npos
167 // is the maximum number of bytes the allocator can allocate.)
168 // If one was to divvy up the theoretical largest size string,
169 // with a terminating character and m _CharT elements, it'd
170 // look like this:
171 // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
172 // + sizeof(_Rep) - 1
173 // (NB: last two terms for rounding reasons, see _M_create below)
174 // Solving for m:
175 // m = ((npos - 2 * sizeof(_Rep) + 1) / sizeof(_CharT)) - 1
176 // In addition, this implementation halves this amount.
177 enum { _S_max_size = (((static_cast<size_type>(-1) - 2 * sizeof(_Rep)
178 + 1) / sizeof(_CharT)) - 1) / 2 };
180 // Data Member (private):
181 mutable typename _Util_Base::template _Alloc_hider<_Alloc> _M_dataplus;
183 void
184 _M_data(_CharT* __p)
185 { _M_dataplus._M_p = __p; }
187 _Rep*
188 _M_rep() const
189 { return &((reinterpret_cast<_Rep*>(_M_data()))[-1]); }
191 _CharT*
192 _M_grab(const _Alloc& __alloc) const
194 return (!_M_is_leaked() && _M_get_allocator() == __alloc)
195 ? _M_rep()->_M_refcopy() : _M_rep()->_M_clone(__alloc);
198 void
199 _M_dispose()
201 // Be race-detector-friendly. For more info see bits/c++config.
202 _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_rep()->_M_info.
203 _M_refcount);
204 if (__exchange_and_add_dispatch(&_M_rep()->_M_info._M_refcount,
205 -1) <= 0)
207 _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_rep()->_M_info.
208 _M_refcount);
209 _M_rep()->_M_destroy(_M_get_allocator());
211 } // XXX MT
213 bool
214 _M_is_leaked() const
215 { return _M_rep()->_M_info._M_refcount < 0; }
217 void
218 _M_set_sharable()
219 { _M_rep()->_M_info._M_refcount = 0; }
221 void
222 _M_leak_hard();
224 // _S_construct_aux is used to implement the 21.3.1 para 15 which
225 // requires special behaviour if _InIterator is an integral type
226 template<typename _InIterator>
227 static _CharT*
228 _S_construct_aux(_InIterator __beg, _InIterator __end,
229 const _Alloc& __a, std::__false_type)
231 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
232 return _S_construct(__beg, __end, __a, _Tag());
235 // _GLIBCXX_RESOLVE_LIB_DEFECTS
236 // 438. Ambiguity in the "do the right thing" clause
237 template<typename _Integer>
238 static _CharT*
239 _S_construct_aux(_Integer __beg, _Integer __end,
240 const _Alloc& __a, std::__true_type)
241 { return _S_construct_aux_2(static_cast<size_type>(__beg),
242 __end, __a); }
244 static _CharT*
245 _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a)
246 { return _S_construct(__req, __c, __a); }
248 template<typename _InIterator>
249 static _CharT*
250 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a)
252 typedef typename std::__is_integer<_InIterator>::__type _Integral;
253 return _S_construct_aux(__beg, __end, __a, _Integral());
256 // For Input Iterators, used in istreambuf_iterators, etc.
257 template<typename _InIterator>
258 static _CharT*
259 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
260 std::input_iterator_tag);
262 // For forward_iterators up to random_access_iterators, used for
263 // string::iterator, _CharT*, etc.
264 template<typename _FwdIterator>
265 static _CharT*
266 _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a,
267 std::forward_iterator_tag);
269 static _CharT*
270 _S_construct(size_type __req, _CharT __c, const _Alloc& __a);
272 public:
273 size_type
274 _M_max_size() const
275 { return size_type(_S_max_size); }
277 _CharT*
278 _M_data() const
279 { return _M_dataplus._M_p; }
281 size_type
282 _M_length() const
283 { return _M_rep()->_M_info._M_length; }
285 size_type
286 _M_capacity() const
287 { return _M_rep()->_M_info._M_capacity; }
289 bool
290 _M_is_shared() const
291 { return _M_rep()->_M_info._M_refcount > 0; }
293 void
294 _M_set_leaked()
295 { _M_rep()->_M_info._M_refcount = -1; }
297 void
298 _M_leak() // for use in begin() & non-const op[]
300 if (!_M_is_leaked())
301 _M_leak_hard();
304 void
305 _M_set_length(size_type __n)
306 { _M_rep()->_M_set_length(__n); }
308 __rc_string_base()
309 : _M_dataplus(_S_empty_rep._M_refcopy()) { }
311 __rc_string_base(const _Alloc& __a);
313 __rc_string_base(const __rc_string_base& __rcs);
315 #ifdef __GXX_EXPERIMENTAL_CXX0X__
316 __rc_string_base(__rc_string_base&& __rcs)
317 : _M_dataplus(__rcs._M_dataplus)
318 { __rcs._M_data(_S_empty_rep._M_refcopy()); }
319 #endif
321 __rc_string_base(size_type __n, _CharT __c, const _Alloc& __a);
323 template<typename _InputIterator>
324 __rc_string_base(_InputIterator __beg, _InputIterator __end,
325 const _Alloc& __a);
327 ~__rc_string_base()
328 { _M_dispose(); }
330 allocator_type&
331 _M_get_allocator()
332 { return _M_dataplus; }
334 const allocator_type&
335 _M_get_allocator() const
336 { return _M_dataplus; }
338 void
339 _M_swap(__rc_string_base& __rcs);
341 void
342 _M_assign(const __rc_string_base& __rcs);
344 void
345 _M_reserve(size_type __res);
347 void
348 _M_mutate(size_type __pos, size_type __len1, const _CharT* __s,
349 size_type __len2);
351 void
352 _M_erase(size_type __pos, size_type __n);
354 void
355 _M_clear()
356 { _M_erase(size_type(0), _M_length()); }
358 bool
359 _M_compare(const __rc_string_base&) const
360 { return false; }
363 template<typename _CharT, typename _Traits, typename _Alloc>
364 typename __rc_string_base<_CharT, _Traits, _Alloc>::_Rep_empty
365 __rc_string_base<_CharT, _Traits, _Alloc>::_S_empty_rep;
367 template<typename _CharT, typename _Traits, typename _Alloc>
368 typename __rc_string_base<_CharT, _Traits, _Alloc>::_Rep*
369 __rc_string_base<_CharT, _Traits, _Alloc>::_Rep::
370 _S_create(size_type __capacity, size_type __old_capacity,
371 const _Alloc& __alloc)
373 // _GLIBCXX_RESOLVE_LIB_DEFECTS
374 // 83. String::npos vs. string::max_size()
375 if (__capacity > size_type(_S_max_size))
376 std::__throw_length_error(__N("__rc_string_base::_Rep::_S_create"));
378 // The standard places no restriction on allocating more memory
379 // than is strictly needed within this layer at the moment or as
380 // requested by an explicit application call to reserve().
382 // Many malloc implementations perform quite poorly when an
383 // application attempts to allocate memory in a stepwise fashion
384 // growing each allocation size by only 1 char. Additionally,
385 // it makes little sense to allocate less linear memory than the
386 // natural blocking size of the malloc implementation.
387 // Unfortunately, we would need a somewhat low-level calculation
388 // with tuned parameters to get this perfect for any particular
389 // malloc implementation. Fortunately, generalizations about
390 // common features seen among implementations seems to suffice.
392 // __pagesize need not match the actual VM page size for good
393 // results in practice, thus we pick a common value on the low
394 // side. __malloc_header_size is an estimate of the amount of
395 // overhead per memory allocation (in practice seen N * sizeof
396 // (void*) where N is 0, 2 or 4). According to folklore,
397 // picking this value on the high side is better than
398 // low-balling it (especially when this algorithm is used with
399 // malloc implementations that allocate memory blocks rounded up
400 // to a size which is a power of 2).
401 const size_type __pagesize = 4096;
402 const size_type __malloc_header_size = 4 * sizeof(void*);
404 // The below implements an exponential growth policy, necessary to
405 // meet amortized linear time requirements of the library: see
406 // http://gcc.gnu.org/ml/libstdc++/2001-07/msg00085.html.
407 if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
409 __capacity = 2 * __old_capacity;
410 // Never allocate a string bigger than _S_max_size.
411 if (__capacity > size_type(_S_max_size))
412 __capacity = size_type(_S_max_size);
415 // NB: Need an array of char_type[__capacity], plus a terminating
416 // null char_type() element, plus enough for the _Rep data structure,
417 // plus sizeof(_Rep) - 1 to upper round to a size multiple of
418 // sizeof(_Rep).
419 // Whew. Seemingly so needy, yet so elemental.
420 size_type __size = ((__capacity + 1) * sizeof(_CharT)
421 + 2 * sizeof(_Rep) - 1);
423 const size_type __adj_size = __size + __malloc_header_size;
424 if (__adj_size > __pagesize && __capacity > __old_capacity)
426 const size_type __extra = __pagesize - __adj_size % __pagesize;
427 __capacity += __extra / sizeof(_CharT);
428 if (__capacity > size_type(_S_max_size))
429 __capacity = size_type(_S_max_size);
430 __size = (__capacity + 1) * sizeof(_CharT) + 2 * sizeof(_Rep) - 1;
433 // NB: Might throw, but no worries about a leak, mate: _Rep()
434 // does not throw.
435 _Rep* __place = _Rep_alloc_type(__alloc).allocate(__size / sizeof(_Rep));
436 _Rep* __p = new (__place) _Rep;
437 __p->_M_info._M_capacity = __capacity;
438 return __p;
441 template<typename _CharT, typename _Traits, typename _Alloc>
442 void
443 __rc_string_base<_CharT, _Traits, _Alloc>::_Rep::
444 _M_destroy(const _Alloc& __a) throw ()
446 const size_type __size = ((_M_info._M_capacity + 1) * sizeof(_CharT)
447 + 2 * sizeof(_Rep) - 1);
448 _Rep_alloc_type(__a).deallocate(this, __size / sizeof(_Rep));
451 template<typename _CharT, typename _Traits, typename _Alloc>
452 _CharT*
453 __rc_string_base<_CharT, _Traits, _Alloc>::_Rep::
454 _M_clone(const _Alloc& __alloc, size_type __res)
456 // Requested capacity of the clone.
457 const size_type __requested_cap = _M_info._M_length + __res;
458 _Rep* __r = _Rep::_S_create(__requested_cap, _M_info._M_capacity,
459 __alloc);
461 if (_M_info._M_length)
462 _S_copy(__r->_M_refdata(), _M_refdata(), _M_info._M_length);
464 __r->_M_set_length(_M_info._M_length);
465 return __r->_M_refdata();
468 template<typename _CharT, typename _Traits, typename _Alloc>
469 __rc_string_base<_CharT, _Traits, _Alloc>::
470 __rc_string_base(const _Alloc& __a)
471 : _M_dataplus(__a, _S_construct(size_type(), _CharT(), __a)) { }
473 template<typename _CharT, typename _Traits, typename _Alloc>
474 __rc_string_base<_CharT, _Traits, _Alloc>::
475 __rc_string_base(const __rc_string_base& __rcs)
476 : _M_dataplus(__rcs._M_get_allocator(),
477 __rcs._M_grab(__rcs._M_get_allocator())) { }
479 template<typename _CharT, typename _Traits, typename _Alloc>
480 __rc_string_base<_CharT, _Traits, _Alloc>::
481 __rc_string_base(size_type __n, _CharT __c, const _Alloc& __a)
482 : _M_dataplus(__a, _S_construct(__n, __c, __a)) { }
484 template<typename _CharT, typename _Traits, typename _Alloc>
485 template<typename _InputIterator>
486 __rc_string_base<_CharT, _Traits, _Alloc>::
487 __rc_string_base(_InputIterator __beg, _InputIterator __end,
488 const _Alloc& __a)
489 : _M_dataplus(__a, _S_construct(__beg, __end, __a)) { }
491 template<typename _CharT, typename _Traits, typename _Alloc>
492 void
493 __rc_string_base<_CharT, _Traits, _Alloc>::
494 _M_leak_hard()
496 if (_M_is_shared())
497 _M_erase(0, 0);
498 _M_set_leaked();
501 // NB: This is the special case for Input Iterators, used in
502 // istreambuf_iterators, etc.
503 // Input Iterators have a cost structure very different from
504 // pointers, calling for a different coding style.
505 template<typename _CharT, typename _Traits, typename _Alloc>
506 template<typename _InIterator>
507 _CharT*
508 __rc_string_base<_CharT, _Traits, _Alloc>::
509 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
510 std::input_iterator_tag)
512 if (__beg == __end && __a == _Alloc())
513 return _S_empty_rep._M_refcopy();
515 // Avoid reallocation for common case.
516 _CharT __buf[128];
517 size_type __len = 0;
518 while (__beg != __end && __len < sizeof(__buf) / sizeof(_CharT))
520 __buf[__len++] = *__beg;
521 ++__beg;
523 _Rep* __r = _Rep::_S_create(__len, size_type(0), __a);
524 _S_copy(__r->_M_refdata(), __buf, __len);
525 __try
527 while (__beg != __end)
529 if (__len == __r->_M_info._M_capacity)
531 // Allocate more space.
532 _Rep* __another = _Rep::_S_create(__len + 1, __len, __a);
533 _S_copy(__another->_M_refdata(), __r->_M_refdata(), __len);
534 __r->_M_destroy(__a);
535 __r = __another;
537 __r->_M_refdata()[__len++] = *__beg;
538 ++__beg;
541 __catch(...)
543 __r->_M_destroy(__a);
544 __throw_exception_again;
546 __r->_M_set_length(__len);
547 return __r->_M_refdata();
550 template<typename _CharT, typename _Traits, typename _Alloc>
551 template<typename _InIterator>
552 _CharT*
553 __rc_string_base<_CharT, _Traits, _Alloc>::
554 _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a,
555 std::forward_iterator_tag)
557 if (__beg == __end && __a == _Alloc())
558 return _S_empty_rep._M_refcopy();
560 // NB: Not required, but considered best practice.
561 if (__is_null_pointer(__beg) && __beg != __end)
562 std::__throw_logic_error(__N("__rc_string_base::"
563 "_S_construct null not valid"));
565 const size_type __dnew = static_cast<size_type>(std::distance(__beg,
566 __end));
567 // Check for out_of_range and length_error exceptions.
568 _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a);
569 __try
570 { _S_copy_chars(__r->_M_refdata(), __beg, __end); }
571 __catch(...)
573 __r->_M_destroy(__a);
574 __throw_exception_again;
576 __r->_M_set_length(__dnew);
577 return __r->_M_refdata();
580 template<typename _CharT, typename _Traits, typename _Alloc>
581 _CharT*
582 __rc_string_base<_CharT, _Traits, _Alloc>::
583 _S_construct(size_type __n, _CharT __c, const _Alloc& __a)
585 if (__n == 0 && __a == _Alloc())
586 return _S_empty_rep._M_refcopy();
588 // Check for out_of_range and length_error exceptions.
589 _Rep* __r = _Rep::_S_create(__n, size_type(0), __a);
590 if (__n)
591 _S_assign(__r->_M_refdata(), __n, __c);
593 __r->_M_set_length(__n);
594 return __r->_M_refdata();
597 template<typename _CharT, typename _Traits, typename _Alloc>
598 void
599 __rc_string_base<_CharT, _Traits, _Alloc>::
600 _M_swap(__rc_string_base& __rcs)
602 if (_M_is_leaked())
603 _M_set_sharable();
604 if (__rcs._M_is_leaked())
605 __rcs._M_set_sharable();
607 _CharT* __tmp = _M_data();
608 _M_data(__rcs._M_data());
609 __rcs._M_data(__tmp);
611 // _GLIBCXX_RESOLVE_LIB_DEFECTS
612 // 431. Swapping containers with unequal allocators.
613 std::__alloc_swap<allocator_type>::_S_do_it(_M_get_allocator(),
614 __rcs._M_get_allocator());
617 template<typename _CharT, typename _Traits, typename _Alloc>
618 void
619 __rc_string_base<_CharT, _Traits, _Alloc>::
620 _M_assign(const __rc_string_base& __rcs)
622 if (_M_rep() != __rcs._M_rep())
624 _CharT* __tmp = __rcs._M_grab(_M_get_allocator());
625 _M_dispose();
626 _M_data(__tmp);
630 template<typename _CharT, typename _Traits, typename _Alloc>
631 void
632 __rc_string_base<_CharT, _Traits, _Alloc>::
633 _M_reserve(size_type __res)
635 // Make sure we don't shrink below the current size.
636 if (__res < _M_length())
637 __res = _M_length();
639 if (__res != _M_capacity() || _M_is_shared())
641 _CharT* __tmp = _M_rep()->_M_clone(_M_get_allocator(),
642 __res - _M_length());
643 _M_dispose();
644 _M_data(__tmp);
648 template<typename _CharT, typename _Traits, typename _Alloc>
649 void
650 __rc_string_base<_CharT, _Traits, _Alloc>::
651 _M_mutate(size_type __pos, size_type __len1, const _CharT* __s,
652 size_type __len2)
654 const size_type __how_much = _M_length() - __pos - __len1;
656 _Rep* __r = _Rep::_S_create(_M_length() + __len2 - __len1,
657 _M_capacity(), _M_get_allocator());
659 if (__pos)
660 _S_copy(__r->_M_refdata(), _M_data(), __pos);
661 if (__s && __len2)
662 _S_copy(__r->_M_refdata() + __pos, __s, __len2);
663 if (__how_much)
664 _S_copy(__r->_M_refdata() + __pos + __len2,
665 _M_data() + __pos + __len1, __how_much);
667 _M_dispose();
668 _M_data(__r->_M_refdata());
671 template<typename _CharT, typename _Traits, typename _Alloc>
672 void
673 __rc_string_base<_CharT, _Traits, _Alloc>::
674 _M_erase(size_type __pos, size_type __n)
676 const size_type __new_size = _M_length() - __n;
677 const size_type __how_much = _M_length() - __pos - __n;
679 if (_M_is_shared())
681 // Must reallocate.
682 _Rep* __r = _Rep::_S_create(__new_size, _M_capacity(),
683 _M_get_allocator());
685 if (__pos)
686 _S_copy(__r->_M_refdata(), _M_data(), __pos);
687 if (__how_much)
688 _S_copy(__r->_M_refdata() + __pos,
689 _M_data() + __pos + __n, __how_much);
691 _M_dispose();
692 _M_data(__r->_M_refdata());
694 else if (__how_much && __n)
696 // Work in-place.
697 _S_move(_M_data() + __pos,
698 _M_data() + __pos + __n, __how_much);
701 _M_rep()->_M_set_length(__new_size);
704 template<>
705 inline bool
706 __rc_string_base<char, std::char_traits<char>,
707 std::allocator<char> >::
708 _M_compare(const __rc_string_base& __rcs) const
710 if (_M_rep() == __rcs._M_rep())
711 return true;
712 return false;
715 #ifdef _GLIBCXX_USE_WCHAR_T
716 template<>
717 inline bool
718 __rc_string_base<wchar_t, std::char_traits<wchar_t>,
719 std::allocator<wchar_t> >::
720 _M_compare(const __rc_string_base& __rcs) const
722 if (_M_rep() == __rcs._M_rep())
723 return true;
724 return false;
726 #endif
728 _GLIBCXX_END_NAMESPACE
730 #endif /* _RC_STRING_BASE_H */