46#pragma GCC system_header
59#include <tr1/functional>
62# define __GC_CONST const
69namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
71_GLIBCXX_BEGIN_NAMESPACE_VERSION
75 enum { _S_max_rope_depth = 45 };
76 enum _Tag {_S_leaf, _S_concat, _S_substringfn, _S_function};
80 template<
typename _ForwardIterator,
typename _Allocator>
82 _Destroy_const(_ForwardIterator __first,
83 _ForwardIterator __last, _Allocator __alloc)
85 for (; __first != __last; ++__first)
86 __alloc.destroy(&*__first);
89 template<
typename _ForwardIterator,
typename _Tp>
91 _Destroy_const(_ForwardIterator __first,
100 template <
class _CharT>
107 template <
class _CharT>
109 _S_is_basic_char_type(_CharT*)
112 template <
class _CharT>
114 _S_is_one_byte_char_type(_CharT*)
118 _S_is_basic_char_type(
char*)
122 _S_is_one_byte_char_type(
char*)
126 _S_is_basic_char_type(
wchar_t*)
131 template <
class _CharT>
133 _S_cond_store_eos(_CharT&) { }
136 _S_cond_store_eos(
char& __c)
140 _S_cond_store_eos(
wchar_t& __c)
147 template <
class _CharT>
151 virtual ~char_producer() { }
154 operator()(std::size_t __start_pos, std::size_t __len,
155 _CharT* __buffer) = 0;
177#pragma GCC diagnostic push
178#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
180 template<
class _Sequence, std::
size_t _Buf_sz = 100>
181 class sequence_buffer
182 :
public std::iterator<std::output_iterator_tag, void, void, void, void>
185 typedef typename _Sequence::value_type value_type;
187 _Sequence* _M_prefix;
188 value_type _M_buffer[_Buf_sz];
189 std::size_t _M_buf_count;
195 _M_prefix->append(_M_buffer, _M_buffer + _M_buf_count);
203 : _M_prefix(0), _M_buf_count(0) { }
205 sequence_buffer(
const sequence_buffer& __x)
207 _M_prefix = __x._M_prefix;
208 _M_buf_count = __x._M_buf_count;
209 std::copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer);
213 sequence_buffer(sequence_buffer& __x)
216 _M_prefix = __x._M_prefix;
220 sequence_buffer(_Sequence& __s)
221 : _M_prefix(&__s), _M_buf_count(0) { }
225 operator=(sequence_buffer& __x)
228 _M_prefix = __x._M_prefix;
234 operator=(
const sequence_buffer& __x)
236 _M_prefix = __x._M_prefix;
237 _M_buf_count = __x._M_buf_count;
238 std::copy(__x._M_buffer, __x._M_buffer + __x._M_buf_count, _M_buffer);
242#if __cplusplus >= 201103L
243 sequence_buffer(sequence_buffer&& __x) : sequence_buffer(__x) { }
244 sequence_buffer& operator=(sequence_buffer&& __x) {
return *
this = __x; }
248 push_back(value_type __x)
250 if (_M_buf_count < _Buf_sz)
252 _M_buffer[_M_buf_count] = __x;
264 append(value_type* __s, std::size_t __len)
266 if (__len + _M_buf_count <= _Buf_sz)
268 std::size_t __i = _M_buf_count;
269 for (std::size_t __j = 0; __j < __len; __i++, __j++)
270 _M_buffer[__i] = __s[__j];
271 _M_buf_count += __len;
273 else if (0 == _M_buf_count)
274 _M_prefix->append(__s, __s + __len);
283 write(value_type* __s, std::size_t __len)
297 operator=(
const value_type& __rhs)
315#pragma GCC diagnostic pop
318 template<
class _CharT>
319 class _Rope_char_consumer
327 virtual ~_Rope_char_consumer() { }
330 operator()(
const _CharT* __buffer, std::size_t __len) = 0;
336 template<
class _CharT,
class _Alloc = std::allocator<_CharT> >
339 template<
class _CharT,
class _Alloc>
340 struct _Rope_RopeConcatenation;
342 template<
class _CharT,
class _Alloc>
343 struct _Rope_RopeLeaf;
345 template<
class _CharT,
class _Alloc>
346 struct _Rope_RopeFunction;
348 template<
class _CharT,
class _Alloc>
349 struct _Rope_RopeSubstring;
351 template<
class _CharT,
class _Alloc>
352 class _Rope_iterator;
354 template<
class _CharT,
class _Alloc>
355 class _Rope_const_iterator;
357 template<
class _CharT,
class _Alloc>
358 class _Rope_char_ref_proxy;
360 template<
class _CharT,
class _Alloc>
361 class _Rope_char_ptr_proxy;
363 template<
class _CharT,
class _Alloc>
365 operator==(
const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x,
366 const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y);
368 template<
class _CharT,
class _Alloc>
369 _Rope_const_iterator<_CharT, _Alloc>
370 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
373 template<
class _CharT,
class _Alloc>
374 _Rope_const_iterator<_CharT, _Alloc>
375 operator+(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
378 template<
class _CharT,
class _Alloc>
379 _Rope_const_iterator<_CharT, _Alloc>
381 const _Rope_const_iterator<_CharT, _Alloc>& __x);
383 template<
class _CharT,
class _Alloc>
385 operator==(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
386 const _Rope_const_iterator<_CharT, _Alloc>& __y);
388 template<
class _CharT,
class _Alloc>
390 operator<(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
391 const _Rope_const_iterator<_CharT, _Alloc>& __y);
393 template<
class _CharT,
class _Alloc>
395 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
396 const _Rope_const_iterator<_CharT, _Alloc>& __y);
398 template<
class _CharT,
class _Alloc>
399 _Rope_iterator<_CharT, _Alloc>
400 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x, std::ptrdiff_t __n);
402 template<
class _CharT,
class _Alloc>
403 _Rope_iterator<_CharT, _Alloc>
404 operator+(
const _Rope_iterator<_CharT, _Alloc>& __x, std::ptrdiff_t __n);
406 template<
class _CharT,
class _Alloc>
407 _Rope_iterator<_CharT, _Alloc>
408 operator+(std::ptrdiff_t __n,
const _Rope_iterator<_CharT, _Alloc>& __x);
410 template<
class _CharT,
class _Alloc>
412 operator==(
const _Rope_iterator<_CharT, _Alloc>& __x,
413 const _Rope_iterator<_CharT, _Alloc>& __y);
415 template<
class _CharT,
class _Alloc>
417 operator<(
const _Rope_iterator<_CharT, _Alloc>& __x,
418 const _Rope_iterator<_CharT, _Alloc>& __y);
420 template<
class _CharT,
class _Alloc>
422 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x,
423 const _Rope_iterator<_CharT, _Alloc>& __y);
425 template<
class _CharT,
class _Alloc>
427 operator+(
const rope<_CharT, _Alloc>& __left,
428 const rope<_CharT, _Alloc>& __right);
430 template<
class _CharT,
class _Alloc>
432 operator+(
const rope<_CharT, _Alloc>& __left,
const _CharT* __right);
434 template<
class _CharT,
class _Alloc>
436 operator+(
const rope<_CharT, _Alloc>& __left, _CharT __right);
442#pragma GCC diagnostic push
443#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
446 template<
class _CharT,
class _Alloc>
447 struct _Rope_Concat_fn
449 rope<_CharT, _Alloc> >
452 operator()(
const rope<_CharT, _Alloc>& __x,
453 const rope<_CharT, _Alloc>& __y)
454 {
return __x + __y; }
456#pragma GCC diagnostic pop
458 template <
class _CharT,
class _Alloc>
459 inline rope<_CharT, _Alloc>
460 identity_element(_Rope_Concat_fn<_CharT, _Alloc>)
461 {
return rope<_CharT, _Alloc>(); }
467 struct _Refcount_Base
470 typedef std::size_t _RC_t;
476#ifdef __GTHREAD_MUTEX_INIT
477 __gthread_mutex_t _M_ref_count_lock = __GTHREAD_MUTEX_INIT;
479 __gthread_mutex_t _M_ref_count_lock;
482 _Refcount_Base(_RC_t __n) : _M_ref_count(__n)
484#ifndef __GTHREAD_MUTEX_INIT
485#ifdef __GTHREAD_MUTEX_INIT_FUNCTION
486 __GTHREAD_MUTEX_INIT_FUNCTION (&_M_ref_count_lock);
488#error __GTHREAD_MUTEX_INIT or __GTHREAD_MUTEX_INIT_FUNCTION should be defined by gthr.h abstraction layer, report problem to libstdc++@gcc.gnu.org.
493#ifndef __GTHREAD_MUTEX_INIT
495 { __gthread_mutex_destroy(&_M_ref_count_lock); }
501 __gthread_mutex_lock(&_M_ref_count_lock);
503 __gthread_mutex_unlock(&_M_ref_count_lock);
509 __gthread_mutex_lock(&_M_ref_count_lock);
510 _RC_t __tmp = --_M_ref_count;
511 __gthread_mutex_unlock(&_M_ref_count_lock);
541#define __ROPE_DEFINE_ALLOCS(__a) \
542 __ROPE_DEFINE_ALLOC(_CharT,_Data) \
543 typedef _Rope_RopeConcatenation<_CharT,__a> __C; \
544 __ROPE_DEFINE_ALLOC(__C,_C) \
545 typedef _Rope_RopeLeaf<_CharT,__a> __L; \
546 __ROPE_DEFINE_ALLOC(__L,_L) \
547 typedef _Rope_RopeFunction<_CharT,__a> __F; \
548 __ROPE_DEFINE_ALLOC(__F,_F) \
549 typedef _Rope_RopeSubstring<_CharT,__a> __S; \
550 __ROPE_DEFINE_ALLOC(__S,_S)
559#define __STATIC_IF_SGI_ALLOC
561 template <
class _CharT,
class _Alloc>
562 struct _Rope_rep_base
565 typedef std::size_t size_type;
566 typedef _Alloc allocator_type;
569 get_allocator()
const
570 {
return *
static_cast<const _Alloc*
>(
this); }
574 {
return *
static_cast<_Alloc*
>(
this); }
576 const allocator_type&
577 _M_get_allocator()
const
578 {
return *
static_cast<const _Alloc*
>(
this); }
580 _Rope_rep_base(size_type __size,
const allocator_type&)
581 : _M_size(__size) { }
585# define __ROPE_DEFINE_ALLOC(_Tp, __name) \
587 __alloc_traits<_Alloc>::template rebind<_Tp>::other __name##Alloc; \
588 static _Tp* __name##_allocate(size_type __n) \
589 { return __name##Alloc().allocate(__n); } \
590 static void __name##_deallocate(_Tp *__p, size_type __n) \
591 { __name##Alloc().deallocate(__p, __n); }
592 __ROPE_DEFINE_ALLOCS(_Alloc)
593# undef __ROPE_DEFINE_ALLOC
596 template<
class _CharT,
class _Alloc>
598 :
public _Rope_rep_base<_CharT, _Alloc>
604 __detail::_Tag _M_tag:8;
605 bool _M_is_balanced:8;
606 unsigned char _M_depth;
607 __GC_CONST _CharT* _M_c_string;
608#ifdef __GTHREAD_MUTEX_INIT
609 __gthread_mutex_t _M_c_string_lock = __GTHREAD_MUTEX_INIT;
611 __gthread_mutex_t _M_c_string_lock;
619 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
621 typedef std::size_t size_type;
623 using _Rope_rep_base<_CharT, _Alloc>::get_allocator;
624 using _Rope_rep_base<_CharT, _Alloc>::_M_get_allocator;
626 _Rope_RopeRep(__detail::_Tag __t,
int __d,
bool __b, size_type __size,
627 const allocator_type& __a)
628 : _Rope_rep_base<_CharT, _Alloc>(__size, __a),
632 _M_tag(__t), _M_is_balanced(__b), _M_depth(__d), _M_c_string(0)
633#ifdef __GTHREAD_MUTEX_INIT
636 { __GTHREAD_MUTEX_INIT_FUNCTION (&_M_c_string_lock); }
638 { __gthread_mutex_destroy (&_M_c_string_lock); }
645 _S_free_string(__GC_CONST _CharT*, size_type __len,
646 allocator_type& __a);
647#define __STL_FREE_STRING(__s, __l, __a) _S_free_string(__s, __l, __a);
655 void _M_free_c_string();
670 _S_unref(_Rope_RopeRep* __t)
673 __t->_M_unref_nonnil();
677 _S_ref(_Rope_RopeRep* __t)
684 _S_free_if_unref(_Rope_RopeRep* __t)
686 if (0 != __t && 0 == __t->_M_ref_count)
690 void _M_unref_nonnil() { }
691 void _M_ref_nonnil() { }
692 static void _S_unref(_Rope_RopeRep*) { }
693 static void _S_ref(_Rope_RopeRep*) { }
694 static void _S_free_if_unref(_Rope_RopeRep*) { }
698 operator=(
const _Rope_RopeRep&);
700 _Rope_RopeRep(
const _Rope_RopeRep&);
703 template<
class _CharT,
class _Alloc>
704 struct _Rope_RopeLeaf
705 :
public _Rope_RopeRep<_CharT, _Alloc>
707 typedef std::size_t size_type;
713 enum { _S_alloc_granularity = 8 };
716 _S_rounded_up_size(size_type __n)
718 size_type __size_with_eos;
720 if (_S_is_basic_char_type((_CharT*)0))
721 __size_with_eos = __n + 1;
723 __size_with_eos = __n;
725 return __size_with_eos;
728 return ((__size_with_eos + size_type(_S_alloc_granularity) - 1)
729 &~ (size_type(_S_alloc_granularity) - 1));
732 __GC_CONST _CharT* _M_data;
737 typedef typename _Rope_rep_base<_CharT,_Alloc>::allocator_type
740 _Rope_RopeLeaf(__GC_CONST _CharT* __d, size_type __size,
741 const allocator_type& __a)
742 : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_leaf, 0, true,
743 __size, __a), _M_data(__d)
745 if (_S_is_basic_char_type((_CharT *)0))
748 this->_M_c_string = __d;
755 ~_Rope_RopeLeaf() throw()
757 if (_M_data != this->_M_c_string)
758 this->_M_free_c_string();
760 this->__STL_FREE_STRING(_M_data, this->_M_size, this->_M_get_allocator());
765 operator=(
const _Rope_RopeLeaf&);
767 _Rope_RopeLeaf(
const _Rope_RopeLeaf&);
770 template<
class _CharT,
class _Alloc>
771 struct _Rope_RopeConcatenation
772 :
public _Rope_RopeRep<_CharT, _Alloc>
775 _Rope_RopeRep<_CharT, _Alloc>* _M_left;
776 _Rope_RopeRep<_CharT, _Alloc>* _M_right;
778 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
781 _Rope_RopeConcatenation(_Rope_RopeRep<_CharT, _Alloc>* __l,
782 _Rope_RopeRep<_CharT, _Alloc>* __r,
783 const allocator_type& __a)
784 : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_concat,
785 std::max(__l->_M_depth,
788 __l->_M_size + __r->_M_size, __a),
789 _M_left(__l), _M_right(__r)
792 ~_Rope_RopeConcatenation() throw()
794 this->_M_free_c_string();
795 _M_left->_M_unref_nonnil();
796 _M_right->_M_unref_nonnil();
800 _Rope_RopeConcatenation&
801 operator=(
const _Rope_RopeConcatenation&);
803 _Rope_RopeConcatenation(
const _Rope_RopeConcatenation&);
806 template<
class _CharT,
class _Alloc>
807 struct _Rope_RopeFunction
808 :
public _Rope_RopeRep<_CharT, _Alloc>
811 char_producer<_CharT>* _M_fn;
813 bool _M_delete_when_done;
824 _S_fn_finalization_proc(
void * __tree,
void *)
825 {
delete ((_Rope_RopeFunction *)__tree) -> _M_fn; }
827 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
830 _Rope_RopeFunction(char_producer<_CharT>* __f, std::size_t __size,
831 bool __d,
const allocator_type& __a)
832 : _Rope_RopeRep<_CharT, _Alloc>(__detail::_S_function, 0, true, __size, __a)
835 , _M_delete_when_done(__d)
841 GC_REGISTER_FINALIZER(
this, _Rope_RopeFunction::
842 _S_fn_finalization_proc, 0, 0, 0);
847 ~_Rope_RopeFunction() throw()
849 this->_M_free_c_string();
850 if (_M_delete_when_done)
856 operator=(
const _Rope_RopeFunction&);
858 _Rope_RopeFunction(
const _Rope_RopeFunction&);
867 template<
class _CharT,
class _Alloc>
868 struct _Rope_RopeSubstring
869 :
public _Rope_RopeFunction<_CharT, _Alloc>,
870 public char_producer<_CharT>
872 typedef std::size_t size_type;
875 _Rope_RopeRep<_CharT,_Alloc>* _M_base;
879 operator()(size_type __start_pos, size_type __req_len,
882 switch(_M_base->_M_tag)
884 case __detail::_S_function:
885 case __detail::_S_substringfn:
887 char_producer<_CharT>* __fn =
888 ((_Rope_RopeFunction<_CharT,_Alloc>*)_M_base)->_M_fn;
889 (*__fn)(__start_pos + _M_start, __req_len, __buffer);
892 case __detail::_S_leaf:
894 __GC_CONST _CharT* __s =
895 ((_Rope_RopeLeaf<_CharT,_Alloc>*)_M_base)->_M_data;
905 typedef typename _Rope_rep_base<_CharT, _Alloc>::allocator_type
908 _Rope_RopeSubstring(_Rope_RopeRep<_CharT, _Alloc>* __b, size_type __s,
909 size_type __l,
const allocator_type& __a)
910 : _Rope_RopeFunction<_CharT, _Alloc>(this, __l, false, __a),
911 char_producer<_CharT>(), _M_base(__b), _M_start(__s)
914 _M_base->_M_ref_nonnil();
916 this->_M_tag = __detail::_S_substringfn;
918 virtual ~_Rope_RopeSubstring() throw()
921 _M_base->_M_unref_nonnil();
937 template<
class _CharT,
class _Alloc>
938 struct _Rope_self_destruct_ptr
940 _Rope_RopeRep<_CharT, _Alloc>* _M_ptr;
942 ~_Rope_self_destruct_ptr()
943 { _Rope_RopeRep<_CharT, _Alloc>::_S_unref(_M_ptr); }
945 _Rope_self_destruct_ptr() : _M_ptr(0) { }
947 _Rope_self_destruct_ptr() { }
949 _Rope_self_destruct_ptr(_Rope_RopeRep<_CharT, _Alloc>* __p)
952 _Rope_RopeRep<_CharT, _Alloc>&
956 _Rope_RopeRep<_CharT, _Alloc>*
960 operator _Rope_RopeRep<_CharT, _Alloc>*()
963 _Rope_self_destruct_ptr&
964 operator=(_Rope_RopeRep<_CharT, _Alloc>* __x)
965 { _M_ptr = __x;
return *
this; }
974 template<
class _CharT,
class _Alloc>
975 class _Rope_char_ref_proxy
977 friend class rope<_CharT, _Alloc>;
978 friend class _Rope_iterator<_CharT, _Alloc>;
979 friend class _Rope_char_ptr_proxy<_CharT, _Alloc>;
981 typedef _Rope_RopeRep<_CharT, _Alloc>* _Self_destruct_ptr;
983 typedef _Rope_self_destruct_ptr<_CharT, _Alloc> _Self_destruct_ptr;
985 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
986 typedef rope<_CharT, _Alloc> _My_rope;
989 bool _M_current_valid;
992 _Rope_char_ref_proxy(_My_rope* __r, std::size_t __p)
993 : _M_pos(__p), _M_current(), _M_current_valid(false), _M_root(__r) { }
995 _Rope_char_ref_proxy(
const _Rope_char_ref_proxy& __x)
996 : _M_pos(__x._M_pos), _M_current(__x._M_current),
997 _M_current_valid(false), _M_root(__x._M_root) { }
1003 _Rope_char_ref_proxy(_My_rope* __r, std::size_t __p, _CharT __c)
1004 : _M_pos(__p), _M_current(__c), _M_current_valid(true), _M_root(__r) { }
1006 inline operator _CharT ()
const;
1008 _Rope_char_ref_proxy&
1009 operator=(_CharT __c);
1011 _Rope_char_ptr_proxy<_CharT, _Alloc>
operator&()
const;
1013 _Rope_char_ref_proxy&
1014 operator=(
const _Rope_char_ref_proxy& __c)
1015 {
return operator=((_CharT)__c); }
1018 template<
class _CharT,
class __Alloc>
1020 swap(_Rope_char_ref_proxy <_CharT, __Alloc > __a,
1021 _Rope_char_ref_proxy <_CharT, __Alloc > __b)
1028 template<
class _CharT,
class _Alloc>
1029 class _Rope_char_ptr_proxy
1032 friend class _Rope_char_ref_proxy<_CharT, _Alloc>;
1034 rope<_CharT,_Alloc>* _M_root;
1036 _Rope_char_ptr_proxy(
const _Rope_char_ref_proxy<_CharT,_Alloc>& __x)
1037 : _M_pos(__x._M_pos), _M_root(__x._M_root) { }
1039 _Rope_char_ptr_proxy(
const _Rope_char_ptr_proxy& __x)
1040 : _M_pos(__x._M_pos), _M_root(__x._M_root) { }
1042 _Rope_char_ptr_proxy() { }
1044 _Rope_char_ptr_proxy(_CharT* __x)
1045 : _M_root(0), _M_pos(0) { }
1047 _Rope_char_ptr_proxy&
1048 operator=(
const _Rope_char_ptr_proxy& __x)
1050 _M_pos = __x._M_pos;
1051 _M_root = __x._M_root;
1055 template<
class _CharT2,
class _Alloc2>
1057 operator==(
const _Rope_char_ptr_proxy<_CharT2, _Alloc2>& __x,
1058 const _Rope_char_ptr_proxy<_CharT2, _Alloc2>& __y);
1060 _Rope_char_ref_proxy<_CharT, _Alloc>
operator*()
const
1061 {
return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root, _M_pos); }
1074#pragma GCC diagnostic push
1075#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1076 template<
class _CharT,
class _Alloc>
1077 class _Rope_iterator_base
1078 :
public std::iterator<std::random_access_iterator_tag, _CharT>
1080 friend class rope<_CharT, _Alloc>;
1082 typedef _Alloc _allocator_type;
1083 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1086 enum { _S_path_cache_len = 4 };
1087 enum { _S_iterator_buf_len = 15 };
1088 std::size_t _M_current_pos;
1090 std::size_t _M_leaf_pos;
1091 __GC_CONST _CharT* _M_buf_start;
1094 __GC_CONST _CharT* _M_buf_ptr;
1097 __GC_CONST _CharT* _M_buf_end;
1103 const _RopeRep* _M_path_end[_S_path_cache_len];
1107 unsigned char _M_path_directions;
1112 _CharT _M_tmp_buf[_S_iterator_buf_len];
1120 static void _S_setbuf(_Rope_iterator_base& __x);
1123 static void _S_setcache(_Rope_iterator_base& __x);
1126 static void _S_setcache_for_incr(_Rope_iterator_base& __x);
1129 _Rope_iterator_base() { }
1131 _Rope_iterator_base(_RopeRep* __root, std::size_t __pos)
1132 : _M_current_pos(__pos), _M_root(__root), _M_buf_ptr(0) { }
1134 void _M_incr(std::size_t __n);
1135 void _M_decr(std::size_t __n);
1139 {
return _M_current_pos; }
1141 _Rope_iterator_base(
const _Rope_iterator_base& __x)
1143 if (0 != __x._M_buf_ptr && __x._M_buf_start != __x._M_tmp_buf)
1147 _M_current_pos = __x._M_current_pos;
1148 _M_root = __x._M_root;
1153#pragma GCC diagnostic pop
1155 template<
class _CharT,
class _Alloc>
1156 class _Rope_iterator;
1158 template<
class _CharT,
class _Alloc>
1159 class _Rope_const_iterator
1160 :
public _Rope_iterator_base<_CharT, _Alloc>
1162 friend class rope<_CharT, _Alloc>;
1164 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1166 _Rope_const_iterator(
const _RopeRep* __root, std::size_t __pos)
1167 : _Rope_iterator_base<_CharT, _Alloc>(const_cast<_RopeRep*>(__root),
1172 typedef _CharT reference;
1175 typedef const _CharT* pointer;
1178 _Rope_const_iterator() { }
1180 _Rope_const_iterator(
const _Rope_const_iterator& __x)
1181 : _Rope_iterator_base<_CharT,_Alloc>(__x) { }
1183 _Rope_const_iterator(
const _Rope_iterator<_CharT,_Alloc>& __x);
1185 _Rope_const_iterator(
const rope<_CharT, _Alloc>& __r, std::size_t __pos)
1186 : _Rope_iterator_base<_CharT,_Alloc>(__r._M_tree_ptr, __pos) { }
1188 _Rope_const_iterator&
1189 operator=(
const _Rope_const_iterator& __x)
1191 if (0 != __x._M_buf_ptr && __x._M_buf_start != __x._M_tmp_buf)
1192 *(
static_cast<_Rope_iterator_base<_CharT, _Alloc>*
>(
this)) = __x;
1195 this->_M_current_pos = __x._M_current_pos;
1196 this->_M_root = __x._M_root;
1197 this->_M_buf_ptr = 0;
1205 if (0 == this->_M_buf_ptr)
1206 this->_S_setcache(*
this);
1207 return *this->_M_buf_ptr;
1215 return *
const_cast<_Rope_const_iterator&
>(*this);
1218 _Rope_const_iterator&
1221 __GC_CONST _CharT* __next;
1222 if (0 != this->_M_buf_ptr
1223 && (__next = this->_M_buf_ptr + 1) < this->_M_buf_end)
1225 this->_M_buf_ptr = __next;
1226 ++this->_M_current_pos;
1233 _Rope_const_iterator&
1234 operator+=(std::ptrdiff_t __n)
1239 this->_M_decr(-__n);
1243 _Rope_const_iterator&
1250 _Rope_const_iterator&
1251 operator-=(std::ptrdiff_t __n)
1256 this->_M_incr(-__n);
1260 _Rope_const_iterator
1263 std::size_t __old_pos = this->_M_current_pos;
1265 return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos);
1271 _Rope_const_iterator
1274 std::size_t __old_pos = this->_M_current_pos;
1276 return _Rope_const_iterator<_CharT,_Alloc>(this->_M_root, __old_pos);
1279 template<
class _CharT2,
class _Alloc2>
1280 friend _Rope_const_iterator<_CharT2, _Alloc2>
1281 operator-(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1282 std::ptrdiff_t __n);
1284 template<
class _CharT2,
class _Alloc2>
1285 friend _Rope_const_iterator<_CharT2, _Alloc2>
1286 operator+(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1287 std::ptrdiff_t __n);
1289 template<
class _CharT2,
class _Alloc2>
1290 friend _Rope_const_iterator<_CharT2, _Alloc2>
1292 const _Rope_const_iterator<_CharT2, _Alloc2>& __x);
1295 operator[](std::size_t __n)
1296 {
return rope<_CharT, _Alloc>::_S_fetch(this->_M_root,
1297 this->_M_current_pos + __n); }
1299 template<
class _CharT2,
class _Alloc2>
1301 operator==(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1302 const _Rope_const_iterator<_CharT2, _Alloc2>& __y);
1304 template<
class _CharT2,
class _Alloc2>
1306 operator<(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1307 const _Rope_const_iterator<_CharT2, _Alloc2>& __y);
1309 template<
class _CharT2,
class _Alloc2>
1310 friend std::ptrdiff_t
1311 operator-(
const _Rope_const_iterator<_CharT2, _Alloc2>& __x,
1312 const _Rope_const_iterator<_CharT2, _Alloc2>& __y);
1315 template<
class _CharT,
class _Alloc>
1316 class _Rope_iterator
1317 :
public _Rope_iterator_base<_CharT, _Alloc>
1319 friend class rope<_CharT, _Alloc>;
1321 typedef typename _Rope_iterator_base<_CharT, _Alloc>::_RopeRep _RopeRep;
1322 rope<_CharT, _Alloc>* _M_root_rope;
1330 _Rope_iterator(rope<_CharT, _Alloc>* __r, std::size_t __pos)
1331 : _Rope_iterator_base<_CharT, _Alloc>(__r->_M_tree_ptr, __pos),
1333 { _RopeRep::_S_ref(this->_M_root);
1334 if (!(__r ->
empty()))
1335 this->_S_setcache(*
this);
1340 typedef _Rope_char_ref_proxy<_CharT, _Alloc> reference;
1341 typedef _Rope_char_ref_proxy<_CharT, _Alloc>* pointer;
1343 rope<_CharT, _Alloc>&
1345 {
return *_M_root_rope; }
1352 _Rope_iterator(
const _Rope_iterator& __x)
1353 : _Rope_iterator_base<_CharT, _Alloc>(__x)
1355 _M_root_rope = __x._M_root_rope;
1356 _RopeRep::_S_ref(this->_M_root);
1359 _Rope_iterator(rope<_CharT, _Alloc>& __r, std::size_t __pos);
1362 { _RopeRep::_S_unref(this->_M_root); }
1365 operator=(
const _Rope_iterator& __x)
1367 _RopeRep* __old = this->_M_root;
1369 _RopeRep::_S_ref(__x._M_root);
1370 if (0 != __x._M_buf_ptr && __x._M_buf_start != __x._M_tmp_buf)
1372 _M_root_rope = __x._M_root_rope;
1373 *(
static_cast<_Rope_iterator_base<_CharT, _Alloc>*
>(
this)) = __x;
1377 this->_M_current_pos = __x._M_current_pos;
1378 this->_M_root = __x._M_root;
1379 _M_root_rope = __x._M_root_rope;
1380 this->_M_buf_ptr = 0;
1382 _RopeRep::_S_unref(__old);
1390 if (0 == this->_M_buf_ptr)
1391 return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope,
1392 this->_M_current_pos);
1394 return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope,
1395 this->_M_current_pos,
1403 return *
const_cast<_Rope_iterator&
>(*this);
1414 operator+=(std::ptrdiff_t __n)
1419 this->_M_decr(-__n);
1431 operator-=(std::ptrdiff_t __n)
1436 this->_M_incr(-__n);
1443 std::size_t __old_pos = this->_M_current_pos;
1445 return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos);
1451 std::size_t __old_pos = this->_M_current_pos;
1453 return _Rope_iterator<_CharT,_Alloc>(_M_root_rope, __old_pos);
1457 operator[](std::ptrdiff_t __n)
1458 {
return _Rope_char_ref_proxy<_CharT, _Alloc>(_M_root_rope,
1459 this->_M_current_pos
1462 template<
class _CharT2,
class _Alloc2>
1464 operator==(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1465 const _Rope_iterator<_CharT2, _Alloc2>& __y);
1467 template<
class _CharT2,
class _Alloc2>
1469 operator<(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1470 const _Rope_iterator<_CharT2, _Alloc2>& __y);
1472 template<
class _CharT2,
class _Alloc2>
1473 friend std::ptrdiff_t
1474 operator-(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1475 const _Rope_iterator<_CharT2, _Alloc2>& __y);
1477 template<
class _CharT2,
class _Alloc2>
1478 friend _Rope_iterator<_CharT2, _Alloc2>
1479 operator-(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1480 std::ptrdiff_t __n);
1482 template<
class _CharT2,
class _Alloc2>
1483 friend _Rope_iterator<_CharT2, _Alloc2>
1484 operator+(
const _Rope_iterator<_CharT2, _Alloc2>& __x,
1485 std::ptrdiff_t __n);
1487 template<
class _CharT2,
class _Alloc2>
1488 friend _Rope_iterator<_CharT2, _Alloc2>
1490 const _Rope_iterator<_CharT2, _Alloc2>& __x);
1494 template <
class _CharT,
class _Alloc>
1498 typedef _Alloc allocator_type;
1501 get_allocator()
const
1502 {
return *
static_cast<const _Alloc*
>(
this); }
1506 {
return *
static_cast<_Alloc*
>(
this); }
1508 const allocator_type&
1509 _M_get_allocator()
const
1510 {
return *
static_cast<const _Alloc*
>(
this); }
1512 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1515 _Rope_base(_RopeRep* __t,
const allocator_type&)
1516 : _M_tree_ptr(__t) { }
1518 _Rope_base(
const allocator_type&) { }
1521 _RopeRep *_M_tree_ptr;
1523#define __ROPE_DEFINE_ALLOC(_Tp, __name) \
1525 __alloc_traits<_Alloc>::template rebind<_Tp>::other __name##Alloc; \
1526 static _Tp* __name##_allocate(std::size_t __n) \
1527 { return __name##Alloc().allocate(__n); } \
1528 static void __name##_deallocate(_Tp *__p, std::size_t __n) \
1529 { __name##Alloc().deallocate(__p, __n); }
1530 __ROPE_DEFINE_ALLOCS(_Alloc)
1531#undef __ROPE_DEFINE_ALLOC
1535 operator=(
const _Rope_base&);
1537 _Rope_base(
const _Rope_base&);
1545 template <
class _CharT,
class _Alloc>
1546 class rope :
public _Rope_base<_CharT, _Alloc>
1549 typedef _CharT value_type;
1550 typedef std::ptrdiff_t difference_type;
1551 typedef std::size_t size_type;
1552 typedef _CharT const_reference;
1553 typedef const _CharT* const_pointer;
1554 typedef _Rope_iterator<_CharT, _Alloc> iterator;
1555 typedef _Rope_const_iterator<_CharT, _Alloc> const_iterator;
1556 typedef _Rope_char_ref_proxy<_CharT, _Alloc> reference;
1557 typedef _Rope_char_ptr_proxy<_CharT, _Alloc> pointer;
1559 friend class _Rope_iterator<_CharT, _Alloc>;
1560 friend class _Rope_const_iterator<_CharT, _Alloc>;
1561 friend struct _Rope_RopeRep<_CharT, _Alloc>;
1562 friend class _Rope_iterator_base<_CharT, _Alloc>;
1563 friend class _Rope_char_ptr_proxy<_CharT, _Alloc>;
1564 friend class _Rope_char_ref_proxy<_CharT, _Alloc>;
1565 friend struct _Rope_RopeSubstring<_CharT, _Alloc>;
1568 typedef _Rope_base<_CharT, _Alloc> _Base;
1569 typedef typename _Base::allocator_type allocator_type;
1570 using _Base::_M_tree_ptr;
1571 using _Base::get_allocator;
1572 using _Base::_M_get_allocator;
1573 typedef __GC_CONST _CharT* _Cstrptr;
1575 static _CharT _S_empty_c_str[1];
1579 {
return __c == _S_eos((_CharT*)0); }
1581 enum { _S_copy_max = 23 };
1585 typedef _Rope_RopeRep<_CharT, _Alloc> _RopeRep;
1586 typedef _Rope_RopeConcatenation<_CharT, _Alloc> _RopeConcatenation;
1587 typedef _Rope_RopeLeaf<_CharT, _Alloc> _RopeLeaf;
1588 typedef _Rope_RopeFunction<_CharT, _Alloc> _RopeFunction;
1589 typedef _Rope_RopeSubstring<_CharT, _Alloc> _RopeSubstring;
1592 static _CharT _S_fetch(_RopeRep* __r, size_type __pos);
1601 static _CharT* _S_fetch_ptr(_RopeRep* __r, size_type __pos);
1606 _Rope_char_consumer<_CharT>& __c,
1607 const _RopeRep* __r,
1608 size_type __begin, size_type __end);
1613 _S_unref(_RopeRep* __t)
1614 { _RopeRep::_S_unref(__t); }
1617 _S_ref(_RopeRep* __t)
1618 { _RopeRep::_S_ref(__t); }
1621 static void _S_unref(_RopeRep*) { }
1622 static void _S_ref(_RopeRep*) { }
1626 typedef _Rope_RopeRep<_CharT, _Alloc>* _Self_destruct_ptr;
1628 typedef _Rope_self_destruct_ptr<_CharT, _Alloc> _Self_destruct_ptr;
1632 static _RopeRep* _S_substring(_RopeRep* __base,
1633 size_type __start, size_type __endp1);
1635 static _RopeRep* _S_concat_char_iter(_RopeRep* __r,
1636 const _CharT* __iter,
1638 allocator_type& __a);
1642 static _RopeRep* _S_destr_concat_char_iter(_RopeRep* __r,
1643 const _CharT* __iter,
1645 allocator_type& __a)
1651 {
return _S_concat_char_iter(__r, __iter, __slen, __a); }
1656 static _RopeRep* _S_concat(_RopeRep* __left, _RopeRep* __right);
1662 apply_to_pieces(size_type __begin, size_type __end,
1663 _Rope_char_consumer<_CharT>& __c)
const
1664 { _S_apply_to_pieces(__c, this->_M_tree_ptr, __begin, __end); }
1669 _S_rounded_up_size(size_type __n)
1670 {
return _RopeLeaf::_S_rounded_up_size(__n); }
1673 _S_allocated_capacity(size_type __n)
1675 if (_S_is_basic_char_type((_CharT*)0))
1676 return _S_rounded_up_size(__n) - 1;
1678 return _S_rounded_up_size(__n);
1685 _S_new_RopeLeaf(__GC_CONST _CharT *__s,
1686 size_type __size, allocator_type& __a)
1688 _RopeLeaf* __space =
typename _Base::_LAlloc(__a).allocate(1);
1689 return new(__space) _RopeLeaf(__s, __size, __a);
1692 static _RopeConcatenation*
1693 _S_new_RopeConcatenation(_RopeRep* __left, _RopeRep* __right,
1694 allocator_type& __a)
1696 _RopeConcatenation* __space =
typename _Base::_CAlloc(__a).allocate(1);
1697 return new(__space) _RopeConcatenation(__left, __right, __a);
1700 static _RopeFunction*
1701 _S_new_RopeFunction(char_producer<_CharT>* __f,
1702 size_type __size,
bool __d, allocator_type& __a)
1704 _RopeFunction* __space =
typename _Base::_FAlloc(__a).allocate(1);
1705 return new(__space) _RopeFunction(__f, __size, __d, __a);
1708 static _RopeSubstring*
1709 _S_new_RopeSubstring(_Rope_RopeRep<_CharT,_Alloc>* __b, size_type __s,
1710 size_type __l, allocator_type& __a)
1712 _RopeSubstring* __space =
typename _Base::_SAlloc(__a).allocate(1);
1713 return new(__space) _RopeSubstring(__b, __s, __l, __a);
1717 _S_RopeLeaf_from_unowned_char_ptr(
const _CharT *__s,
1718 size_type __size, allocator_type& __a)
1719#define __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __size, __a) \
1720 _S_RopeLeaf_from_unowned_char_ptr(__s, __size, __a)
1724 _CharT* __buf = __a.allocate(_S_rounded_up_size(__size));
1726 __uninitialized_copy_n_a(__s, __size, __buf, __a);
1727 _S_cond_store_eos(__buf[__size]);
1729 {
return _S_new_RopeLeaf(__buf, __size, __a); }
1732 _RopeRep::__STL_FREE_STRING(__buf, __size, __a);
1733 __throw_exception_again;
1744 _S_tree_concat(_RopeRep* __left, _RopeRep* __right);
1748 _S_leaf_concat_char_iter(_RopeLeaf* __r,
1749 const _CharT* __iter, size_type __slen);
1755 _S_destr_leaf_concat_char_iter(_RopeLeaf* __r,
1756 const _CharT* __iter, size_type __slen);
1762 static size_type _S_char_ptr_len(
const _CharT* __s);
1765 rope(_RopeRep* __t,
const allocator_type& __a = allocator_type())
1766 : _Base(__t, __a) { }
1772 static _CharT* _S_flatten(_RopeRep* __r, _CharT* __buffer);
1776 static _CharT* _S_flatten(_RopeRep* __r,
1777 size_type __start, size_type __len,
1780 static const unsigned long
1781 _S_min_len[__detail::_S_max_rope_depth + 1];
1784 _S_is_balanced(_RopeRep* __r)
1785 {
return (__r->_M_size >= _S_min_len[__r->_M_depth]); }
1788 _S_is_almost_balanced(_RopeRep* __r)
1789 {
return (__r->_M_depth == 0
1790 || __r->_M_size >= _S_min_len[__r->_M_depth - 1]); }
1793 _S_is_roughly_balanced(_RopeRep* __r)
1794 {
return (__r->_M_depth <= 1
1795 || __r->_M_size >= _S_min_len[__r->_M_depth - 2]); }
1799 _S_concat_and_set_balanced(_RopeRep* __left, _RopeRep* __right)
1801 _RopeRep* __result = _S_concat(__left, __right);
1802 if (_S_is_balanced(__result))
1803 __result->_M_is_balanced =
true;
1812 static _RopeRep* _S_balance(_RopeRep* __r);
1816 static void _S_add_to_forest(_RopeRep*__r, _RopeRep** __forest);
1819 static void _S_add_leaf_to_forest(_RopeRep* __r, _RopeRep** __forest);
1822 static void _S_dump(_RopeRep* __r,
int __indent = 0);
1825 static int _S_compare(
const _RopeRep* __x,
const _RopeRep* __y);
1828 _GLIBCXX_NODISCARD
bool
1830 {
return 0 == this->_M_tree_ptr; }
1836 compare(
const rope& __y)
const
1837 {
return _S_compare(this->_M_tree_ptr, __y._M_tree_ptr); }
1839 rope(
const _CharT* __s,
const allocator_type& __a = allocator_type())
1843 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, _S_char_ptr_len(__s),
1844 _M_get_allocator());
1847 rope(
const _CharT* __s, size_type __len,
1848 const allocator_type& __a = allocator_type())
1852 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __len, _M_get_allocator());
1858 rope(
const _CharT* __s,
const _CharT* __e,
1859 const allocator_type& __a = allocator_type())
1863 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(__s, __e - __s, _M_get_allocator());
1866 rope(
const const_iterator& __s,
const const_iterator& __e,
1867 const allocator_type& __a = allocator_type())
1868 : _Base(_S_substring(__s._M_root, __s._M_current_pos,
1869 __e._M_current_pos), __a)
1872 rope(
const iterator& __s,
const iterator& __e,
1873 const allocator_type& __a = allocator_type())
1874 : _Base(_S_substring(__s._M_root, __s._M_current_pos,
1875 __e._M_current_pos), __a)
1878 rope(_CharT __c,
const allocator_type& __a = allocator_type())
1881 _CharT* __buf = this->_Data_allocate(_S_rounded_up_size(1));
1887 this->_M_tree_ptr = _S_new_RopeLeaf(__buf, 1,
1888 _M_get_allocator());
1892 _RopeRep::__STL_FREE_STRING(__buf, 1, _M_get_allocator());
1893 __throw_exception_again;
1897 rope(size_type __n, _CharT __c,
1898 const allocator_type& __a = allocator_type());
1900 rope(
const allocator_type& __a = allocator_type())
1904 rope(char_producer<_CharT> *__fn, size_type __len,
bool __delete_fn,
1905 const allocator_type& __a = allocator_type())
1908 this->_M_tree_ptr = (0 == __len)
1910 : _S_new_RopeFunction(__fn, __len, __delete_fn, _M_get_allocator());
1913 rope(
const rope& __x,
const allocator_type& __a = allocator_type())
1914 : _Base(__x._M_tree_ptr, __a)
1915 { _S_ref(this->_M_tree_ptr); }
1918 { _S_unref(this->_M_tree_ptr); }
1921 operator=(
const rope& __x)
1923 _RopeRep* __old = this->_M_tree_ptr;
1924 this->_M_tree_ptr = __x._M_tree_ptr;
1925 _S_ref(this->_M_tree_ptr);
1933 _S_unref(this->_M_tree_ptr);
1934 this->_M_tree_ptr = 0;
1938 push_back(_CharT __x)
1940 allocator_type __a = _M_get_allocator();
1941 _RopeRep* __old = this->_M_tree_ptr;
1943 = _S_destr_concat_char_iter(this->_M_tree_ptr, &__x, 1, __a);
1950 _RopeRep* __old = this->_M_tree_ptr;
1951 this->_M_tree_ptr = _S_substring(this->_M_tree_ptr,
1952 0, this->_M_tree_ptr->_M_size - 1);
1958 {
return _S_fetch(this->_M_tree_ptr, this->_M_tree_ptr->_M_size - 1); }
1961 push_front(_CharT __x)
1963 _RopeRep* __old = this->_M_tree_ptr;
1965 __STL_ROPE_FROM_UNOWNED_CHAR_PTR(&__x, 1, _M_get_allocator());
1968 this->_M_tree_ptr = _S_concat(__left, this->_M_tree_ptr);
1975 __throw_exception_again;
1982 _RopeRep* __old = this->_M_tree_ptr;
1984 = _S_substring(this->_M_tree_ptr, 1, this->_M_tree_ptr->_M_size);
1990 {
return _S_fetch(this->_M_tree_ptr, 0); }
1995 _RopeRep* __old = this->_M_tree_ptr;
1996 this->_M_tree_ptr = _S_balance(this->_M_tree_ptr);
2001 copy(_CharT* __buffer)
const
2003 _Destroy_const(__buffer, __buffer + size(), _M_get_allocator());
2004 _S_flatten(this->_M_tree_ptr, __buffer);
2013 copy(size_type __pos, size_type __n, _CharT* __buffer)
const
2015 size_type __size = size();
2016 size_type __len = (__pos + __n > __size? __size - __pos : __n);
2018 _Destroy_const(__buffer, __buffer + __len, _M_get_allocator());
2019 _S_flatten(this->_M_tree_ptr, __pos, __len, __buffer);
2027 { _S_dump(this->_M_tree_ptr); }
2031 const _CharT* c_str()
const;
2035 const _CharT* replace_with_c_str();
2043 if (0 == this->_M_tree_ptr)
2045 if (__detail::_S_leaf == this->_M_tree_ptr->_M_tag &&
2046 ((_RopeLeaf*)this->_M_tree_ptr)->_M_data ==
2047 this->_M_tree_ptr->_M_c_string)
2053 this->_M_tree_ptr->_M_free_c_string();
2055 this->_M_tree_ptr->_M_c_string = 0;
2059 operator[] (size_type __pos)
const
2060 {
return _S_fetch(this->_M_tree_ptr, __pos); }
2063 at(size_type __pos)
const
2066 return (*
this)[__pos];
2071 {
return(const_iterator(this->_M_tree_ptr, 0)); }
2076 {
return(const_iterator(this->_M_tree_ptr, 0)); }
2080 {
return(const_iterator(this->_M_tree_ptr, size())); }
2084 {
return(const_iterator(this->_M_tree_ptr, size())); }
2088 {
return(0 == this->_M_tree_ptr? 0 : this->_M_tree_ptr->_M_size); }
2097 return _S_min_len[int(__detail::_S_max_rope_depth) - 1] - 1;
2110 const_rbegin()
const
2121 template<
class _CharT2,
class _Alloc2>
2126 template<
class _CharT2,
class _Alloc2>
2130 template<
class _CharT2,
class _Alloc2>
2141 append(
const _CharT* __iter, size_type __n)
2143 allocator_type __a = _M_get_allocator();
2144 _RopeRep* __result =
2145 _S_destr_concat_char_iter(this->_M_tree_ptr, __iter, __n, __a);
2146 _S_unref(this->_M_tree_ptr);
2147 this->_M_tree_ptr = __result;
2152 append(
const _CharT* __c_string)
2154 size_type __len = _S_char_ptr_len(__c_string);
2155 append(__c_string, __len);
2160 append(
const _CharT* __s,
const _CharT* __e)
2162 allocator_type __a = _M_get_allocator();
2163 _RopeRep* __result =
2164 _S_destr_concat_char_iter(this->_M_tree_ptr, __s, __e - __s, __a);
2165 _S_unref(this->_M_tree_ptr);
2166 this->_M_tree_ptr = __result;
2171 append(const_iterator __s, const_iterator __e)
2173 _Self_destruct_ptr __appendee(_S_substring(__s._M_root,
2175 __e._M_current_pos));
2176 _RopeRep* __result = _S_concat(this->_M_tree_ptr,
2177 (_RopeRep*)__appendee);
2178 _S_unref(this->_M_tree_ptr);
2179 this->_M_tree_ptr = __result;
2186 allocator_type __a = _M_get_allocator();
2187 _RopeRep* __result =
2188 _S_destr_concat_char_iter(this->_M_tree_ptr, &__c, 1, __a);
2189 _S_unref(this->_M_tree_ptr);
2190 this->_M_tree_ptr = __result;
2196 {
return append(_CharT()); }
2199 append(
const rope& __y)
2201 _RopeRep* __result = _S_concat(this->_M_tree_ptr, __y._M_tree_ptr);
2202 _S_unref(this->_M_tree_ptr);
2203 this->_M_tree_ptr = __result;
2208 append(size_type __n, _CharT __c)
2211 return append(__last);
2217 _RopeRep* __tmp = this->_M_tree_ptr;
2218 this->_M_tree_ptr = __b._M_tree_ptr;
2219 __b._M_tree_ptr = __tmp;
2225 replace(_RopeRep* __old, size_type __pos1,
2226 size_type __pos2, _RopeRep* __r)
2233 _Self_destruct_ptr __left(_S_substring(__old, 0, __pos1));
2234 _Self_destruct_ptr __right(_S_substring(__old, __pos2, __old->_M_size));
2238 __result = _S_concat(__left, __right);
2241 _Self_destruct_ptr __left_result(_S_concat(__left, __r));
2242 __result = _S_concat(__left_result, __right);
2249 insert(size_type __p,
const rope& __r)
2251 _RopeRep* __result =
2252 replace(this->_M_tree_ptr, __p, __p, __r._M_tree_ptr);
2253 _S_unref(this->_M_tree_ptr);
2254 this->_M_tree_ptr = __result;
2258 insert(size_type __p, size_type __n, _CharT __c)
2265 insert(size_type __p,
const _CharT* __i, size_type __n)
2267 _Self_destruct_ptr __left(_S_substring(this->_M_tree_ptr, 0, __p));
2268 _Self_destruct_ptr __right(_S_substring(this->_M_tree_ptr,
2270 _Self_destruct_ptr __left_result(_S_concat_char_iter(__left, __i, __n,
2271 _M_get_allocator()));
2275 _RopeRep* __result = _S_concat(__left_result, __right);
2276 _S_unref(this->_M_tree_ptr);
2277 this->_M_tree_ptr = __result;
2281 insert(size_type __p,
const _CharT* __c_string)
2282 { insert(__p, __c_string, _S_char_ptr_len(__c_string)); }
2285 insert(size_type __p, _CharT __c)
2286 { insert(__p, &__c, 1); }
2289 insert(size_type __p)
2291 _CharT __c = _CharT();
2292 insert(__p, &__c, 1);
2296 insert(size_type __p,
const _CharT* __i,
const _CharT* __j)
2303 insert(size_type __p,
const const_iterator& __i,
2304 const const_iterator& __j)
2311 insert(size_type __p,
const iterator& __i,
2312 const iterator& __j)
2321 replace(size_type __p, size_type __n,
const rope& __r)
2323 _RopeRep* __result =
2324 replace(this->_M_tree_ptr, __p, __p + __n, __r._M_tree_ptr);
2325 _S_unref(this->_M_tree_ptr);
2326 this->_M_tree_ptr = __result;
2330 replace(size_type __p, size_type __n,
2331 const _CharT* __i, size_type __i_len)
2333 rope __r(__i, __i_len);
2334 replace(__p, __n, __r);
2338 replace(size_type __p, size_type __n, _CharT __c)
2341 replace(__p, __n, __r);
2345 replace(size_type __p, size_type __n,
const _CharT* __c_string)
2347 rope __r(__c_string);
2348 replace(__p, __n, __r);
2352 replace(size_type __p, size_type __n,
2353 const _CharT* __i,
const _CharT* __j)
2356 replace(__p, __n, __r);
2360 replace(size_type __p, size_type __n,
2361 const const_iterator& __i,
const const_iterator& __j)
2364 replace(__p, __n, __r);
2368 replace(size_type __p, size_type __n,
2369 const iterator& __i,
const iterator& __j)
2372 replace(__p, __n, __r);
2377 replace(size_type __p, _CharT __c)
2379 iterator __i(
this, __p);
2384 replace(size_type __p,
const rope& __r)
2385 { replace(__p, 1, __r); }
2388 replace(size_type __p,
const _CharT* __i, size_type __i_len)
2389 { replace(__p, 1, __i, __i_len); }
2392 replace(size_type __p,
const _CharT* __c_string)
2393 { replace(__p, 1, __c_string); }
2396 replace(size_type __p,
const _CharT* __i,
const _CharT* __j)
2397 { replace(__p, 1, __i, __j); }
2400 replace(size_type __p,
const const_iterator& __i,
2401 const const_iterator& __j)
2402 { replace(__p, 1, __i, __j); }
2405 replace(size_type __p,
const iterator& __i,
2406 const iterator& __j)
2407 { replace(__p, 1, __i, __j); }
2411 erase(size_type __p, size_type __n)
2413 _RopeRep* __result = replace(this->_M_tree_ptr, __p,
2415 _S_unref(this->_M_tree_ptr);
2416 this->_M_tree_ptr = __result;
2421 insert(
const iterator& __p,
const rope& __r)
2423 insert(__p.index(), __r);
2428 insert(
const iterator& __p, size_type __n, _CharT __c)
2430 insert(__p.index(), __n, __c);
2434 iterator insert(
const iterator& __p, _CharT __c)
2436 insert(__p.index(), __c);
2441 insert(
const iterator& __p )
2443 insert(__p.index());
2448 insert(
const iterator& __p,
const _CharT* c_string)
2450 insert(__p.index(), c_string);
2455 insert(
const iterator& __p,
const _CharT* __i, size_type __n)
2457 insert(__p.index(), __i, __n);
2462 insert(
const iterator& __p,
const _CharT* __i,
2465 insert(__p.index(), __i, __j);
2470 insert(
const iterator& __p,
2471 const const_iterator& __i,
const const_iterator& __j)
2473 insert(__p.index(), __i, __j);
2478 insert(
const iterator& __p,
2479 const iterator& __i,
const iterator& __j)
2481 insert(__p.index(), __i, __j);
2487 replace(
const iterator& __p,
const iterator& __q,
const rope& __r)
2488 { replace(__p.index(), __q.index() - __p.index(), __r); }
2491 replace(
const iterator& __p,
const iterator& __q, _CharT __c)
2492 { replace(__p.index(), __q.index() - __p.index(), __c); }
2495 replace(
const iterator& __p,
const iterator& __q,
2496 const _CharT* __c_string)
2497 { replace(__p.index(), __q.index() - __p.index(), __c_string); }
2500 replace(
const iterator& __p,
const iterator& __q,
2501 const _CharT* __i, size_type __n)
2502 { replace(__p.index(), __q.index() - __p.index(), __i, __n); }
2505 replace(
const iterator& __p,
const iterator& __q,
2506 const _CharT* __i,
const _CharT* __j)
2507 { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
2510 replace(
const iterator& __p,
const iterator& __q,
2511 const const_iterator& __i,
const const_iterator& __j)
2512 { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
2515 replace(
const iterator& __p,
const iterator& __q,
2516 const iterator& __i,
const iterator& __j)
2517 { replace(__p.index(), __q.index() - __p.index(), __i, __j); }
2521 replace(
const iterator& __p,
const rope& __r)
2522 { replace(__p.index(), __r); }
2525 replace(
const iterator& __p, _CharT __c)
2526 { replace(__p.index(), __c); }
2529 replace(
const iterator& __p,
const _CharT* __c_string)
2530 { replace(__p.index(), __c_string); }
2533 replace(
const iterator& __p,
const _CharT* __i, size_type __n)
2534 { replace(__p.index(), __i, __n); }
2537 replace(
const iterator& __p,
const _CharT* __i,
const _CharT* __j)
2538 { replace(__p.index(), __i, __j); }
2541 replace(
const iterator& __p, const_iterator __i, const_iterator __j)
2542 { replace(__p.index(), __i, __j); }
2545 replace(
const iterator& __p, iterator __i, iterator __j)
2546 { replace(__p.index(), __i, __j); }
2550 erase(
const iterator& __p,
const iterator& __q)
2552 size_type __p_index = __p.index();
2553 erase(__p_index, __q.index() - __p_index);
2554 return iterator(
this, __p_index);
2558 erase(
const iterator& __p)
2560 size_type __p_index = __p.index();
2561 erase(__p_index, 1);
2562 return iterator(
this, __p_index);
2566 substr(size_type __start, size_type __len = 1)
const
2574 substr(iterator __start, iterator __end)
const
2582 substr(iterator __start)
const
2584 size_type __pos = __start.index();
2590 substr(const_iterator __start, const_iterator __end)
const
2600 substr(const_iterator __start)
2602 size_type __pos = __start.index();
2607 static const size_type npos;
2609 size_type find(_CharT __c, size_type __pos = 0)
const;
2612 find(
const _CharT* __s, size_type __pos = 0)
const
2614 size_type __result_pos;
2615 const_iterator __result =
2616 std::search(const_begin() + __pos, const_end(),
2617 __s, __s + _S_char_ptr_len(__s));
2618 __result_pos = __result.index();
2619#ifndef __STL_OLD_ROPE_SEMANTICS
2620 if (__result_pos == size())
2621 __result_pos = npos;
2623 return __result_pos;
2628 {
return(iterator(
this, 0)); }
2632 {
return(iterator(
this, size())); }
2645 mutable_reference_at(size_type __pos)
2646 {
return reference(
this, __pos); }
2650 operator[] (size_type __pos)
2651 {
return _char_ref_proxy(
this, __pos); }
2657 return (*
this)[__pos];
2660 void resize(size_type __n, _CharT __c) { }
2661 void resize(size_type __n) { }
2662 void reserve(size_type __res_arg = 0) { }
2666 {
return max_size(); }
2672 copy(_CharT* __buffer, size_type __n,
2673 size_type __pos = 0)
const
2674 {
return copy(__pos, __n, __buffer); }
2678 {
return mutable_end(); }
2682 {
return mutable_begin(); }
2686 {
return mutable_rend(); }
2690 {
return mutable_rbegin(); }
2695 {
return const_end(); }
2699 {
return const_begin(); }
2703 {
return const_rend(); }
2707 {
return const_rbegin(); }
2712 template <
class _CharT,
class _Alloc>
2713 const typename rope<_CharT, _Alloc>::size_type
2716 template <
class _CharT,
class _Alloc>
2717 inline bool operator==(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2718 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2719 {
return (__x._M_current_pos == __y._M_current_pos
2720 && __x._M_root == __y._M_root); }
2722 template <
class _CharT,
class _Alloc>
2723 inline bool operator<(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2724 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2725 {
return (__x._M_current_pos < __y._M_current_pos); }
2727 template <
class _CharT,
class _Alloc>
2728 inline bool operator!=(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2729 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2730 {
return !(__x == __y); }
2732 template <
class _CharT,
class _Alloc>
2733 inline bool operator>(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2734 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2735 {
return __y < __x; }
2737 template <
class _CharT,
class _Alloc>
2739 operator<=(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2740 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2741 {
return !(__y < __x); }
2743 template <
class _CharT,
class _Alloc>
2745 operator>=(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2746 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2747 {
return !(__x < __y); }
2749 template <
class _CharT,
class _Alloc>
2750 inline std::ptrdiff_t
2751 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2752 const _Rope_const_iterator<_CharT, _Alloc>& __y)
2754 return (std::ptrdiff_t)__x._M_current_pos
2755 - (std::ptrdiff_t)__y._M_current_pos;
2758 template <
class _CharT,
class _Alloc>
2759 inline _Rope_const_iterator<_CharT, _Alloc>
2760 operator-(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2762 {
return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root,
2763 __x._M_current_pos - __n); }
2765 template <
class _CharT,
class _Alloc>
2766 inline _Rope_const_iterator<_CharT, _Alloc>
2767 operator+(
const _Rope_const_iterator<_CharT, _Alloc>& __x,
2769 {
return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root,
2770 __x._M_current_pos + __n); }
2772 template <
class _CharT,
class _Alloc>
2773 inline _Rope_const_iterator<_CharT, _Alloc>
2775 const _Rope_const_iterator<_CharT, _Alloc>& __x)
2776 {
return _Rope_const_iterator<_CharT, _Alloc>(__x._M_root,
2777 __x._M_current_pos + __n); }
2779 template <
class _CharT,
class _Alloc>
2781 operator==(
const _Rope_iterator<_CharT, _Alloc>& __x,
2782 const _Rope_iterator<_CharT, _Alloc>& __y)
2783 {
return (__x._M_current_pos == __y._M_current_pos
2784 && __x._M_root_rope == __y._M_root_rope); }
2786 template <
class _CharT,
class _Alloc>
2788 operator<(
const _Rope_iterator<_CharT, _Alloc>& __x,
2789 const _Rope_iterator<_CharT, _Alloc>& __y)
2790 {
return (__x._M_current_pos < __y._M_current_pos); }
2792 template <
class _CharT,
class _Alloc>
2794 operator!=(
const _Rope_iterator<_CharT, _Alloc>& __x,
2795 const _Rope_iterator<_CharT, _Alloc>& __y)
2796 {
return !(__x == __y); }
2798 template <
class _CharT,
class _Alloc>
2800 operator>(
const _Rope_iterator<_CharT, _Alloc>& __x,
2801 const _Rope_iterator<_CharT, _Alloc>& __y)
2802 {
return __y < __x; }
2804 template <
class _CharT,
class _Alloc>
2806 operator<=(
const _Rope_iterator<_CharT, _Alloc>& __x,
2807 const _Rope_iterator<_CharT, _Alloc>& __y)
2808 {
return !(__y < __x); }
2810 template <
class _CharT,
class _Alloc>
2812 operator>=(
const _Rope_iterator<_CharT, _Alloc>& __x,
2813 const _Rope_iterator<_CharT, _Alloc>& __y)
2814 {
return !(__x < __y); }
2816 template <
class _CharT,
class _Alloc>
2817 inline std::ptrdiff_t
2818 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x,
2819 const _Rope_iterator<_CharT, _Alloc>& __y)
2820 {
return ((std::ptrdiff_t)__x._M_current_pos
2821 - (std::ptrdiff_t)__y._M_current_pos); }
2823 template <
class _CharT,
class _Alloc>
2824 inline _Rope_iterator<_CharT, _Alloc>
2825 operator-(
const _Rope_iterator<_CharT, _Alloc>& __x,
2827 {
return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
2828 __x._M_current_pos - __n); }
2830 template <
class _CharT,
class _Alloc>
2831 inline _Rope_iterator<_CharT, _Alloc>
2832 operator+(
const _Rope_iterator<_CharT, _Alloc>& __x, std::ptrdiff_t __n)
2833 {
return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
2834 __x._M_current_pos + __n); }
2836 template <
class _CharT,
class _Alloc>
2837 inline _Rope_iterator<_CharT, _Alloc>
2838 operator+(std::ptrdiff_t __n,
const _Rope_iterator<_CharT, _Alloc>& __x)
2839 {
return _Rope_iterator<_CharT, _Alloc>(__x._M_root_rope,
2840 __x._M_current_pos + __n); }
2842 template <
class _CharT,
class _Alloc>
2843 inline rope<_CharT, _Alloc>
2844 operator+(
const rope<_CharT, _Alloc>& __left,
2845 const rope<_CharT, _Alloc>& __right)
2849 typedef rope<_CharT, _Alloc> rope_type;
2850 return rope_type(rope_type::_S_concat(__left._M_tree_ptr,
2851 __right._M_tree_ptr));
2854 template <
class _CharT,
class _Alloc>
2855 inline rope<_CharT, _Alloc>&
2856 operator+=(rope<_CharT, _Alloc>& __left,
2857 const rope<_CharT, _Alloc>& __right)
2859 __left.append(__right);
2863 template <
class _CharT,
class _Alloc>
2864 inline rope<_CharT, _Alloc>
2865 operator+(
const rope<_CharT, _Alloc>& __left,
2866 const _CharT* __right)
2868 typedef rope<_CharT, _Alloc> rope_type;
2869 std::size_t __rlen = rope_type::_S_char_ptr_len(__right);
2870 _Alloc __a = __left.get_allocator();
2871 return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr,
2872 __right, __rlen, __a));
2875 template <
class _CharT,
class _Alloc>
2876 inline rope<_CharT, _Alloc>&
2877 operator+=(rope<_CharT, _Alloc>& __left,
2878 const _CharT* __right)
2880 __left.append(__right);
2884 template <
class _CharT,
class _Alloc>
2885 inline rope<_CharT, _Alloc>
2886 operator+(
const rope<_CharT, _Alloc>& __left, _CharT __right)
2888 typedef rope<_CharT, _Alloc> rope_type;
2889 _Alloc __a = __left.get_allocator();
2890 return rope_type(rope_type::_S_concat_char_iter(__left._M_tree_ptr,
2894 template <
class _CharT,
class _Alloc>
2895 inline rope<_CharT, _Alloc>&
2896 operator+=(rope<_CharT, _Alloc>& __left, _CharT __right)
2898 __left.append(__right);
2902 template <
class _CharT,
class _Alloc>
2904 operator<(
const rope<_CharT, _Alloc>& __left,
2905 const rope<_CharT, _Alloc>& __right)
2906 {
return __left.compare(__right) < 0; }
2908 template <
class _CharT,
class _Alloc>
2910 operator==(
const rope<_CharT, _Alloc>& __left,
2911 const rope<_CharT, _Alloc>& __right)
2912 {
return __left.compare(__right) == 0; }
2914 template <
class _CharT,
class _Alloc>
2916 operator==(
const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x,
2917 const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y)
2918 {
return (__x._M_pos == __y._M_pos && __x._M_root == __y._M_root); }
2920 template <
class _CharT,
class _Alloc>
2922 operator!=(
const rope<_CharT, _Alloc>& __x,
2923 const rope<_CharT, _Alloc>& __y)
2924 {
return !(__x == __y); }
2926 template <
class _CharT,
class _Alloc>
2928 operator>(
const rope<_CharT, _Alloc>& __x,
2929 const rope<_CharT, _Alloc>& __y)
2930 {
return __y < __x; }
2932 template <
class _CharT,
class _Alloc>
2935 const rope<_CharT, _Alloc>& __y)
2936 {
return !(__y < __x); }
2938 template <
class _CharT,
class _Alloc>
2941 const rope<_CharT, _Alloc>& __y)
2942 {
return !(__x < __y); }
2944 template <
class _CharT,
class _Alloc>
2946 operator!=(
const _Rope_char_ptr_proxy<_CharT, _Alloc>& __x,
2947 const _Rope_char_ptr_proxy<_CharT, _Alloc>& __y)
2948 {
return !(__x == __y); }
2950 template<
class _CharT,
class _Traits,
class _Alloc>
2953 const rope<_CharT, _Alloc>& __r);
2955 typedef rope<char> crope;
2956 typedef rope<wchar_t> wrope;
2958 inline crope::reference
2959 __mutable_reference_at(crope& __c, std::size_t __i)
2960 {
return __c.mutable_reference_at(__i); }
2962 inline wrope::reference
2963 __mutable_reference_at(wrope& __c, std::size_t __i)
2964 {
return __c.mutable_reference_at(__i); }
2966 template <
class _CharT,
class _Alloc>
2968 swap(rope<_CharT, _Alloc>& __x, rope<_CharT, _Alloc>& __y)
2971_GLIBCXX_END_NAMESPACE_VERSION
2975namespace std _GLIBCXX_VISIBILITY(default)
2977_GLIBCXX_BEGIN_NAMESPACE_VERSION
2987 size_t __size = __str.size();
2990 return 13 * __str[0] + 5 * __str[__size - 1] + __size;
3001 size_t __size = __str.size();
3004 return 13 * __str[0] + 5 * __str[__size - 1] + __size;
3009_GLIBCXX_END_NAMESPACE_VERSION
std::pair< _InputIter, _ForwardIter > uninitialized_copy_n(_InputIter __first, _Size __count, _ForwardIter __result)
Copies the range [first,last) into result.
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator<(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
ISO C++ entities toplevel namespace is std.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
basic_ostream< _CharT, _Traits > & flush(basic_ostream< _CharT, _Traits > &__os)
Flushes the output stream.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr void _Destroy(_ForwardIterator __first, _ForwardIterator __last)
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
GNU extensions for public use.
Template class basic_ostream.
The standard allocator, as per C++03 [20.4.1].
Uniform interface to C++98 and C++11 allocators.