Debian Codegraph @

gcc/testsuite/g++.dg/torture/pr47333.C

raw
1 /* { dg-require-effective-target sync_int_long } */
2 // { dg-additional-options "-Wno-template-body" }
3
4 namespace std
5 {
6 typedef unsigned int size_t;
7 typedef int ptrdiff_t;
8
9 }
10
11 namespace std __attribute__ ((__visibility__ ("default"))) {
12
13 template<typename _Alloc>
14 class allocator;
15
16 template<class _CharT>
17 struct char_traits;
18
19 template<typename _CharT, typename _Traits = char_traits<_CharT>,
20 typename _Alloc = allocator<_CharT> >
21 class basic_string;
22
23 template<> struct char_traits<char>;
24
25 typedef basic_string<char> string;
26
27 template<> struct char_traits<wchar_t>;
28
29 typedef basic_string<wchar_t> wstring;
30 }
31
32 namespace std __attribute__ ((__visibility__ ("default"))) {
33 void
34 __throw_bad_alloc(void) __attribute__((__noreturn__));
35 }
36
37 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
38 template<typename _Iterator, typename _Container>
39 class __normal_iterator;
40 }
41
42 namespace std __attribute__ ((__visibility__ ("default"))) {
43
44 template<typename _Tp>
45 inline _Tp*
46 __addressof(_Tp& __r)
47 {
48 return reinterpret_cast<_Tp*>
49 (&const_cast<char&>(reinterpret_cast<const volatile char&>(__r)));
50 }
51 }
52
53 namespace std __attribute__ ((__visibility__ ("default"))) {
54 template<class _T1, class _T2>
55 struct pair
56 {
57 typedef _T1 first_type;
58 typedef _T2 second_type;
59
60 _T1 first;
61 _T2 second;
62
63 pair()
64 : first(), second() { }
65
66 pair(const _T1& __a, const _T2& __b)
67 : first(__a), second(__b) { }
68 };
69 }
70
71 namespace std __attribute__ ((__visibility__ ("default"))) {
72 struct input_iterator_tag { };
73
74 struct output_iterator_tag { };
75
76 struct forward_iterator_tag : public input_iterator_tag { };
77
78 struct bidirectional_iterator_tag : public forward_iterator_tag { };
79
80 struct random_access_iterator_tag : public bidirectional_iterator_tag { };
81 template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t,
82 typename _Pointer = _Tp*, typename _Reference = _Tp&>
83 struct iterator
84 {
85 typedef _Category iterator_category;
86 typedef _Tp value_type;
87 typedef _Distance difference_type;
88 typedef _Pointer pointer;
89 typedef _Reference reference;
90 };
91
92 template<typename _Iterator>
93 struct iterator_traits
94 {
95 typedef typename _Iterator::iterator_category iterator_category;
96 typedef typename _Iterator::value_type value_type;
97 typedef typename _Iterator::difference_type difference_type;
98 typedef typename _Iterator::pointer pointer;
99 typedef typename _Iterator::reference reference;
100 };
101 }
102
103 namespace std __attribute__ ((__visibility__ ("default"))) {
104 template<typename _Iterator>
105 class reverse_iterator
106 : public iterator<typename iterator_traits<_Iterator>::iterator_category,
107 typename iterator_traits<_Iterator>::value_type,
108 typename iterator_traits<_Iterator>::difference_type,
109 typename iterator_traits<_Iterator>::pointer,
110 typename iterator_traits<_Iterator>::reference>
111 {
112 protected:
113 _Iterator current;
114 typedef iterator_traits<_Iterator> __traits_type;
115 };
116 }
117
118 struct _IO_FILE;
119
120 typedef struct _IO_FILE FILE;
121
122 typedef struct _IO_FILE __FILE;
123
124 typedef __builtin_va_list __gnuc_va_list;
125
126 typedef unsigned int size_t;
127 typedef unsigned int wint_t;
128
129 typedef struct
130 {
131 int __count;
132 union
133 {
134 unsigned int __wch;
135 char __wchb[4];
136 } __value;
137 } __mbstate_t;
138
139
140 typedef __mbstate_t mbstate_t;
141
142 namespace std __attribute__ ((__visibility__ ("default"))) {
143 using ::mbstate_t;
144 }
145
146 namespace std __attribute__ ((__visibility__ ("default"))) {
147 typedef long long streamoff;
148
149 typedef ptrdiff_t streamsize;
150 template<typename _StateT>
151 class fpos
152 {
153 private:
154 streamoff _M_off;
155 _StateT _M_state;
156
157 public:
158
159 fpos()
160 : _M_off(0), _M_state() { }
161 fpos(streamoff __off)
162 : _M_off(__off), _M_state() { }
163
164 operator streamoff() const { return _M_off; }
165
166 };
167
168 typedef fpos<mbstate_t> streampos;
169
170 typedef fpos<mbstate_t> wstreampos;
171 }
172
173 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
174 template<typename _CharT>
175 struct _Char_types
176 {
177 typedef unsigned long int_type;
178 typedef std::streampos pos_type;
179 typedef std::streamoff off_type;
180 typedef std::mbstate_t state_type;
181 };
182 template<typename _CharT>
183 struct char_traits
184 {
185 typedef _CharT char_type;
186 typedef typename _Char_types<_CharT>::int_type int_type;
187 typedef typename _Char_types<_CharT>::pos_type pos_type;
188 typedef typename _Char_types<_CharT>::off_type off_type;
189 typedef typename _Char_types<_CharT>::state_type state_type;
190
191 static const char_type*
192 find(const char_type* __s, std::size_t __n, const char_type& __a);
193 };
194 }
195
196 namespace std __attribute__ ((__visibility__ ("default"))) {
197 template<class _CharT>
198 struct char_traits : public __gnu_cxx::char_traits<_CharT>
199 { };
200
201 template<>
202 struct char_traits<char>
203 {
204 typedef char char_type;
205 typedef int int_type;
206 typedef streampos pos_type;
207 typedef streamoff off_type;
208 typedef mbstate_t state_type;
209
210 static const char_type*
211 find(const char_type* __s, size_t __n, const char_type& __a)
212 { return static_cast<const char_type*>(__builtin_memchr(__s, __a, __n)); }
213 };
214 }
215
216 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
217
218 using std::size_t;
219 using std::ptrdiff_t;
220 template<typename _Tp>
221 class new_allocator
222 {
223 public:
224 typedef size_t size_type;
225 typedef ptrdiff_t difference_type;
226 typedef _Tp* pointer;
227 typedef const _Tp* const_pointer;
228 typedef _Tp& reference;
229 typedef const _Tp& const_reference;
230 typedef _Tp value_type;
231
232 new_allocator() throw() { }
233
234 new_allocator(const new_allocator&) throw() { }
235
236 template<typename _Tp1>
237 new_allocator(const new_allocator<_Tp1>&) throw() { }
238
239 ~new_allocator() throw() { }
240
241 pointer
242 allocate(size_type __n, const void* = 0)
243 {
244 if (__n > this->max_size())
245 std::__throw_bad_alloc();
246
247 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
248 }
249 void
250 deallocate(pointer __p, size_type)
251 { ::operator delete(__p); }
252
253 void
254 destroy(pointer __p) { __p->~_Tp(); }
255 };
256 }
257
258 namespace std __attribute__ ((__visibility__ ("default"))) {
259 template<typename _Tp>
260 class allocator;
261
262 template<typename _Tp>
263 class allocator: public __gnu_cxx::new_allocator<_Tp>
264 {
265 public:
266 typedef size_t size_type;
267 typedef ptrdiff_t difference_type;
268 typedef _Tp* pointer;
269 typedef const _Tp* const_pointer;
270 typedef _Tp& reference;
271 typedef const _Tp& const_reference;
272 typedef _Tp value_type;
273
274 template<typename _Tp1>
275 struct rebind
276 { typedef allocator<_Tp1> other; };
277
278 allocator() throw() { }
279
280 allocator(const allocator& __a) throw()
281 : __gnu_cxx::new_allocator<_Tp>(__a) { }
282
283 template<typename _Tp1>
284 allocator(const allocator<_Tp1>&) throw() { }
285
286 ~allocator() throw() { }
287 };
288 }
289
290 namespace std __attribute__ ((__visibility__ ("default"))) {
291 template<typename _Arg, typename _Result>
292 struct unary_function
293 {
294 typedef _Arg argument_type;
295 typedef _Result result_type;
296 };
297
298 template<typename _Arg1, typename _Arg2, typename _Result>
299 struct binary_function
300 {
301 typedef _Arg1 first_argument_type;
302 typedef _Arg2 second_argument_type;
303 typedef _Result result_type;
304 };
305
306 template<typename _Tp>
307 struct less : public binary_function<_Tp, _Tp, bool>
308 {
309 bool
310 operator()(const _Tp& __x, const _Tp& __y) const
311 { return __x < __y; }
312 };
313
314 template<typename _Pair>
315 struct _Select1st : public unary_function<_Pair,
316 typename _Pair::first_type>
317 {
318 typename _Pair::first_type&
319 operator()(_Pair& __x) const
320 { return __x.first; }
321
322 const typename _Pair::first_type&
323 operator()(const _Pair& __x) const
324 { return __x.first; }
325 };
326 }
327
328 extern "C" {
329
330 typedef int __sig_atomic_t;
331
332 typedef struct
333 {
334 unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
335 } __sigset_t;
336 typedef __sigset_t sigset_t;
337 }
338 typedef unsigned long int pthread_t;
339
340 typedef struct __pthread_internal_slist
341 {
342 struct __pthread_internal_slist *__next;
343 } __pthread_slist_t;
344
345 typedef union
346 {
347 struct __pthread_mutex_s
348 {
349 int __lock;
350 unsigned int __count;
351 int __owner;
352 int __kind;
353
354 unsigned int __nusers;
355 __extension__ union
356 {
357 int __spins;
358 __pthread_slist_t __list;
359 };
360
361 } __data;
362 char __size[24];
363 long int __align;
364 } pthread_mutex_t;
365
366 typedef unsigned int pthread_key_t;
367
368 typedef int pthread_once_t;
369
370 extern int pthread_once (pthread_once_t *__once_control,
371 void (*__init_routine) (void)) __attribute__ ((__nonnull__ (1, 2)));
372
373 extern int pthread_mutex_lock (pthread_mutex_t *__mutex)
374 throw () __attribute__ ((__nonnull__ (1)));
375
376 extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
377 throw () __attribute__ ((__nonnull__ (1)));
378
379 typedef pthread_t __gthread_t;
380 typedef pthread_key_t __gthread_key_t;
381 typedef pthread_once_t __gthread_once_t;
382 typedef pthread_mutex_t __gthread_mutex_t;
383
384 static __typeof(pthread_once) __gthrw_pthread_once __attribute__ ((__weakref__("pthread_once")));
385
386 static __typeof(pthread_mutex_lock) __gthrw_pthread_mutex_lock __attribute__ ((__weakref__("pthread_mutex_lock")));
387
388 static __typeof(pthread_mutex_unlock) __gthrw_pthread_mutex_unlock __attribute__ ((__weakref__("pthread_mutex_unlock")));
389
390 static volatile int __gthread_active = -1;
391
392 static void
393 __gthread_trigger (void)
394 {
395 __gthread_active = 1;
396 }
397
398 static inline int
399 __gthread_active_p (void)
400 {
401 static pthread_mutex_t __gthread_active_mutex = { { 0, 0, 0, 0, 0, { 0 } } };
402 static pthread_once_t __gthread_active_once = 0;
403
404 int __gthread_active_latest_value = __gthread_active;
405
406 if (__builtin_expect (__gthread_active_latest_value < 0, 0))
407 {
408 if (__gthrw_pthread_once)
409 {
410 __gthrw_pthread_mutex_lock (&__gthread_active_mutex);
411 __gthrw_pthread_once (&__gthread_active_once, __gthread_trigger);
412 __gthrw_pthread_mutex_unlock (&__gthread_active_mutex);
413 }
414
415 if (__gthread_active < 0)
416 __gthread_active = 0;
417 __gthread_active_latest_value = __gthread_active;
418 }
419
420 return __gthread_active_latest_value != 0;
421 }
422
423 typedef int _Atomic_word;
424
425 namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) {
426
427 static inline _Atomic_word
428 __exchange_and_add(volatile _Atomic_word* __mem, int __val)
429 { return __sync_fetch_and_add(__mem, __val); }
430
431 static inline void
432 __atomic_add(volatile _Atomic_word* __mem, int __val)
433 { __sync_fetch_and_add(__mem, __val); }
434 static inline _Atomic_word
435 __exchange_and_add_single(_Atomic_word* __mem, int __val)
436 {
437 _Atomic_word __result = *__mem;
438 *__mem += __val;
439 return __result;
440 }
441
442 static inline void
443 __atomic_add_single(_Atomic_word* __mem, int __val)
444 { *__mem += __val; }
445
446 static inline _Atomic_word
447 __attribute__ ((__unused__))
448 __exchange_and_add_dispatch(_Atomic_word* __mem, int __val)
449 {
450 if (__gthread_active_p())
451 return __exchange_and_add(__mem, __val);
452 else
453 return __exchange_and_add_single(__mem, __val);
454 }
455
456 static inline void
457 __attribute__ ((__unused__))
458 __atomic_add_dispatch(_Atomic_word* __mem, int __val)
459 {
460 if (__gthread_active_p())
461 __atomic_add(__mem, __val);
462 else
463 __atomic_add_single(__mem, __val);
464 }
465 }
466
467 namespace std __attribute__ ((__visibility__ ("default"))) {
468 template<typename _CharT, typename _Traits, typename _Alloc>
469 class basic_string
470 {
471 typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;
472
473 public:
474 typedef _Traits traits_type;
475 typedef typename _Traits::char_type value_type;
476 typedef _Alloc allocator_type;
477 typedef typename _CharT_alloc_type::size_type size_type;
478 typedef typename _CharT_alloc_type::difference_type difference_type;
479 typedef typename _CharT_alloc_type::reference reference;
480 typedef typename _CharT_alloc_type::const_reference const_reference;
481 typedef typename _CharT_alloc_type::pointer pointer;
482 typedef typename _CharT_alloc_type::const_pointer const_pointer;
483 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
484 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
485 const_iterator;
486 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
487 typedef std::reverse_iterator<iterator> reverse_iterator;
488
489 private:
490 struct _Rep_base
491 {
492 size_type _M_length;
493 size_type _M_capacity;
494 _Atomic_word _M_refcount;
495 };
496
497 struct _Rep : _Rep_base
498 {
499
500 typedef typename _Alloc::template rebind<char>::other _Raw_bytes_alloc;
501 static const size_type _S_max_size;
502 static const _CharT _S_terminal;
503
504 static size_type _S_empty_rep_storage[];
505
506 static _Rep&
507 _S_empty_rep()
508 {
509 void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage);
510 return *reinterpret_cast<_Rep*>(__p);
511 }
512
513 _CharT*
514 _M_refdata() throw()
515 { return reinterpret_cast<_CharT*>(this + 1); }
516
517 void
518 _M_dispose(const _Alloc& __a)
519 {
520 if (__builtin_expect(this != &_S_empty_rep(), false))
521 {
522 ;
523 if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount,
524 -1) <= 0)
525 {
526 ;
527 _M_destroy(__a);
528 }
529 }
530 }
531
532 void
533 _M_destroy(const _Alloc&) throw();
534
535 _CharT*
536 _M_refcopy() throw()
537 {
538 if (__builtin_expect(this != &_S_empty_rep(), false))
539 __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1);
540 return _M_refdata();
541 }
542 };
543
544 struct _Alloc_hider : _Alloc
545 {
546 _Alloc_hider(_CharT* __dat, const _Alloc& __a)
547 : _Alloc(__a), _M_p(__dat) { }
548
549 _CharT* _M_p;
550 };
551
552 private:
553
554 mutable _Alloc_hider _M_dataplus;
555
556 _CharT*
557 _M_data() const
558 { return _M_dataplus._M_p; }
559
560 _Rep*
561 _M_rep() const
562 { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); }
563
564 void
565 _M_leak_hard();
566
567 public:
568
569 ~basic_string()
570 { _M_rep()->_M_dispose(this->get_allocator()); }
571
572 public:
573
574 allocator_type
575 get_allocator() const
576 { return _M_dataplus; }
577 };
578 }
579
580 namespace std __attribute__ ((__visibility__ ("default"))) {
581 enum _Rb_tree_color { _S_red = false, _S_black = true };
582
583 struct _Rb_tree_node_base
584 {
585 typedef _Rb_tree_node_base* _Base_ptr;
586 typedef const _Rb_tree_node_base* _Const_Base_ptr;
587
588 _Rb_tree_color _M_color;
589 _Base_ptr _M_parent;
590 _Base_ptr _M_left;
591 _Base_ptr _M_right;
592
593 static _Base_ptr
594 _S_minimum(_Base_ptr __x)
595 {
596 while (__x->_M_left != 0) __x = __x->_M_left;
597 return __x;
598 }
599
600 static _Const_Base_ptr
601 _S_minimum(_Const_Base_ptr __x)
602 {
603 while (__x->_M_left != 0) __x = __x->_M_left;
604 return __x;
605 }
606
607 static _Base_ptr
608 _S_maximum(_Base_ptr __x)
609 {
610 while (__x->_M_right != 0) __x = __x->_M_right;
611 return __x;
612 }
613
614 static _Const_Base_ptr
615 _S_maximum(_Const_Base_ptr __x)
616 {
617 while (__x->_M_right != 0) __x = __x->_M_right;
618 return __x;
619 }
620 };
621
622 template<typename _Val>
623 struct _Rb_tree_node : public _Rb_tree_node_base
624 {
625 typedef _Rb_tree_node<_Val>* _Link_type;
626 _Val _M_value_field;
627 };
628
629 __attribute__ ((__pure__)) _Rb_tree_node_base*
630 _Rb_tree_increment(_Rb_tree_node_base* __x) throw ();
631
632 __attribute__ ((__pure__)) const _Rb_tree_node_base*
633 _Rb_tree_increment(const _Rb_tree_node_base* __x) throw ();
634
635 __attribute__ ((__pure__)) _Rb_tree_node_base*
636 _Rb_tree_decrement(_Rb_tree_node_base* __x) throw ();
637
638 __attribute__ ((__pure__)) const _Rb_tree_node_base*
639 _Rb_tree_decrement(const _Rb_tree_node_base* __x) throw ();
640
641 template<typename _Tp>
642 struct _Rb_tree_iterator
643 {
644 typedef _Tp value_type;
645 typedef _Tp& reference;
646 typedef _Tp* pointer;
647
648 typedef bidirectional_iterator_tag iterator_category;
649 typedef ptrdiff_t difference_type;
650
651 typedef _Rb_tree_iterator<_Tp> _Self;
652 typedef _Rb_tree_node_base::_Base_ptr _Base_ptr;
653 typedef _Rb_tree_node<_Tp>* _Link_type;
654
655 _Rb_tree_iterator()
656 : _M_node() { }
657
658 explicit
659 _Rb_tree_iterator(_Link_type __x)
660 : _M_node(__x) { }
661
662 bool
663 operator==(const _Self& __x) const
664 { return _M_node == __x._M_node; }
665
666 bool
667 operator!=(const _Self& __x) const
668 { return _M_node != __x._M_node; }
669
670 _Base_ptr _M_node;
671 };
672
673 template<typename _Tp>
674 struct _Rb_tree_const_iterator
675 {
676 typedef _Tp value_type;
677 typedef const _Tp& reference;
678 typedef const _Tp* pointer;
679
680 typedef _Rb_tree_iterator<_Tp> iterator;
681
682 typedef bidirectional_iterator_tag iterator_category;
683 typedef ptrdiff_t difference_type;
684
685 typedef _Rb_tree_const_iterator<_Tp> _Self;
686 typedef _Rb_tree_node_base::_Const_Base_ptr _Base_ptr;
687 typedef const _Rb_tree_node<_Tp>* _Link_type;
688
689 _Rb_tree_const_iterator()
690 : _M_node() { }
691
692 explicit
693 _Rb_tree_const_iterator(_Link_type __x)
694 : _M_node(__x) { }
695
696 _Rb_tree_const_iterator(const iterator& __it)
697 : _M_node(__it._M_node) { }
698
699 pointer
700 operator->() const
701 { return std::__addressof(static_cast<_Link_type>
702 (_M_node)->_M_value_field); }
703
704 bool
705 operator==(const _Self& __x) const
706 { return _M_node == __x._M_node; }
707
708 bool
709 operator!=(const _Self& __x) const
710 { return _M_node != __x._M_node; }
711
712 _Base_ptr _M_node;
713 };
714
715 template<typename _Key, typename _Val, typename _KeyOfValue,
716 typename _Compare, typename _Alloc = allocator<_Val> >
717 class _Rb_tree
718 {
719 typedef typename _Alloc::template rebind<_Rb_tree_node<_Val> >::other
720 _Node_allocator;
721
722 protected:
723 typedef _Rb_tree_node_base* _Base_ptr;
724 typedef const _Rb_tree_node_base* _Const_Base_ptr;
725
726 public:
727 typedef _Key key_type;
728 typedef _Val value_type;
729 typedef value_type* pointer;
730 typedef const value_type* const_pointer;
731 typedef value_type& reference;
732 typedef const value_type& const_reference;
733 typedef _Rb_tree_node<_Val>* _Link_type;
734 typedef const _Rb_tree_node<_Val>* _Const_Link_type;
735 typedef size_t size_type;
736 typedef ptrdiff_t difference_type;
737 typedef _Alloc allocator_type;
738
739 const _Node_allocator&
740 _M_get_Node_allocator() const
741 { return *static_cast<const _Node_allocator*>(&this->_M_impl); }
742
743 allocator_type
744 get_allocator() const
745 { return allocator_type(_M_get_Node_allocator()); }
746
747 protected:
748 void
749 _M_put_node(_Link_type __p)
750 { _M_impl._Node_allocator::deallocate(__p, 1); }
751
752 void
753 _M_destroy_node(_Link_type __p)
754 {
755 get_allocator().destroy(std::__addressof(__p->_M_value_field));
756 _M_put_node(__p);
757 }
758
759 protected:
760 template<typename _Key_compare,
761 bool _Is_pod_comparator = __is_pod(_Key_compare)>
762 struct _Rb_tree_impl : public _Node_allocator
763 {
764 _Key_compare _M_key_compare;
765 _Rb_tree_node_base _M_header;
766 size_type _M_node_count;
767
768 private:
769 void
770 _M_initialize()
771 {
772 this->_M_header._M_color = _S_red;
773 this->_M_header._M_parent = 0;
774 this->_M_header._M_left = &this->_M_header;
775 this->_M_header._M_right = &this->_M_header;
776 }
777 };
778
779 _Rb_tree_impl<_Compare> _M_impl;
780
781 protected:
782
783 _Link_type
784 _M_begin()
785 { return static_cast<_Link_type>(this->_M_impl._M_header._M_parent); }
786
787 _Link_type
788 _M_end()
789 { return static_cast<_Link_type>(&this->_M_impl._M_header); }
790
791 static _Link_type
792 _S_left(_Base_ptr __x)
793 { return static_cast<_Link_type>(__x->_M_left); }
794
795 static _Link_type
796 _S_right(_Base_ptr __x)
797 { return static_cast<_Link_type>(__x->_M_right); }
798
799 static const_reference
800 _S_value(_Const_Base_ptr __x)
801 { return static_cast<_Const_Link_type>(__x)->_M_value_field; }
802
803 static const _Key&
804 _S_key(_Const_Base_ptr __x)
805 { return _KeyOfValue()(_S_value(__x)); }
806
807 public:
808 typedef _Rb_tree_iterator<value_type> iterator;
809 typedef _Rb_tree_const_iterator<value_type> const_iterator;
810
811 private:
812
813 void
814 _M_erase(_Link_type __x);
815
816 iterator
817 _M_lower_bound(_Link_type __x, _Link_type __y,
818 const _Key& __k);
819
820 const_iterator
821 _M_lower_bound(_Const_Link_type __x, _Const_Link_type __y,
822 const _Key& __k) const;
823
824 public:
825
826 ~_Rb_tree()
827 { _M_erase(_M_begin()); }
828
829 iterator
830 end()
831 { return iterator(static_cast<_Link_type>(&this->_M_impl._M_header)); }
832
833 const_iterator
834 end() const
835 {
836 return const_iterator(static_cast<_Const_Link_type>
837 (&this->_M_impl._M_header));
838 }
839
840 public:
841 iterator
842 find(const key_type& __k);
843 };
844
845 template<typename _Key, typename _Val, typename _KeyOfValue,
846 typename _Compare, typename _Alloc>
847 void
848 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
849 _M_erase(_Link_type __x)
850 {
851
852 while (__x != 0)
853 {
854 _M_erase(_S_right(__x));
855 _Link_type __y = _S_left(__x);
856 _M_destroy_node(__x);
857 __x = __y;
858 }
859 }
860
861 template<typename _Key, typename _Val, typename _KeyOfValue,
862 typename _Compare, typename _Alloc>
863 typename _Rb_tree<_Key, _Val, _KeyOfValue,
864 _Compare, _Alloc>::iterator
865 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
866 _M_lower_bound(_Link_type __x, _Link_type __y,
867 const _Key& __k)
868 {
869 while (__x != 0)
870 if (!_M_impl._M_key_compare(_S_key(__x), __k))
871 __y = __x, __x = _S_left(__x);
872 else
873 __x = _S_right(__x);
874 return iterator(__y);
875 }
876
877 template<typename _Key, typename _Val, typename _KeyOfValue,
878 typename _Compare, typename _Alloc>
879 typename _Rb_tree<_Key, _Val, _KeyOfValue,
880 _Compare, _Alloc>::iterator
881 _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
882 find(const _Key& __k)
883 {
884 iterator __j = _M_lower_bound(_M_begin(), _M_end(), __k);
885 return (__j == end()
886 || _M_impl._M_key_compare(__k,
887 _S_key(__j._M_node))) ? end() : __j;
888 }
889
890 }
891
892 namespace std {
893 template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>,
894 typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > >
895 class map
896 {
897 public:
898 typedef _Key key_type;
899 typedef _Tp mapped_type;
900 typedef std::pair<const _Key, _Tp> value_type;
901 typedef _Compare key_compare;
902 typedef _Alloc allocator_type;
903
904 private:
905
906 typedef typename _Alloc::template rebind<value_type>::other
907 _Pair_alloc_type;
908
909 typedef _Rb_tree<key_type, value_type, _Select1st<value_type>,
910 key_compare, _Pair_alloc_type> _Rep_type;
911
912 _Rep_type _M_t;
913
914 public:
915
916 typedef typename _Rep_type::iterator iterator;
917 typedef typename _Rep_type::const_iterator const_iterator;
918
919 map()
920 : _M_t() { }
921
922 const_iterator
923 end() const
924 { return _M_t.end(); }
925
926 key_compare
927 key_comp() const
928 { return _M_t.key_comp(); }
929
930 iterator
931 find(const key_type& __x)
932 { return _M_t.find(__x); }
933 };
934 }
935
936 int main ()
937 {
938 typedef std::map<int, std::string> Map;
939 static Map m;
940
941 Map::const_iterator it = m.find(0);
942 if (it != m.end())
943 std::string s = it->second;
944
945 return 0;
946 }
947