gccxml_gem 0.9.3-x86-darwin-11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/Rakefile +84 -0
  2. data/bin/gccxml +0 -0
  3. data/bin/gccxml_cc1plus +0 -0
  4. data/gccxml.rb +57 -0
  5. data/share/doc/gccxml-0.9/Copyright.txt +55 -0
  6. data/share/doc/gccxml-0.9/gccxml.html +168 -0
  7. data/share/doc/gccxml-0.9/gccxml.txt +293 -0
  8. data/share/gccxml-0.9/GCC/2.95/algorithm +76 -0
  9. data/share/gccxml-0.9/GCC/2.95/bitset +17 -0
  10. data/share/gccxml-0.9/GCC/2.95/cctype +24 -0
  11. data/share/gccxml-0.9/GCC/2.95/clocale +14 -0
  12. data/share/gccxml-0.9/GCC/2.95/cmath +33 -0
  13. data/share/gccxml-0.9/GCC/2.95/complex +38 -0
  14. data/share/gccxml-0.9/GCC/2.95/csetjmp +13 -0
  15. data/share/gccxml-0.9/GCC/2.95/csignal +14 -0
  16. data/share/gccxml-0.9/GCC/2.95/cstdarg +12 -0
  17. data/share/gccxml-0.9/GCC/2.95/cstddef +13 -0
  18. data/share/gccxml-0.9/GCC/2.95/cstdio +55 -0
  19. data/share/gccxml-0.9/GCC/2.95/cstdlib +66 -0
  20. data/share/gccxml-0.9/GCC/2.95/cstring +34 -0
  21. data/share/gccxml-0.9/GCC/2.95/ctime +24 -0
  22. data/share/gccxml-0.9/GCC/2.95/cwchar +65 -0
  23. data/share/gccxml-0.9/GCC/2.95/cwctype +31 -0
  24. data/share/gccxml-0.9/GCC/2.95/deque +19 -0
  25. data/share/gccxml-0.9/GCC/2.95/exception +20 -0
  26. data/share/gccxml-0.9/GCC/2.95/fstream +23 -0
  27. data/share/gccxml-0.9/GCC/2.95/functional +64 -0
  28. data/share/gccxml-0.9/GCC/2.95/gccxml_bitset +1066 -0
  29. data/share/gccxml-0.9/GCC/2.95/iomanip +20 -0
  30. data/share/gccxml-0.9/GCC/2.95/iosfwd +20 -0
  31. data/share/gccxml-0.9/GCC/2.95/iostream +27 -0
  32. data/share/gccxml-0.9/GCC/2.95/iterator +39 -0
  33. data/share/gccxml-0.9/GCC/2.95/list +19 -0
  34. data/share/gccxml-0.9/GCC/2.95/map +20 -0
  35. data/share/gccxml-0.9/GCC/2.95/memory +21 -0
  36. data/share/gccxml-0.9/GCC/2.95/new +13 -0
  37. data/share/gccxml-0.9/GCC/2.95/numeric +15 -0
  38. data/share/gccxml-0.9/GCC/2.95/pthread.h +16 -0
  39. data/share/gccxml-0.9/GCC/2.95/queue +20 -0
  40. data/share/gccxml-0.9/GCC/2.95/set +20 -0
  41. data/share/gccxml-0.9/GCC/2.95/sstream +24 -0
  42. data/share/gccxml-0.9/GCC/2.95/stack +19 -0
  43. data/share/gccxml-0.9/GCC/2.95/std/bastring.cc +524 -0
  44. data/share/gccxml-0.9/GCC/2.95/std/complext.h +397 -0
  45. data/share/gccxml-0.9/GCC/2.95/std/dcomplex.h +92 -0
  46. data/share/gccxml-0.9/GCC/2.95/std/fcomplex.h +88 -0
  47. data/share/gccxml-0.9/GCC/2.95/std/gslice_array.h +170 -0
  48. data/share/gccxml-0.9/GCC/2.95/std/indirect_array.h +157 -0
  49. data/share/gccxml-0.9/GCC/2.95/std/ldcomplex.h +96 -0
  50. data/share/gccxml-0.9/GCC/2.95/std/mask_array.h +154 -0
  51. data/share/gccxml-0.9/GCC/2.95/std/slice_array.h +156 -0
  52. data/share/gccxml-0.9/GCC/2.95/std/std_valarray.h +728 -0
  53. data/share/gccxml-0.9/GCC/2.95/std/straits.h +162 -0
  54. data/share/gccxml-0.9/GCC/2.95/std/valarray_meta.h +1035 -0
  55. data/share/gccxml-0.9/GCC/2.95/stdexcept +17 -0
  56. data/share/gccxml-0.9/GCC/2.95/stl_alloc.h +1057 -0
  57. data/share/gccxml-0.9/GCC/2.95/stl_bvector.h +836 -0
  58. data/share/gccxml-0.9/GCC/2.95/stl_deque.h +1699 -0
  59. data/share/gccxml-0.9/GCC/2.95/stl_list.h +843 -0
  60. data/share/gccxml-0.9/GCC/2.95/stl_tree.h +1331 -0
  61. data/share/gccxml-0.9/GCC/2.95/stl_vector.h +828 -0
  62. data/share/gccxml-0.9/GCC/2.95/string +26 -0
  63. data/share/gccxml-0.9/GCC/2.95/strstream +23 -0
  64. data/share/gccxml-0.9/GCC/2.95/typeinfo +11 -0
  65. data/share/gccxml-0.9/GCC/2.95/utility +25 -0
  66. data/share/gccxml-0.9/GCC/2.95/valarray +52 -0
  67. data/share/gccxml-0.9/GCC/2.95/vector +19 -0
  68. data/share/gccxml-0.9/GCC/2.96/sstream +305 -0
  69. data/share/gccxml-0.9/GCC/3.0/pthread.h +16 -0
  70. data/share/gccxml-0.9/GCC/3.1/pthread.h +16 -0
  71. data/share/gccxml-0.9/GCC/3.2/bits/fstream.tcc +500 -0
  72. data/share/gccxml-0.9/GCC/3.2/bits/gthr-default.h +585 -0
  73. data/share/gccxml-0.9/GCC/3.2/bits/istream.tcc +1207 -0
  74. data/share/gccxml-0.9/GCC/3.2/bits/locale_facets.h +1810 -0
  75. data/share/gccxml-0.9/GCC/3.2/bits/locale_facets.tcc +2397 -0
  76. data/share/gccxml-0.9/GCC/3.2/bits/messages_members.h +108 -0
  77. data/share/gccxml-0.9/GCC/3.2/bits/ostream.tcc +713 -0
  78. data/share/gccxml-0.9/GCC/3.2/bits/sstream.tcc +241 -0
  79. data/share/gccxml-0.9/GCC/3.2/bits/stl_deque.h +1682 -0
  80. data/share/gccxml-0.9/GCC/3.2/bits/stl_list.h +989 -0
  81. data/share/gccxml-0.9/GCC/3.2/bits/stl_tree.h +1462 -0
  82. data/share/gccxml-0.9/GCC/3.2/bits/stl_vector.h +1085 -0
  83. data/share/gccxml-0.9/GCC/3.2/bits/valarray_meta.h +1063 -0
  84. data/share/gccxml-0.9/GCC/3.2/fstream +579 -0
  85. data/share/gccxml-0.9/GCC/3.2/pthread.h +16 -0
  86. data/share/gccxml-0.9/GCC/3.2/sstream +384 -0
  87. data/share/gccxml-0.9/GCC/3.3/bits/fstream.tcc +530 -0
  88. data/share/gccxml-0.9/GCC/3.3/bits/list.tcc +378 -0
  89. data/share/gccxml-0.9/GCC/3.3/bits/locale_facets.h +2050 -0
  90. data/share/gccxml-0.9/GCC/3.3/bits/messages_members.h +108 -0
  91. data/share/gccxml-0.9/GCC/3.3/bits/sstream.tcc +243 -0
  92. data/share/gccxml-0.9/GCC/3.3/bits/stl_deque.h +1603 -0
  93. data/share/gccxml-0.9/GCC/3.3/bits/stl_list.h +1167 -0
  94. data/share/gccxml-0.9/GCC/3.3/bits/stl_tree.h +1462 -0
  95. data/share/gccxml-0.9/GCC/3.3/bits/stl_vector.h +992 -0
  96. data/share/gccxml-0.9/GCC/3.3/bits/valarray_meta.h +1135 -0
  97. data/share/gccxml-0.9/GCC/3.3/fstream +842 -0
  98. data/share/gccxml-0.9/GCC/3.3/gccxml_builtins.h +22 -0
  99. data/share/gccxml-0.9/GCC/3.3/sstream +638 -0
  100. data/share/gccxml-0.9/GCC/3.4/bits/gthr-default.h +669 -0
  101. data/share/gccxml-0.9/GCC/3.4/gccxml_builtins.h +91 -0
  102. data/share/gccxml-0.9/GCC/4.0/emmintrin.h +5 -0
  103. data/share/gccxml-0.9/GCC/4.0/gccxml_apple_emmintrin.h +1037 -0
  104. data/share/gccxml-0.9/GCC/4.0/gccxml_apple_mmintrin.h +669 -0
  105. data/share/gccxml-0.9/GCC/4.0/gccxml_apple_xmmintrin.h +870 -0
  106. data/share/gccxml-0.9/GCC/4.0/gccxml_builtins.h +128 -0
  107. data/share/gccxml-0.9/GCC/4.0/gccxml_gnu_emmintrin.h +977 -0
  108. data/share/gccxml-0.9/GCC/4.0/gccxml_gnu_mmintrin.h +636 -0
  109. data/share/gccxml-0.9/GCC/4.0/gccxml_gnu_xmmintrin.h +833 -0
  110. data/share/gccxml-0.9/GCC/4.0/mmintrin.h +5 -0
  111. data/share/gccxml-0.9/GCC/4.0/xmmintrin.h +5 -0
  112. data/share/gccxml-0.9/GCC/4.1/bits/gthr-default.h +622 -0
  113. data/share/gccxml-0.9/GCC/4.1/emmintrin.h +5 -0
  114. data/share/gccxml-0.9/GCC/4.1/gccxml_apple_emmintrin.h +1509 -0
  115. data/share/gccxml-0.9/GCC/4.1/gccxml_apple_mmintrin.h +942 -0
  116. data/share/gccxml-0.9/GCC/4.1/gccxml_apple_xmmintrin.h +1192 -0
  117. data/share/gccxml-0.9/GCC/4.1/gccxml_builtins.h +131 -0
  118. data/share/gccxml-0.9/GCC/4.1/gccxml_gnu_emmintrin.h +1004 -0
  119. data/share/gccxml-0.9/GCC/4.1/gccxml_gnu_mmintrin.h +637 -0
  120. data/share/gccxml-0.9/GCC/4.1/gccxml_gnu_xmmintrin.h +834 -0
  121. data/share/gccxml-0.9/GCC/4.1/mmintrin.h +5 -0
  122. data/share/gccxml-0.9/GCC/4.1/xmmintrin.h +5 -0
  123. data/share/gccxml-0.9/GCC/4.2/emmintrin.h +5 -0
  124. data/share/gccxml-0.9/GCC/4.2/gccxml_apple_emmintrin.h +1509 -0
  125. data/share/gccxml-0.9/GCC/4.2/gccxml_apple_mmintrin.h +942 -0
  126. data/share/gccxml-0.9/GCC/4.2/gccxml_apple_xmmintrin.h +1192 -0
  127. data/share/gccxml-0.9/GCC/4.2/gccxml_builtins.h +131 -0
  128. data/share/gccxml-0.9/GCC/4.2/gccxml_gnu_emmintrin.h +1013 -0
  129. data/share/gccxml-0.9/GCC/4.2/gccxml_gnu_mmintrin.h +663 -0
  130. data/share/gccxml-0.9/GCC/4.2/gccxml_gnu_xmmintrin.h +860 -0
  131. data/share/gccxml-0.9/GCC/4.2/mmintrin.h +5 -0
  132. data/share/gccxml-0.9/GCC/4.2/xmmintrin.h +5 -0
  133. data/share/gccxml-0.9/GCC/4.3/emmintrin.h +1043 -0
  134. data/share/gccxml-0.9/GCC/4.3/gccxml_builtins.h +183 -0
  135. data/share/gccxml-0.9/GCC/4.3/mmintrin.h +663 -0
  136. data/share/gccxml-0.9/GCC/4.3/xmmintrin.h +867 -0
  137. data/share/gccxml-0.9/GCC/4.4/bits/c++config.h +1431 -0
  138. data/share/gccxml-0.9/GCC/4.4/emmintrin.h +1041 -0
  139. data/share/gccxml-0.9/GCC/4.4/gccxml_builtins.h +153 -0
  140. data/share/gccxml-0.9/GCC/4.4/mmintrin.h +662 -0
  141. data/share/gccxml-0.9/GCC/4.4/xmmintrin.h +864 -0
  142. data/share/gccxml-0.9/GCC/4.5/gccxml_builtins.h +154 -0
  143. data/share/gccxml-0.9/GCC/4.5/iomanip +349 -0
  144. data/share/gccxml-0.9/GCC/COPYING.RUNTIME +73 -0
  145. data/share/gccxml-0.9/GCC/COPYING3 +674 -0
  146. data/share/gccxml-0.9/IBM/8.0/adapt_headers.sh +34 -0
  147. data/share/gccxml-0.9/IBM/8.0/stdlib.h.patch +27 -0
  148. data/share/gccxml-0.9/IBM/8.0/xstring.patch +19 -0
  149. data/share/gccxml-0.9/IBM/README +8 -0
  150. data/share/gccxml-0.9/IBM/find_flags +51 -0
  151. data/share/gccxml-0.9/IBM/find_flags_common +48 -0
  152. data/share/gccxml-0.9/Intel/find_flags +56 -0
  153. data/share/gccxml-0.9/Intel/pthread.h +16 -0
  154. data/share/gccxml-0.9/MIPSpro/7.3/exception +9 -0
  155. data/share/gccxml-0.9/MIPSpro/7.3/gccxml_mpro_internals.h +21 -0
  156. data/share/gccxml-0.9/MIPSpro/7.3/iomanip +161 -0
  157. data/share/gccxml-0.9/MIPSpro/7.3/ostream +9 -0
  158. data/share/gccxml-0.9/MIPSpro/7.3/stddef.h +9 -0
  159. data/share/gccxml-0.9/MIPSpro/7.3/stl_config.h +9 -0
  160. data/share/gccxml-0.9/MIPSpro/7.3/stl_locale.h +17 -0
  161. data/share/gccxml-0.9/MIPSpro/7.3/stl_monetary.h +14 -0
  162. data/share/gccxml-0.9/MIPSpro/7.3/stl_numeric_facets.h +13 -0
  163. data/share/gccxml-0.9/MIPSpro/7.3/stl_threads.h +11 -0
  164. data/share/gccxml-0.9/MIPSpro/7.3/string +18 -0
  165. data/share/gccxml-0.9/MIPSpro/find_flags +70 -0
  166. data/share/gccxml-0.9/MIPSpro/mipspro_defs.cxx +63 -0
  167. data/share/gccxml-0.9/Sun/5.8/Cstd.patch +156 -0
  168. data/share/gccxml-0.9/Sun/5.8/adapt_headers.sh +32 -0
  169. data/share/gccxml-0.9/Sun/5.8/std-5.10.patch +22 -0
  170. data/share/gccxml-0.9/Sun/README +8 -0
  171. data/share/gccxml-0.9/Sun/find_flags +51 -0
  172. data/share/gccxml-0.9/Sun/find_flags_common +42 -0
  173. data/share/gccxml-0.9/gccxml_config +2 -0
  174. data/share/gccxml-0.9/gccxml_identify_compiler.cc +13 -0
  175. data/share/man/man1/gccxml.1 +246 -0
  176. metadata +243 -0
@@ -0,0 +1,1699 @@
1
+ /*
2
+ *
3
+ * Copyright (c) 1994
4
+ * Hewlett-Packard Company
5
+ *
6
+ * Permission to use, copy, modify, distribute and sell this software
7
+ * and its documentation for any purpose is hereby granted without fee,
8
+ * provided that the above copyright notice appear in all copies and
9
+ * that both that copyright notice and this permission notice appear
10
+ * in supporting documentation. Hewlett-Packard Company makes no
11
+ * representations about the suitability of this software for any
12
+ * purpose. It is provided "as is" without express or implied warranty.
13
+ *
14
+ *
15
+ * Copyright (c) 1997
16
+ * Silicon Graphics Computer Systems, Inc.
17
+ *
18
+ * Permission to use, copy, modify, distribute and sell this software
19
+ * and its documentation for any purpose is hereby granted without fee,
20
+ * provided that the above copyright notice appear in all copies and
21
+ * that both that copyright notice and this permission notice appear
22
+ * in supporting documentation. Silicon Graphics makes no
23
+ * representations about the suitability of this software for any
24
+ * purpose. It is provided "as is" without express or implied warranty.
25
+ */
26
+
27
+ /* NOTE: This is an internal header file, included by other STL headers.
28
+ * You should not attempt to use it directly.
29
+ */
30
+
31
+ #ifndef __SGI_STL_INTERNAL_DEQUE_H
32
+ #define __SGI_STL_INTERNAL_DEQUE_H
33
+
34
+ /* Class invariants:
35
+ * For any nonsingular iterator i:
36
+ * i.node is the address of an element in the map array. The
37
+ * contents of i.node is a pointer to the beginning of a node.
38
+ * i.first == *(i.node)
39
+ * i.last == i.first + node_size
40
+ * i.cur is a pointer in the range [i.first, i.last). NOTE:
41
+ * the implication of this is that i.cur is always a dereferenceable
42
+ * pointer, even if i is a past-the-end iterator.
43
+ * Start and Finish are always nonsingular iterators. NOTE: this means
44
+ * that an empty deque must have one node, and that a deque
45
+ * with N elements, where N is the buffer size, must have two nodes.
46
+ * For every node other than start.node and finish.node, every element
47
+ * in the node is an initialized object. If start.node == finish.node,
48
+ * then [start.cur, finish.cur) are initialized objects, and
49
+ * the elements outside that range are uninitialized storage. Otherwise,
50
+ * [start.cur, start.last) and [finish.first, finish.cur) are initialized
51
+ * objects, and [start.first, start.cur) and [finish.cur, finish.last)
52
+ * are uninitialized storage.
53
+ * [map, map + map_size) is a valid, non-empty range.
54
+ * [start.node, finish.node] is a valid range contained within
55
+ * [map, map + map_size).
56
+ * A pointer in the range [map, map + map_size) points to an allocated node
57
+ * if and only if the pointer is in the range [start.node, finish.node].
58
+ */
59
+
60
+
61
+ /*
62
+ * In previous versions of deque, node_size was fixed by the
63
+ * implementation. In this version, however, users can select
64
+ * the node size. Deque has three template parameters; the third,
65
+ * a number of type size_t, is the number of elements per node.
66
+ * If the third template parameter is 0 (which is the default),
67
+ * then deque will use a default node size.
68
+ *
69
+ * The only reason for using an alternate node size is if your application
70
+ * requires a different performance tradeoff than the default. If,
71
+ * for example, your program contains many deques each of which contains
72
+ * only a few elements, then you might want to save memory (possibly
73
+ * by sacrificing some speed) by using smaller nodes.
74
+ *
75
+ * Unfortunately, some compilers have trouble with non-type template
76
+ * parameters; stl_config.h defines __STL_NON_TYPE_TMPL_PARAM_BUG if
77
+ * that is the case. If your compiler is one of them, then you will
78
+ * not be able to use alternate node sizes; you will have to use the
79
+ * default value.
80
+ */
81
+
82
+ __STL_BEGIN_NAMESPACE
83
+
84
+ #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
85
+ #pragma set woff 1174
86
+ #pragma set woff 1375
87
+ #endif
88
+
89
+ // Note: this function is simply a kludge to work around several compilers'
90
+ // bugs in handling constant expressions.
91
+ inline size_t
92
+ __deque_buf_size(size_t __n, size_t __size)
93
+ {
94
+ return __n != 0 ? __n : (__size < 512 ? size_t(512 / __size) : size_t(1));
95
+ }
96
+
97
+ #ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
98
+ template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
99
+ struct _Deque_iterator {
100
+ typedef _Deque_iterator<_Tp,_Tp&,_Tp*,__bufsiz> iterator;
101
+ typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*,__bufsiz> const_iterator;
102
+ static size_t
103
+ _S_buffer_size() { return __deque_buf_size(__bufsiz, sizeof(_Tp)); }
104
+ #else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
105
+ template <class _Tp, class _Ref, class _Ptr>
106
+ struct _Deque_iterator {
107
+ typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
108
+ typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
109
+ static size_t
110
+ _S_buffer_size() { return __deque_buf_size(0, sizeof(_Tp)); }
111
+ #endif
112
+
113
+ typedef random_access_iterator_tag iterator_category;
114
+ typedef _Tp value_type;
115
+ typedef _Ptr pointer;
116
+ typedef _Ref reference;
117
+ typedef size_t size_type;
118
+ typedef ptrdiff_t difference_type;
119
+ typedef _Tp** _Map_pointer;
120
+
121
+ typedef _Deque_iterator _Self;
122
+
123
+ _Tp* _M_cur;
124
+ _Tp* _M_first;
125
+ _Tp* _M_last;
126
+ _Map_pointer _M_node;
127
+
128
+ _Deque_iterator(_Tp* __x, _Map_pointer __y)
129
+ : _M_cur(__x), _M_first(*__y),
130
+ _M_last(*__y + _S_buffer_size()), _M_node(__y) {}
131
+ _Deque_iterator() : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) {}
132
+ _Deque_iterator(const iterator& __x)
133
+ : _M_cur(__x._M_cur), _M_first(__x._M_first),
134
+ _M_last(__x._M_last), _M_node(__x._M_node) {}
135
+
136
+ reference operator*() const { return *_M_cur; }
137
+ #ifndef __SGI_STL_NO_ARROW_OPERATOR
138
+ pointer operator->() const { return _M_cur; }
139
+ #endif /* __SGI_STL_NO_ARROW_OPERATOR */
140
+
141
+ difference_type operator-(const _Self& __x) const {
142
+ return difference_type(_S_buffer_size()) * (_M_node - __x._M_node - 1) +
143
+ (_M_cur - _M_first) + (__x._M_last - __x._M_cur);
144
+ }
145
+
146
+ _Self& operator++() {
147
+ ++_M_cur;
148
+ if (_M_cur == _M_last) {
149
+ _M_set_node(_M_node + 1);
150
+ _M_cur = _M_first;
151
+ }
152
+ return *this;
153
+ }
154
+ _Self operator++(int) {
155
+ _Self __tmp = *this;
156
+ ++*this;
157
+ return __tmp;
158
+ }
159
+
160
+ _Self& operator--() {
161
+ if (_M_cur == _M_first) {
162
+ _M_set_node(_M_node - 1);
163
+ _M_cur = _M_last;
164
+ }
165
+ --_M_cur;
166
+ return *this;
167
+ }
168
+ _Self operator--(int) {
169
+ _Self __tmp = *this;
170
+ --*this;
171
+ return __tmp;
172
+ }
173
+
174
+ _Self& operator+=(difference_type __n)
175
+ {
176
+ difference_type __offset = __n + (_M_cur - _M_first);
177
+ if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
178
+ _M_cur += __n;
179
+ else {
180
+ difference_type __node_offset =
181
+ __offset > 0 ? __offset / difference_type(_S_buffer_size())
182
+ : -difference_type((-__offset - 1) / _S_buffer_size()) - 1;
183
+ _M_set_node(_M_node + __node_offset);
184
+ _M_cur = _M_first +
185
+ (__offset - __node_offset * difference_type(_S_buffer_size()));
186
+ }
187
+ return *this;
188
+ }
189
+
190
+ _Self operator+(difference_type __n) const
191
+ {
192
+ _Self __tmp = *this;
193
+ return __tmp += __n;
194
+ }
195
+
196
+ _Self& operator-=(difference_type __n) { return *this += -__n; }
197
+
198
+ _Self operator-(difference_type __n) const {
199
+ _Self __tmp = *this;
200
+ return __tmp -= __n;
201
+ }
202
+
203
+ reference operator[](difference_type __n) const { return *(*this + __n); }
204
+
205
+ bool operator==(const _Self& __x) const { return _M_cur == __x._M_cur; }
206
+ bool operator!=(const _Self& __x) const { return !(*this == __x); }
207
+ bool operator<(const _Self& __x) const {
208
+ return (_M_node == __x._M_node) ?
209
+ (_M_cur < __x._M_cur) : (_M_node < __x._M_node);
210
+ }
211
+
212
+ void _M_set_node(_Map_pointer __new_node) {
213
+ _M_node = __new_node;
214
+ _M_first = *__new_node;
215
+ _M_last = _M_first + difference_type(_S_buffer_size());
216
+ }
217
+ };
218
+
219
+ #ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
220
+
221
+ #ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
222
+
223
+ template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
224
+ inline random_access_iterator_tag
225
+ iterator_category(const _Deque_iterator<_Tp,_Ref,_Ptr,__bufsiz>&) {
226
+ return random_access_iterator_tag();
227
+ }
228
+
229
+ template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
230
+ inline _Tp*
231
+ value_type(const _Deque_iterator<_Tp,_Ref,_Ptr,__bufsiz>&) {
232
+ return 0;
233
+ }
234
+
235
+ template <class _Tp, class _Ref, class _Ptr, size_t __bufsiz>
236
+ inline ptrdiff_t*
237
+ distance_type(const _Deque_iterator<_Tp,_Ref,_Ptr,__bufsiz>&) {
238
+ return 0;
239
+ }
240
+
241
+ #else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
242
+
243
+ template <class _Tp, class _Ref, class _Ptr>
244
+ inline random_access_iterator_tag
245
+ iterator_category(const _Deque_iterator<_Tp,_Ref,_Ptr>&)
246
+ {
247
+ return random_access_iterator_tag();
248
+ }
249
+
250
+ template <class _Tp, class _Ref, class _Ptr>
251
+ inline _Tp*
252
+ value_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) { return 0; }
253
+
254
+ template <class _Tp, class _Ref, class _Ptr>
255
+ inline ptrdiff_t*
256
+ distance_type(const _Deque_iterator<_Tp,_Ref,_Ptr>&) {
257
+ return 0;
258
+ }
259
+
260
+ #endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
261
+
262
+ #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
263
+
264
+ // Deque base class. It has two purposes. First, its constructor
265
+ // and destructor allocate (but don't initialize) storage. This makes
266
+ // exception safety easier. Second, the base class encapsulates all of
267
+ // the differences between SGI-style allocators and standard-conforming
268
+ // allocators.
269
+
270
+ #ifdef __STL_USE_STD_ALLOCATORS
271
+
272
+ // Base class for ordinary allocators.
273
+ template <class _Tp, class _Alloc, size_t __bufsiz, bool __is_static>
274
+ class _Deque_alloc_base {
275
+ public:
276
+ typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
277
+ allocator_type get_allocator() const { return node_allocator; }
278
+
279
+ _Deque_alloc_base(const allocator_type& __a)
280
+ : node_allocator(__a), map_allocator(__a), _M_map(0), _M_map_size(0)
281
+ {}
282
+
283
+ protected:
284
+ typedef typename _Alloc_traits<_Tp*, _Alloc>::allocator_type
285
+ map_allocator_type;
286
+
287
+ allocator_type node_allocator;
288
+ map_allocator_type map_allocator;
289
+
290
+ _Tp* _M_allocate_node() {
291
+ return node_allocator.allocate(__deque_buf_size(__bufsiz,sizeof(_Tp)));
292
+ }
293
+ void _M_deallocate_node(_Tp* __p) {
294
+ node_allocator.deallocate(__p, __deque_buf_size(__bufsiz,sizeof(_Tp)));
295
+ }
296
+ _Tp** _M_allocate_map(size_t __n)
297
+ { return map_allocator.allocate(__n); }
298
+ void _M_deallocate_map(_Tp** __p, size_t __n)
299
+ { map_allocator.deallocate(__p, __n); }
300
+
301
+ _Tp** _M_map;
302
+ size_t _M_map_size;
303
+ };
304
+
305
+ // Specialization for instanceless allocators.
306
+ template <class _Tp, class _Alloc, size_t __bufsiz>
307
+ class _Deque_alloc_base<_Tp, _Alloc, __bufsiz, true>
308
+ {
309
+ public:
310
+ typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
311
+ allocator_type get_allocator() const { return allocator_type(); }
312
+
313
+ _Deque_alloc_base(const allocator_type&) : _M_map(0), _M_map_size(0) {}
314
+
315
+ protected:
316
+ typedef typename _Alloc_traits<_Tp, _Alloc>::_Alloc_type _Node_alloc_type;
317
+ typedef typename _Alloc_traits<_Tp*, _Alloc>::_Alloc_type _Map_alloc_type;
318
+
319
+ _Tp* _M_allocate_node()
320
+ { return _Node_alloc_type::allocate(__deque_buf_size(__bufsiz,
321
+ sizeof(_Tp))); }
322
+ void _M_deallocate_node(_Tp* __p)
323
+ { _Node_alloc_type::deallocate(__p, __deque_buf_size(__bufsiz,
324
+ sizeof(_Tp))); }
325
+ _Tp** _M_allocate_map(size_t __n)
326
+ { return _Map_alloc_type::allocate(__n); }
327
+ void _M_deallocate_map(_Tp** __p, size_t __n)
328
+ { _Map_alloc_type::deallocate(__p, __n); }
329
+
330
+ _Tp** _M_map;
331
+ size_t _M_map_size;
332
+ };
333
+
334
+ template <class _Tp, class _Alloc, size_t __bufsiz>
335
+ class _Deque_base
336
+ : public _Deque_alloc_base<_Tp,_Alloc,__bufsiz,
337
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
338
+ {
339
+ public:
340
+ typedef _Deque_alloc_base<_Tp,_Alloc,__bufsiz,
341
+ _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
342
+ _Base;
343
+ using _Base::_M_map;
344
+ using _Base::_M_map_size;
345
+ using _Base::_M_allocate_node;
346
+ typedef typename _Base::allocator_type allocator_type;
347
+ typedef _Deque_iterator<_Tp,_Tp&,_Tp*,__bufsiz> iterator;
348
+ typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*, __bufsiz> const_iterator;
349
+
350
+ _Deque_base(const allocator_type& __a, size_t __num_elements)
351
+ : _Base(__a), _M_start(), _M_finish()
352
+ { _M_initialize_map(__num_elements); }
353
+ _Deque_base(const allocator_type& __a)
354
+ : _Base(__a), _M_start(), _M_finish() {}
355
+ ~_Deque_base();
356
+
357
+ protected:
358
+ void _M_initialize_map(size_t);
359
+ void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
360
+ void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
361
+ enum { _S_initial_map_size = 8 };
362
+
363
+ protected:
364
+ iterator _M_start;
365
+ iterator _M_finish;
366
+ };
367
+
368
+ #else /* __STL_USE_STD_ALLOCATORS */
369
+
370
+ template <class _Tp, class _Alloc, size_t __bufsiz>
371
+ class _Deque_base {
372
+ public:
373
+ #ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
374
+ typedef _Deque_iterator<_Tp,_Tp&,_Tp*,__bufsiz> iterator;
375
+ typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*, __bufsiz> const_iterator;
376
+ #else /* __STL_NON_TYPE_TMPL_PARAM_BUG */
377
+ typedef _Deque_iterator<_Tp,_Tp&,_Tp*> iterator;
378
+ typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*> const_iterator;
379
+ #endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
380
+
381
+ typedef _Alloc allocator_type;
382
+ allocator_type get_allocator() const { return allocator_type(); }
383
+
384
+ _Deque_base(const allocator_type&, size_t __num_elements)
385
+ : _M_map(0), _M_map_size(0), _M_start(), _M_finish() {
386
+ _M_initialize_map(__num_elements);
387
+ }
388
+ _Deque_base(const allocator_type&)
389
+ : _M_map(0), _M_map_size(0), _M_start(), _M_finish() {}
390
+ ~_Deque_base();
391
+
392
+ protected:
393
+ void _M_initialize_map(size_t);
394
+ void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
395
+ void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
396
+ enum { _S_initial_map_size = 8 };
397
+
398
+ protected:
399
+ _Tp** _M_map;
400
+ size_t _M_map_size;
401
+ iterator _M_start;
402
+ iterator _M_finish;
403
+
404
+ typedef simple_alloc<_Tp, _Alloc> _Node_alloc_type;
405
+ typedef simple_alloc<_Tp*, _Alloc> _Map_alloc_type;
406
+
407
+ _Tp* _M_allocate_node()
408
+ { return _Node_alloc_type::allocate(__deque_buf_size(__bufsiz,
409
+ sizeof(_Tp))); }
410
+ void _M_deallocate_node(_Tp* __p)
411
+ { _Node_alloc_type::deallocate(__p, __deque_buf_size(__bufsiz,
412
+ sizeof(_Tp))); }
413
+ _Tp** _M_allocate_map(size_t __n)
414
+ { return _Map_alloc_type::allocate(__n); }
415
+ void _M_deallocate_map(_Tp** __p, size_t __n)
416
+ { _Map_alloc_type::deallocate(__p, __n); }
417
+ };
418
+
419
+ #endif /* __STL_USE_STD_ALLOCATORS */
420
+
421
+ // Non-inline member functions from _Deque_base.
422
+
423
+ template <class _Tp, class _Alloc, size_t __bufsiz>
424
+ _Deque_base<_Tp,_Alloc,__bufsiz>::~_Deque_base() {
425
+ if (_M_map) {
426
+ _M_destroy_nodes(_M_start._M_node, _M_finish._M_node + 1);
427
+ _M_deallocate_map(_M_map, _M_map_size);
428
+ }
429
+ }
430
+
431
+ template <class _Tp, class _Alloc, size_t __bufsiz>
432
+ void
433
+ _Deque_base<_Tp,_Alloc,__bufsiz>::_M_initialize_map(size_t __num_elements)
434
+ {
435
+ size_t __num_nodes =
436
+ __num_elements / __deque_buf_size(__bufsiz, sizeof(_Tp)) + 1;
437
+
438
+ _M_map_size = max((size_t) _S_initial_map_size, __num_nodes + 2);
439
+ _M_map = _M_allocate_map(_M_map_size);
440
+
441
+ _Tp** __nstart = _M_map + (_M_map_size - __num_nodes) / 2;
442
+ _Tp** __nfinish = __nstart + __num_nodes;
443
+
444
+ __STL_TRY {
445
+ _M_create_nodes(__nstart, __nfinish);
446
+ }
447
+ __STL_UNWIND((_M_deallocate_map(_M_map, _M_map_size),
448
+ _M_map = 0, _M_map_size = 0));
449
+ _M_start._M_set_node(__nstart);
450
+ _M_finish._M_set_node(__nfinish - 1);
451
+ _M_start._M_cur = _M_start._M_first;
452
+ _M_finish._M_cur = _M_finish._M_first +
453
+ __num_elements % __deque_buf_size(__bufsiz, sizeof(_Tp));
454
+ }
455
+
456
+ template <class _Tp, class _Alloc, size_t __bufsiz>
457
+ void
458
+ _Deque_base<_Tp,_Alloc,__bufsiz>::_M_create_nodes(_Tp** __nstart,
459
+ _Tp** __nfinish)
460
+ {
461
+ _Tp** __cur;
462
+ __STL_TRY {
463
+ for (__cur = __nstart; __cur < __nfinish; ++__cur)
464
+ *__cur = _M_allocate_node();
465
+ }
466
+ __STL_UNWIND(_M_destroy_nodes(__nstart, __cur));
467
+ }
468
+
469
+ template <class _Tp, class _Alloc, size_t __bufsiz>
470
+ void
471
+ _Deque_base<_Tp,_Alloc,__bufsiz>::_M_destroy_nodes(_Tp** __nstart,
472
+ _Tp** __nfinish)
473
+ {
474
+ for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
475
+ _M_deallocate_node(*__n);
476
+ }
477
+
478
+ // See __deque_buf_size(). The only reason that the default value is 0
479
+ // is as a workaround for bugs in the way that some compilers handle
480
+ // constant expressions.
481
+ template <class _Tp, class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp),
482
+ size_t __bufsiz = 0>
483
+ class deque : protected _Deque_base<_Tp, _Alloc, __bufsiz> {
484
+ typedef _Deque_base<_Tp, _Alloc, __bufsiz> _Base;
485
+ public: // Basic types
486
+ typedef _Tp value_type;
487
+ typedef value_type* pointer;
488
+ typedef const value_type* const_pointer;
489
+ typedef value_type& reference;
490
+ typedef const value_type& const_reference;
491
+ typedef size_t size_type;
492
+ typedef ptrdiff_t difference_type;
493
+
494
+ typedef typename _Base::allocator_type allocator_type;
495
+ allocator_type get_allocator() const { return _Base::get_allocator(); }
496
+
497
+ public: // Iterators
498
+ typedef typename _Base::iterator iterator;
499
+ typedef typename _Base::const_iterator const_iterator;
500
+
501
+ #ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
502
+ typedef reverse_iterator<const_iterator> const_reverse_iterator;
503
+ typedef reverse_iterator<iterator> reverse_iterator;
504
+ #else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
505
+ typedef reverse_iterator<const_iterator, value_type, const_reference,
506
+ difference_type>
507
+ const_reverse_iterator;
508
+ typedef reverse_iterator<iterator, value_type, reference, difference_type>
509
+ reverse_iterator;
510
+ #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
511
+
512
+ protected: // Internal typedefs
513
+ typedef pointer* _Map_pointer;
514
+ static size_t _S_buffer_size()
515
+ { return __deque_buf_size(__bufsiz, sizeof(_Tp)); }
516
+
517
+ protected:
518
+ using _Base::_M_initialize_map;
519
+ using _Base::_M_create_nodes;
520
+ using _Base::_M_destroy_nodes;
521
+ using _Base::_M_allocate_node;
522
+ using _Base::_M_deallocate_node;
523
+ using _Base::_M_allocate_map;
524
+ using _Base::_M_deallocate_map;
525
+
526
+ using _Base::_M_map;
527
+ using _Base::_M_map_size;
528
+ using _Base::_M_start;
529
+ using _Base::_M_finish;
530
+
531
+ public: // Basic accessors
532
+ iterator begin() { return _M_start; }
533
+ iterator end() { return _M_finish; }
534
+ const_iterator begin() const { return _M_start; }
535
+ const_iterator end() const { return _M_finish; }
536
+
537
+ reverse_iterator rbegin() { return reverse_iterator(_M_finish); }
538
+ reverse_iterator rend() { return reverse_iterator(_M_start); }
539
+ const_reverse_iterator rbegin() const
540
+ { return const_reverse_iterator(_M_finish); }
541
+ const_reverse_iterator rend() const
542
+ { return const_reverse_iterator(_M_start); }
543
+
544
+ reference operator[](size_type __n)
545
+ { return _M_start[difference_type(__n)]; }
546
+ const_reference operator[](size_type __n) const
547
+ { return _M_start[difference_type(__n)]; }
548
+
549
+ reference front() { return *_M_start; }
550
+ reference back() {
551
+ iterator __tmp = _M_finish;
552
+ --__tmp;
553
+ return *__tmp;
554
+ }
555
+ const_reference front() const { return *_M_start; }
556
+ const_reference back() const {
557
+ const_iterator __tmp = _M_finish;
558
+ --__tmp;
559
+ return *__tmp;
560
+ }
561
+
562
+ size_type size() const { return _M_finish - _M_start;; }
563
+ size_type max_size() const { return size_type(-1); }
564
+ bool empty() const { return _M_finish == _M_start; }
565
+
566
+ public: // Constructor, destructor.
567
+ explicit deque(const allocator_type& __a = allocator_type())
568
+ : _Base(__a, 0) {}
569
+ deque(const deque& __x) : _Base(__x.get_allocator(), __x.size())
570
+ { uninitialized_copy(__x.begin(), __x.end(), _M_start); }
571
+ deque(size_type __n, const value_type& __value,
572
+ const allocator_type& __a = allocator_type()) : _Base(__a, __n)
573
+ { _M_fill_initialize(__value); }
574
+ explicit deque(size_type __n) : _Base(allocator_type(), __n)
575
+ { _M_fill_initialize(value_type()); }
576
+
577
+ #ifdef __STL_MEMBER_TEMPLATES
578
+
579
+ // Check whether it's an integral type. If so, it's not an iterator.
580
+ template <class _InputIterator>
581
+ deque(_InputIterator __first, _InputIterator __last,
582
+ const allocator_type& __a = allocator_type()) : _Base(__a) {
583
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
584
+ _M_initialize_dispatch(__first, __last, _Integral());
585
+ }
586
+
587
+ template <class _Integer>
588
+ void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) {
589
+ _M_initialize_map(__n);
590
+ _M_fill_initialize(__x);
591
+ }
592
+
593
+ template <class _InputIter>
594
+ void _M_initialize_dispatch(_InputIter __first, _InputIter __last,
595
+ __false_type) {
596
+ _M_range_initialize(__first, __last, __ITERATOR_CATEGORY(__first));
597
+ }
598
+
599
+ #else /* __STL_MEMBER_TEMPLATES */
600
+
601
+ deque(const value_type* __first, const value_type* __last,
602
+ const allocator_type& __a = allocator_type())
603
+ : _Base(__a, __last - __first)
604
+ { uninitialized_copy(__first, __last, _M_start); }
605
+ deque(const_iterator __first, const_iterator __last,
606
+ const allocator_type& __a = allocator_type())
607
+ : _Base(__a, __last - __first)
608
+ { uninitialized_copy(__first, __last, _M_start); }
609
+
610
+ #endif /* __STL_MEMBER_TEMPLATES */
611
+
612
+ ~deque() { destroy(_M_start, _M_finish); }
613
+
614
+ deque& operator= (const deque& __x) {
615
+ const size_type __len = size();
616
+ if (&__x != this) {
617
+ if (__len >= __x.size())
618
+ erase(copy(__x.begin(), __x.end(), _M_start), _M_finish);
619
+ else {
620
+ const_iterator __mid = __x.begin() + difference_type(__len);
621
+ copy(__x.begin(), __mid, _M_start);
622
+ insert(_M_finish, __mid, __x.end());
623
+ }
624
+ }
625
+ return *this;
626
+ }
627
+
628
+ void swap(deque& __x) {
629
+ __STD::swap(_M_start, __x._M_start);
630
+ __STD::swap(_M_finish, __x._M_finish);
631
+ __STD::swap(_M_map, __x._M_map);
632
+ __STD::swap(_M_map_size, __x._M_map_size);
633
+ }
634
+
635
+ public:
636
+ // assign(), a generalized assignment member function. Two
637
+ // versions: one that takes a count, and one that takes a range.
638
+ // The range version is a member template, so we dispatch on whether
639
+ // or not the type is an integer.
640
+
641
+ void assign(size_type __n, const _Tp& __val) {
642
+ if (__n > size()) {
643
+ fill(begin(), end(), __val);
644
+ insert(end(), __n - size(), __val);
645
+ }
646
+ else {
647
+ erase(begin() + __n, end());
648
+ fill(begin(), end(), __val);
649
+ }
650
+ }
651
+
652
+ #ifdef __STL_MEMBER_TEMPLATES
653
+
654
+ template <class _InputIterator>
655
+ void assign(_InputIterator __first, _InputIterator __last) {
656
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
657
+ _M_assign_dispatch(__first, __last, _Integral());
658
+ }
659
+
660
+ private: // helper functions for assign()
661
+
662
+ template <class _Integer>
663
+ void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
664
+ { assign((size_type) __n, (_Tp) __val); }
665
+
666
+ template <class _InputIterator>
667
+ void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
668
+ __false_type) {
669
+ _M_assign_aux(__first, __last, __ITERATOR_CATEGORY(__first));
670
+ }
671
+
672
+ template <class _InputIterator>
673
+ void _M_assign_aux(_InputIterator __first, _InputIterator __last,
674
+ input_iterator_tag);
675
+
676
+ template <class _ForwardIterator>
677
+ void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
678
+ forward_iterator_tag) {
679
+ size_type __len = 0;
680
+ distance(__first, __last, __len);
681
+ if (__len > size()) {
682
+ _ForwardIterator __mid = __first;
683
+ advance(__mid, size());
684
+ copy(__first, __mid, begin());
685
+ insert(end(), __mid, __last);
686
+ }
687
+ else
688
+ erase(copy(__first, __last, begin()), end());
689
+ }
690
+
691
+ #endif /* __STL_MEMBER_TEMPLATES */
692
+
693
+ public: // push_* and pop_*
694
+
695
+ void push_back(const value_type& __t) {
696
+ if (_M_finish._M_cur != _M_finish._M_last - 1) {
697
+ construct(_M_finish._M_cur, __t);
698
+ ++_M_finish._M_cur;
699
+ }
700
+ else
701
+ _M_push_back_aux(__t);
702
+ }
703
+
704
+ void push_back() {
705
+ if (_M_finish._M_cur != _M_finish._M_last - 1) {
706
+ construct(_M_finish._M_cur);
707
+ ++_M_finish._M_cur;
708
+ }
709
+ else
710
+ _M_push_back_aux();
711
+ }
712
+
713
+ void push_front(const value_type& __t) {
714
+ if (_M_start._M_cur != _M_start._M_first) {
715
+ construct(_M_start._M_cur - 1, __t);
716
+ --_M_start._M_cur;
717
+ }
718
+ else
719
+ _M_push_front_aux(__t);
720
+ }
721
+
722
+ void push_front() {
723
+ if (_M_start._M_cur != _M_start._M_first) {
724
+ construct(_M_start._M_cur - 1);
725
+ --_M_start._M_cur;
726
+ }
727
+ else
728
+ _M_push_front_aux();
729
+ }
730
+
731
+
732
+ void pop_back() {
733
+ if (_M_finish._M_cur != _M_finish._M_first) {
734
+ --_M_finish._M_cur;
735
+ destroy(_M_finish._M_cur);
736
+ }
737
+ else
738
+ _M_pop_back_aux();
739
+ }
740
+
741
+ void pop_front() {
742
+ if (_M_start._M_cur != _M_start._M_last - 1) {
743
+ destroy(_M_start._M_cur);
744
+ ++_M_start._M_cur;
745
+ }
746
+ else
747
+ _M_pop_front_aux();
748
+ }
749
+
750
+ public: // Insert
751
+
752
+ iterator insert(iterator position, const value_type& __x) {
753
+ if (position._M_cur == _M_start._M_cur) {
754
+ push_front(__x);
755
+ return _M_start;
756
+ }
757
+ else if (position._M_cur == _M_finish._M_cur) {
758
+ push_back(__x);
759
+ iterator __tmp = _M_finish;
760
+ --__tmp;
761
+ return __tmp;
762
+ }
763
+ else {
764
+ return _M_insert_aux(position, __x);
765
+ }
766
+ }
767
+
768
+ iterator insert(iterator __position)
769
+ { return insert(__position, value_type()); }
770
+
771
+ void insert(iterator __pos, size_type __n, const value_type& __x);
772
+
773
+ #ifdef __STL_MEMBER_TEMPLATES
774
+
775
+ // Check whether it's an integral type. If so, it's not an iterator.
776
+ template <class _InputIterator>
777
+ void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
778
+ typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
779
+ _M_insert_dispatch(__pos, __first, __last, _Integral());
780
+ }
781
+
782
+ template <class _Integer>
783
+ void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
784
+ __true_type) {
785
+ insert(__pos, (size_type) __n, (value_type) __x);
786
+ }
787
+
788
+ template <class _InputIterator>
789
+ void _M_insert_dispatch(iterator __pos,
790
+ _InputIterator __first, _InputIterator __last,
791
+ __false_type) {
792
+ insert(__pos, __first, __last, __ITERATOR_CATEGORY(__first));
793
+ }
794
+
795
+ #else /* __STL_MEMBER_TEMPLATES */
796
+
797
+ void insert(iterator __pos,
798
+ const value_type* __first, const value_type* __last);
799
+ void insert(iterator __pos,
800
+ const_iterator __first, const_iterator __last);
801
+
802
+ #endif /* __STL_MEMBER_TEMPLATES */
803
+
804
+ void resize(size_type __new_size, const value_type& __x) {
805
+ const size_type __len = size();
806
+ if (__new_size < __len)
807
+ erase(_M_start + __new_size, _M_finish);
808
+ else
809
+ insert(_M_finish, __new_size - __len, __x);
810
+ }
811
+
812
+ void resize(size_type new_size) { resize(new_size, value_type()); }
813
+
814
+ public: // Erase
815
+ iterator erase(iterator __pos) {
816
+ iterator __next = __pos;
817
+ ++__next;
818
+ difference_type __index = __pos - _M_start;
819
+ if (static_cast<size_type>(__index) < (size() >> 1)) {
820
+ copy_backward(_M_start, __pos, __next);
821
+ pop_front();
822
+ }
823
+ else {
824
+ copy(__next, _M_finish, __pos);
825
+ pop_back();
826
+ }
827
+ return _M_start + __index;
828
+ }
829
+
830
+ iterator erase(iterator __first, iterator __last);
831
+ void clear();
832
+
833
+ protected: // Internal construction/destruction
834
+
835
+ void _M_fill_initialize(const value_type& __value);
836
+
837
+ #ifdef __STL_MEMBER_TEMPLATES
838
+
839
+ template <class _InputIterator>
840
+ void _M_range_initialize(_InputIterator __first, _InputIterator __last,
841
+ input_iterator_tag);
842
+
843
+ template <class _ForwardIterator>
844
+ void _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
845
+ forward_iterator_tag);
846
+
847
+ #endif /* __STL_MEMBER_TEMPLATES */
848
+
849
+ protected: // Internal push_* and pop_*
850
+
851
+ void _M_push_back_aux(const value_type&);
852
+ void _M_push_back_aux();
853
+ void _M_push_front_aux(const value_type&);
854
+ void _M_push_front_aux();
855
+ void _M_pop_back_aux();
856
+ void _M_pop_front_aux();
857
+
858
+ protected: // Internal insert functions
859
+
860
+ #ifdef __STL_MEMBER_TEMPLATES
861
+
862
+ template <class _InputIterator>
863
+ void insert(iterator __pos, _InputIterator __first, _InputIterator __last,
864
+ input_iterator_tag);
865
+
866
+ template <class _ForwardIterator>
867
+ void insert(iterator __pos,
868
+ _ForwardIterator __first, _ForwardIterator __last,
869
+ forward_iterator_tag);
870
+
871
+ #endif /* __STL_MEMBER_TEMPLATES */
872
+
873
+ iterator _M_insert_aux(iterator __pos, const value_type& __x);
874
+ iterator _M_insert_aux(iterator __pos);
875
+ void _M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
876
+
877
+ #ifdef __STL_MEMBER_TEMPLATES
878
+
879
+ template <class _ForwardIterator>
880
+ void _M_insert_aux(iterator __pos,
881
+ _ForwardIterator __first, _ForwardIterator __last,
882
+ size_type __n);
883
+
884
+ #else /* __STL_MEMBER_TEMPLATES */
885
+
886
+ void _M_insert_aux(iterator __pos,
887
+ const value_type* __first, const value_type* __last,
888
+ size_type __n);
889
+
890
+ void _M_insert_aux(iterator __pos,
891
+ const_iterator __first, const_iterator __last,
892
+ size_type __n);
893
+
894
+ #endif /* __STL_MEMBER_TEMPLATES */
895
+
896
+ iterator _M_reserve_elements_at_front(size_type __n) {
897
+ size_type __vacancies = _M_start._M_cur - _M_start._M_first;
898
+ if (__n > __vacancies)
899
+ _M_new_elements_at_front(__n - __vacancies);
900
+ return _M_start - difference_type(__n);
901
+ }
902
+
903
+ iterator _M_reserve_elements_at_back(size_type __n) {
904
+ size_type __vacancies = (_M_finish._M_last - _M_finish._M_cur) - 1;
905
+ if (__n > __vacancies)
906
+ _M_new_elements_at_back(__n - __vacancies);
907
+ return _M_finish + difference_type(__n);
908
+ }
909
+
910
+ void _M_new_elements_at_front(size_type __new_elements);
911
+ void _M_new_elements_at_back(size_type __new_elements);
912
+
913
+ protected: // Allocation of _M_map and nodes
914
+
915
+ // Makes sure the _M_map has space for new nodes. Does not actually
916
+ // add the nodes. Can invalidate _M_map pointers. (And consequently,
917
+ // deque iterators.)
918
+
919
+ void _M_reserve_map_at_back (size_type __nodes_to_add = 1) {
920
+ if (__nodes_to_add + 1 > _M_map_size - (_M_finish._M_node - _M_map))
921
+ _M_reallocate_map(__nodes_to_add, false);
922
+ }
923
+
924
+ void _M_reserve_map_at_front (size_type __nodes_to_add = 1) {
925
+ if (__nodes_to_add > size_type(_M_start._M_node - _M_map))
926
+ _M_reallocate_map(__nodes_to_add, true);
927
+ }
928
+
929
+ void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
930
+
931
+ #ifdef __STL_NON_TYPE_TMPL_PARAM_BUG
932
+ public:
933
+ bool operator==(const deque<_Tp,_Alloc,0>& __x) const {
934
+ return size() == __x.size() && equal(begin(), end(), __x.begin());
935
+ }
936
+ bool operator!=(const deque<_Tp,_Alloc,0>& __x) const {
937
+ return size() != __x.size() || !equal(begin(), end(), __x.begin());
938
+ }
939
+ bool operator<(const deque<_Tp,_Alloc,0>& __x) const {
940
+ return lexicographical_compare(begin(), end(), __x.begin(), __x.end());
941
+ }
942
+ #endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
943
+ };
944
+
945
+ // Non-inline member functions
946
+
947
+ #ifdef __STL_MEMBER_TEMPLATES
948
+
949
+ template <class _Tp, class _Alloc, size_t __bufsize>
950
+ template <class _InputIter>
951
+ void deque<_Tp, _Alloc, __bufsize>
952
+ ::_M_assign_aux(_InputIter __first, _InputIter __last, input_iterator_tag)
953
+ {
954
+ iterator __cur = begin();
955
+ for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
956
+ *__cur = *__first;
957
+ if (__first == __last)
958
+ erase(__cur, end());
959
+ else
960
+ insert(end(), __first, __last);
961
+ }
962
+
963
+ #endif /* __STL_MEMBER_TEMPLATES */
964
+
965
+ template <class _Tp, class _Alloc, size_t __bufsize>
966
+ void
967
+ deque<_Tp, _Alloc, __bufsize>::insert(iterator __pos,
968
+ size_type __n, const value_type& __x)
969
+ {
970
+ if (__pos._M_cur == _M_start._M_cur) {
971
+ iterator __new_start = _M_reserve_elements_at_front(__n);
972
+ uninitialized_fill(__new_start, _M_start, __x);
973
+ _M_start = __new_start;
974
+ }
975
+ else if (__pos._M_cur == _M_finish._M_cur) {
976
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
977
+ uninitialized_fill(_M_finish, __new_finish, __x);
978
+ _M_finish = __new_finish;
979
+ }
980
+ else
981
+ _M_insert_aux(__pos, __n, __x);
982
+ }
983
+
984
+ #ifndef __STL_MEMBER_TEMPLATES
985
+
986
+ template <class _Tp, class _Alloc, size_t __bufsize>
987
+ void deque<_Tp, _Alloc, __bufsize>::insert(iterator __pos,
988
+ const value_type* __first,
989
+ const value_type* __last) {
990
+ size_type __n = __last - __first;
991
+ if (__pos._M_cur == _M_start._M_cur) {
992
+ iterator __new_start = _M_reserve_elements_at_front(__n);
993
+ __STL_TRY {
994
+ uninitialized_copy(__first, __last, __new_start);
995
+ _M_start = __new_start;
996
+ }
997
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
998
+ }
999
+ else if (__pos._M_cur == _M_finish._M_cur) {
1000
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
1001
+ __STL_TRY {
1002
+ uninitialized_copy(__first, __last, _M_finish);
1003
+ _M_finish = __new_finish;
1004
+ }
1005
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
1006
+ __new_finish._M_node + 1));
1007
+ }
1008
+ else
1009
+ _M_insert_aux(__pos, __first, __last, __n);
1010
+ }
1011
+
1012
+ template <class _Tp, class _Alloc, size_t __bufsize>
1013
+ void deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos,
1014
+ const_iterator __first,
1015
+ const_iterator __last)
1016
+ {
1017
+ size_type __n = __last - __first;
1018
+ if (__pos._M_cur == _M_start._M_cur) {
1019
+ iterator __new_start = _M_reserve_elements_at_front(__n);
1020
+ __STL_TRY {
1021
+ uninitialized_copy(__first, __last, __new_start);
1022
+ _M_start = __new_start;
1023
+ }
1024
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
1025
+ }
1026
+ else if (__pos._M_cur == _M_finish._M_cur) {
1027
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
1028
+ __STL_TRY {
1029
+ uninitialized_copy(__first, __last, _M_finish);
1030
+ _M_finish = __new_finish;
1031
+ }
1032
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
1033
+ __new_finish._M_node + 1));
1034
+ }
1035
+ else
1036
+ _M_insert_aux(__pos, __first, __last, __n);
1037
+ }
1038
+
1039
+ #endif /* __STL_MEMBER_TEMPLATES */
1040
+
1041
+ template <class _Tp, class _Alloc, size_t __bufsize>
1042
+ typename deque<_Tp,_Alloc,__bufsize>::iterator
1043
+ deque<_Tp,_Alloc,__bufsize>::erase(iterator __first, iterator __last)
1044
+ {
1045
+ if (__first == _M_start && __last == _M_finish) {
1046
+ clear();
1047
+ return _M_finish;
1048
+ }
1049
+ else {
1050
+ difference_type __n = __last - __first;
1051
+ difference_type __elems_before = __first - _M_start;
1052
+ if (static_cast<size_type>(__elems_before) < (size() - __n) / 2) {
1053
+ copy_backward(_M_start, __first, __last);
1054
+ iterator __new_start = _M_start + __n;
1055
+ destroy(_M_start, __new_start);
1056
+ _M_destroy_nodes(__new_start._M_node, _M_start._M_node);
1057
+ _M_start = __new_start;
1058
+ }
1059
+ else {
1060
+ copy(__last, _M_finish, __first);
1061
+ iterator __new_finish = _M_finish - __n;
1062
+ destroy(__new_finish, _M_finish);
1063
+ _M_destroy_nodes(__new_finish._M_node + 1, _M_finish._M_node + 1);
1064
+ _M_finish = __new_finish;
1065
+ }
1066
+ return _M_start + __elems_before;
1067
+ }
1068
+ }
1069
+
1070
+ template <class _Tp, class _Alloc, size_t __bufsize>
1071
+ void deque<_Tp,_Alloc,__bufsize>::clear()
1072
+ {
1073
+ for (_Map_pointer __node = _M_start._M_node + 1;
1074
+ __node < _M_finish._M_node;
1075
+ ++__node) {
1076
+ destroy(*__node, *__node + _S_buffer_size());
1077
+ _M_deallocate_node(*__node);
1078
+ }
1079
+
1080
+ if (_M_start._M_node != _M_finish._M_node) {
1081
+ destroy(_M_start._M_cur, _M_start._M_last);
1082
+ destroy(_M_finish._M_first, _M_finish._M_cur);
1083
+ _M_deallocate_node(_M_finish._M_first);
1084
+ }
1085
+ else
1086
+ destroy(_M_start._M_cur, _M_finish._M_cur);
1087
+
1088
+ _M_finish = _M_start;
1089
+ }
1090
+
1091
+ // Precondition: _M_start and _M_finish have already been initialized,
1092
+ // but none of the deque's elements have yet been constructed.
1093
+ template <class _Tp, class _Alloc, size_t __bufsize>
1094
+ void
1095
+ deque<_Tp,_Alloc,__bufsize>::_M_fill_initialize(const value_type& __value) {
1096
+ _Map_pointer __cur;
1097
+ __STL_TRY {
1098
+ for (__cur = _M_start._M_node; __cur < _M_finish._M_node; ++__cur)
1099
+ uninitialized_fill(*__cur, *__cur + _S_buffer_size(), __value);
1100
+ uninitialized_fill(_M_finish._M_first, _M_finish._M_cur, __value);
1101
+ }
1102
+ __STL_UNWIND(destroy(_M_start, iterator(*__cur, __cur)));
1103
+ }
1104
+
1105
+ #ifdef __STL_MEMBER_TEMPLATES
1106
+
1107
+ template <class _Tp, class _Alloc, size_t __bufsize>
1108
+ template <class _InputIterator>
1109
+ void
1110
+ deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_InputIterator __first,
1111
+ _InputIterator __last,
1112
+ input_iterator_tag)
1113
+ {
1114
+ _M_initialize_map(0);
1115
+ for ( ; __first != __last; ++__first)
1116
+ push_back(*__first);
1117
+ }
1118
+
1119
+ template <class _Tp, class _Alloc, size_t __bufsize>
1120
+ template <class _ForwardIterator>
1121
+ void
1122
+ deque<_Tp,_Alloc,__bufsize>::_M_range_initialize(_ForwardIterator __first,
1123
+ _ForwardIterator __last,
1124
+ forward_iterator_tag)
1125
+ {
1126
+ size_type __n = 0;
1127
+ distance(__first, __last, __n);
1128
+ _M_initialize_map(__n);
1129
+
1130
+ _Map_pointer __cur_node;
1131
+ __STL_TRY {
1132
+ for (__cur_node = _M_start._M_node;
1133
+ __cur_node < _M_finish._M_node;
1134
+ ++__cur_node) {
1135
+ _ForwardIterator __mid = __first;
1136
+ advance(__mid, _S_buffer_size());
1137
+ uninitialized_copy(__first, __mid, *__cur_node);
1138
+ __first = __mid;
1139
+ }
1140
+ uninitialized_copy(__first, __last, _M_finish._M_first);
1141
+ }
1142
+ __STL_UNWIND(destroy(_M_start, iterator(*__cur_node, __cur_node)));
1143
+ }
1144
+
1145
+ #endif /* __STL_MEMBER_TEMPLATES */
1146
+
1147
+ // Called only if _M_finish._M_cur == _M_finish._M_last - 1.
1148
+ template <class _Tp, class _Alloc, size_t __bufsize>
1149
+ void
1150
+ deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux(const value_type& __t)
1151
+ {
1152
+ value_type __t_copy = __t;
1153
+ _M_reserve_map_at_back();
1154
+ *(_M_finish._M_node + 1) = _M_allocate_node();
1155
+ __STL_TRY {
1156
+ construct(_M_finish._M_cur, __t_copy);
1157
+ _M_finish._M_set_node(_M_finish._M_node + 1);
1158
+ _M_finish._M_cur = _M_finish._M_first;
1159
+ }
1160
+ __STL_UNWIND(_M_deallocate_node(*(_M_finish._M_node + 1)));
1161
+ }
1162
+
1163
+ // Called only if _M_finish._M_cur == _M_finish._M_last - 1.
1164
+ template <class _Tp, class _Alloc, size_t __bufsize>
1165
+ void
1166
+ deque<_Tp,_Alloc,__bufsize>::_M_push_back_aux()
1167
+ {
1168
+ _M_reserve_map_at_back();
1169
+ *(_M_finish._M_node + 1) = _M_allocate_node();
1170
+ __STL_TRY {
1171
+ construct(_M_finish._M_cur);
1172
+ _M_finish._M_set_node(_M_finish._M_node + 1);
1173
+ _M_finish._M_cur = _M_finish._M_first;
1174
+ }
1175
+ __STL_UNWIND(_M_deallocate_node(*(_M_finish._M_node + 1)));
1176
+ }
1177
+
1178
+ // Called only if _M_start._M_cur == _M_start._M_first.
1179
+ template <class _Tp, class _Alloc, size_t __bufsize>
1180
+ void
1181
+ deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux(const value_type& __t)
1182
+ {
1183
+ value_type __t_copy = __t;
1184
+ _M_reserve_map_at_front();
1185
+ *(_M_start._M_node - 1) = _M_allocate_node();
1186
+ __STL_TRY {
1187
+ _M_start._M_set_node(_M_start._M_node - 1);
1188
+ _M_start._M_cur = _M_start._M_last - 1;
1189
+ construct(_M_start._M_cur, __t_copy);
1190
+ }
1191
+ __STL_UNWIND((++_M_start, _M_deallocate_node(*(_M_start._M_node - 1))));
1192
+ }
1193
+
1194
+ // Called only if _M_start._M_cur == _M_start._M_first.
1195
+ template <class _Tp, class _Alloc, size_t __bufsize>
1196
+ void
1197
+ deque<_Tp,_Alloc,__bufsize>::_M_push_front_aux()
1198
+ {
1199
+ _M_reserve_map_at_front();
1200
+ *(_M_start._M_node - 1) = _M_allocate_node();
1201
+ __STL_TRY {
1202
+ _M_start._M_set_node(_M_start._M_node - 1);
1203
+ _M_start._M_cur = _M_start._M_last - 1;
1204
+ construct(_M_start._M_cur);
1205
+ }
1206
+ __STL_UNWIND((++_M_start, _M_deallocate_node(*(_M_start._M_node - 1))));
1207
+ }
1208
+
1209
+ // Called only if _M_finish._M_cur == _M_finish._M_first.
1210
+ template <class _Tp, class _Alloc, size_t __bufsize>
1211
+ void
1212
+ deque<_Tp,_Alloc,__bufsize>::_M_pop_back_aux()
1213
+ {
1214
+ _M_deallocate_node(_M_finish._M_first);
1215
+ _M_finish._M_set_node(_M_finish._M_node - 1);
1216
+ _M_finish._M_cur = _M_finish._M_last - 1;
1217
+ destroy(_M_finish._M_cur);
1218
+ }
1219
+
1220
+ // Called only if _M_start._M_cur == _M_start._M_last - 1. Note that
1221
+ // if the deque has at least one element (a precondition for this member
1222
+ // function), and if _M_start._M_cur == _M_start._M_last, then the deque
1223
+ // must have at least two nodes.
1224
+ template <class _Tp, class _Alloc, size_t __bufsize>
1225
+ void
1226
+ deque<_Tp,_Alloc,__bufsize>::_M_pop_front_aux()
1227
+ {
1228
+ destroy(_M_start._M_cur);
1229
+ _M_deallocate_node(_M_start._M_first);
1230
+ _M_start._M_set_node(_M_start._M_node + 1);
1231
+ _M_start._M_cur = _M_start._M_first;
1232
+ }
1233
+
1234
+ #ifdef __STL_MEMBER_TEMPLATES
1235
+
1236
+ template <class _Tp, class _Alloc, size_t __bufsize>
1237
+ template <class _InputIterator>
1238
+ void
1239
+ deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos,
1240
+ _InputIterator __first,
1241
+ _InputIterator __last,
1242
+ input_iterator_tag)
1243
+ {
1244
+ copy(__first, __last, inserter(*this, __pos));
1245
+ }
1246
+
1247
+ template <class _Tp, class _Alloc, size_t __bufsize>
1248
+ template <class _ForwardIterator>
1249
+ void
1250
+ deque<_Tp,_Alloc,__bufsize>::insert(iterator __pos,
1251
+ _ForwardIterator __first,
1252
+ _ForwardIterator __last,
1253
+ forward_iterator_tag) {
1254
+ size_type __n = 0;
1255
+ distance(__first, __last, __n);
1256
+ if (__pos._M_cur == _M_start._M_cur) {
1257
+ iterator __new_start = _M_reserve_elements_at_front(__n);
1258
+ __STL_TRY {
1259
+ uninitialized_copy(__first, __last, __new_start);
1260
+ _M_start = __new_start;
1261
+ }
1262
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
1263
+ }
1264
+ else if (__pos._M_cur == _M_finish._M_cur) {
1265
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
1266
+ __STL_TRY {
1267
+ uninitialized_copy(__first, __last, _M_finish);
1268
+ _M_finish = __new_finish;
1269
+ }
1270
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
1271
+ __new_finish._M_node + 1));
1272
+ }
1273
+ else
1274
+ _M_insert_aux(__pos, __first, __last, __n);
1275
+ }
1276
+
1277
+ #endif /* __STL_MEMBER_TEMPLATES */
1278
+
1279
+ template <class _Tp, class _Alloc, size_t __bufsize>
1280
+ typename deque<_Tp, _Alloc, __bufsize>::iterator
1281
+ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
1282
+ const value_type& __x)
1283
+ {
1284
+ difference_type __index = __pos - _M_start;
1285
+ value_type __x_copy = __x;
1286
+ if (static_cast<size_type>(__index) < size() / 2) {
1287
+ push_front(front());
1288
+ iterator __front1 = _M_start;
1289
+ ++__front1;
1290
+ iterator __front2 = __front1;
1291
+ ++__front2;
1292
+ __pos = _M_start + __index;
1293
+ iterator __pos1 = __pos;
1294
+ ++__pos1;
1295
+ copy(__front2, __pos1, __front1);
1296
+ }
1297
+ else {
1298
+ push_back(back());
1299
+ iterator __back1 = _M_finish;
1300
+ --__back1;
1301
+ iterator __back2 = __back1;
1302
+ --__back2;
1303
+ __pos = _M_start + __index;
1304
+ copy_backward(__pos, __back2, __back1);
1305
+ }
1306
+ *__pos = __x_copy;
1307
+ return __pos;
1308
+ }
1309
+
1310
+ template <class _Tp, class _Alloc, size_t __bufsize>
1311
+ typename deque<_Tp,_Alloc,__bufsize>::iterator
1312
+ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos)
1313
+ {
1314
+ difference_type __index = __pos - _M_start;
1315
+ if (static_cast<size_type>(__index) < size() / 2) {
1316
+ push_front(front());
1317
+ iterator __front1 = _M_start;
1318
+ ++__front1;
1319
+ iterator __front2 = __front1;
1320
+ ++__front2;
1321
+ __pos = _M_start + __index;
1322
+ iterator __pos1 = __pos;
1323
+ ++__pos1;
1324
+ copy(__front2, __pos1, __front1);
1325
+ }
1326
+ else {
1327
+ push_back(back());
1328
+ iterator __back1 = _M_finish;
1329
+ --__back1;
1330
+ iterator __back2 = __back1;
1331
+ --__back2;
1332
+ __pos = _M_start + __index;
1333
+ copy_backward(__pos, __back2, __back1);
1334
+ }
1335
+ *__pos = value_type();
1336
+ return __pos;
1337
+ }
1338
+
1339
+ template <class _Tp, class _Alloc, size_t __bufsize>
1340
+ void
1341
+ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
1342
+ size_type __n,
1343
+ const value_type& __x)
1344
+ {
1345
+ const difference_type __elems_before = __pos - _M_start;
1346
+ size_type __length = size();
1347
+ value_type __x_copy = __x;
1348
+ if (static_cast<size_type>(__elems_before) < __length / 2) {
1349
+ iterator __new_start = _M_reserve_elements_at_front(__n);
1350
+ iterator __old_start = _M_start;
1351
+ __pos = _M_start + __elems_before;
1352
+ __STL_TRY {
1353
+ if (__elems_before >= difference_type(__n)) {
1354
+ iterator __start_n = _M_start + difference_type(__n);
1355
+ uninitialized_copy(_M_start, __start_n, __new_start);
1356
+ _M_start = __new_start;
1357
+ copy(__start_n, __pos, __old_start);
1358
+ fill(__pos - difference_type(__n), __pos, __x_copy);
1359
+ }
1360
+ else {
1361
+ __uninitialized_copy_fill(_M_start, __pos, __new_start,
1362
+ _M_start, __x_copy);
1363
+ _M_start = __new_start;
1364
+ fill(__old_start, __pos, __x_copy);
1365
+ }
1366
+ }
1367
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
1368
+ }
1369
+ else {
1370
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
1371
+ iterator __old_finish = _M_finish;
1372
+ const difference_type __elems_after =
1373
+ difference_type(__length) - __elems_before;
1374
+ __pos = _M_finish - __elems_after;
1375
+ __STL_TRY {
1376
+ if (__elems_after > difference_type(__n)) {
1377
+ iterator __finish_n = _M_finish - difference_type(__n);
1378
+ uninitialized_copy(__finish_n, _M_finish, _M_finish);
1379
+ _M_finish = __new_finish;
1380
+ copy_backward(__pos, __finish_n, __old_finish);
1381
+ fill(__pos, __pos + difference_type(__n), __x_copy);
1382
+ }
1383
+ else {
1384
+ __uninitialized_fill_copy(_M_finish, __pos + difference_type(__n),
1385
+ __x_copy, __pos, _M_finish);
1386
+ _M_finish = __new_finish;
1387
+ fill(__pos, __old_finish, __x_copy);
1388
+ }
1389
+ }
1390
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
1391
+ __new_finish._M_node + 1));
1392
+ }
1393
+ }
1394
+
1395
+ #ifdef __STL_MEMBER_TEMPLATES
1396
+
1397
+ template <class _Tp, class _Alloc, size_t __bufsize>
1398
+ template <class _ForwardIterator>
1399
+ void
1400
+ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
1401
+ _ForwardIterator __first,
1402
+ _ForwardIterator __last,
1403
+ size_type __n)
1404
+ {
1405
+ const difference_type __elemsbefore = __pos - _M_start;
1406
+ size_type __length = size();
1407
+ if (static_cast<size_type>(__elemsbefore) < __length / 2) {
1408
+ iterator __new_start = _M_reserve_elements_at_front(__n);
1409
+ iterator __old_start = _M_start;
1410
+ __pos = _M_start + __elemsbefore;
1411
+ __STL_TRY {
1412
+ if (__elemsbefore >= difference_type(__n)) {
1413
+ iterator __start_n = _M_start + difference_type(__n);
1414
+ uninitialized_copy(_M_start, __start_n, __new_start);
1415
+ _M_start = __new_start;
1416
+ copy(__start_n, __pos, __old_start);
1417
+ copy(__first, __last, __pos - difference_type(__n));
1418
+ }
1419
+ else {
1420
+ _ForwardIterator __mid = __first;
1421
+ advance(__mid, difference_type(__n) - __elemsbefore);
1422
+ __uninitialized_copy_copy(_M_start, __pos, __first, __mid,
1423
+ __new_start);
1424
+ _M_start = __new_start;
1425
+ copy(__mid, __last, __old_start);
1426
+ }
1427
+ }
1428
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
1429
+ }
1430
+ else {
1431
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
1432
+ iterator __old_finish = _M_finish;
1433
+ const difference_type __elemsafter =
1434
+ difference_type(__length) - __elemsbefore;
1435
+ __pos = _M_finish - __elemsafter;
1436
+ __STL_TRY {
1437
+ if (__elemsafter > difference_type(__n)) {
1438
+ iterator __finish_n = _M_finish - difference_type(__n);
1439
+ uninitialized_copy(__finish_n, _M_finish, _M_finish);
1440
+ _M_finish = __new_finish;
1441
+ copy_backward(__pos, __finish_n, __old_finish);
1442
+ copy(__first, __last, __pos);
1443
+ }
1444
+ else {
1445
+ _ForwardIterator __mid = __first;
1446
+ advance(__mid, __elemsafter);
1447
+ __uninitialized_copy_copy(__mid, __last, __pos, _M_finish, _M_finish);
1448
+ _M_finish = __new_finish;
1449
+ copy(__first, __mid, __pos);
1450
+ }
1451
+ }
1452
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
1453
+ __new_finish._M_node + 1));
1454
+ }
1455
+ }
1456
+
1457
+ #else /* __STL_MEMBER_TEMPLATES */
1458
+
1459
+ template <class _Tp, class _Alloc, size_t __bufsize>
1460
+ void
1461
+ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
1462
+ const value_type* __first,
1463
+ const value_type* __last,
1464
+ size_type __n)
1465
+ {
1466
+ const difference_type __elemsbefore = __pos - _M_start;
1467
+ size_type __length = size();
1468
+ if (__elemsbefore < __length / 2) {
1469
+ iterator __new_start = _M_reserve_elements_at_front(__n);
1470
+ iterator __old_start = _M_start;
1471
+ __pos = _M_start + __elemsbefore;
1472
+ __STL_TRY {
1473
+ if (__elemsbefore >= difference_type(__n)) {
1474
+ iterator __start_n = _M_start + difference_type(__n);
1475
+ uninitialized_copy(_M_start, __start_n, __new_start);
1476
+ _M_start = __new_start;
1477
+ copy(__start_n, __pos, __old_start);
1478
+ copy(__first, __last, __pos - difference_type(__n));
1479
+ }
1480
+ else {
1481
+ const value_type* __mid =
1482
+ __first + (difference_type(__n) - __elemsbefore);
1483
+ __uninitialized_copy_copy(_M_start, __pos, __first, __mid,
1484
+ __new_start);
1485
+ _M_start = __new_start;
1486
+ copy(__mid, __last, __old_start);
1487
+ }
1488
+ }
1489
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
1490
+ }
1491
+ else {
1492
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
1493
+ iterator __old_finish = _M_finish;
1494
+ const difference_type __elemsafter =
1495
+ difference_type(__length) - __elemsbefore;
1496
+ __pos = _M_finish - __elemsafter;
1497
+ __STL_TRY {
1498
+ if (__elemsafter > difference_type(__n)) {
1499
+ iterator __finish_n = _M_finish - difference_type(__n);
1500
+ uninitialized_copy(__finish_n, _M_finish, _M_finish);
1501
+ _M_finish = __new_finish;
1502
+ copy_backward(__pos, __finish_n, __old_finish);
1503
+ copy(__first, __last, __pos);
1504
+ }
1505
+ else {
1506
+ const value_type* __mid = __first + __elemsafter;
1507
+ __uninitialized_copy_copy(__mid, __last, __pos, _M_finish, _M_finish);
1508
+ _M_finish = __new_finish;
1509
+ copy(__first, __mid, __pos);
1510
+ }
1511
+ }
1512
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
1513
+ __new_finish._M_node + 1));
1514
+ }
1515
+ }
1516
+
1517
+ template <class _Tp, class _Alloc, size_t __bufsize>
1518
+ void
1519
+ deque<_Tp,_Alloc,__bufsize>::_M_insert_aux(iterator __pos,
1520
+ const_iterator __first,
1521
+ const_iterator __last,
1522
+ size_type __n)
1523
+ {
1524
+ const difference_type __elemsbefore = __pos - _M_start;
1525
+ size_type __length = size();
1526
+ if (__elemsbefore < __length / 2) {
1527
+ iterator __new_start = _M_reserve_elements_at_front(__n);
1528
+ iterator __old_start = _M_start;
1529
+ __pos = _M_start + __elemsbefore;
1530
+ __STL_TRY {
1531
+ if (__elemsbefore >= __n) {
1532
+ iterator __start_n = _M_start + __n;
1533
+ uninitialized_copy(_M_start, __start_n, __new_start);
1534
+ _M_start = __new_start;
1535
+ copy(__start_n, __pos, __old_start);
1536
+ copy(__first, __last, __pos - difference_type(__n));
1537
+ }
1538
+ else {
1539
+ const_iterator __mid = __first + (__n - __elemsbefore);
1540
+ __uninitialized_copy_copy(_M_start, __pos, __first, __mid,
1541
+ __new_start);
1542
+ _M_start = __new_start;
1543
+ copy(__mid, __last, __old_start);
1544
+ }
1545
+ }
1546
+ __STL_UNWIND(_M_destroy_nodes(__new_start._M_node, _M_start._M_node));
1547
+ }
1548
+ else {
1549
+ iterator __new_finish = _M_reserve_elements_at_back(__n);
1550
+ iterator __old_finish = _M_finish;
1551
+ const difference_type __elemsafter = __length - __elemsbefore;
1552
+ __pos = _M_finish - __elemsafter;
1553
+ __STL_TRY {
1554
+ if (__elemsafter > __n) {
1555
+ iterator __finish_n = _M_finish - difference_type(__n);
1556
+ uninitialized_copy(__finish_n, _M_finish, _M_finish);
1557
+ _M_finish = __new_finish;
1558
+ copy_backward(__pos, __finish_n, __old_finish);
1559
+ copy(__first, __last, __pos);
1560
+ }
1561
+ else {
1562
+ const_iterator __mid = __first + __elemsafter;
1563
+ __uninitialized_copy_copy(__mid, __last, __pos, _M_finish, _M_finish);
1564
+ _M_finish = __new_finish;
1565
+ copy(__first, __mid, __pos);
1566
+ }
1567
+ }
1568
+ __STL_UNWIND(_M_destroy_nodes(_M_finish._M_node + 1,
1569
+ __new_finish._M_node + 1));
1570
+ }
1571
+ }
1572
+
1573
+ #endif /* __STL_MEMBER_TEMPLATES */
1574
+
1575
+ template <class _Tp, class _Alloc, size_t __bufsize>
1576
+ void
1577
+ deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_front(size_type __new_elems)
1578
+ {
1579
+ size_type __new_nodes
1580
+ = (__new_elems + _S_buffer_size() - 1) / _S_buffer_size();
1581
+ _M_reserve_map_at_front(__new_nodes);
1582
+ size_type __i;
1583
+ __STL_TRY {
1584
+ for (__i = 1; __i <= __new_nodes; ++__i)
1585
+ *(_M_start._M_node - __i) = _M_allocate_node();
1586
+ }
1587
+ # ifdef __STL_USE_EXCEPTIONS
1588
+ catch(...) {
1589
+ for (size_type __j = 1; __j < __i; ++__j)
1590
+ _M_deallocate_node(*(_M_start._M_node - __j));
1591
+ throw;
1592
+ }
1593
+ # endif /* __STL_USE_EXCEPTIONS */
1594
+ }
1595
+
1596
+ template <class _Tp, class _Alloc, size_t __bufsize>
1597
+ void
1598
+ deque<_Tp,_Alloc,__bufsize>::_M_new_elements_at_back(size_type __new_elems)
1599
+ {
1600
+ size_type __new_nodes
1601
+ = (__new_elems + _S_buffer_size() - 1) / _S_buffer_size();
1602
+ _M_reserve_map_at_back(__new_nodes);
1603
+ size_type __i;
1604
+ __STL_TRY {
1605
+ for (__i = 1; __i <= __new_nodes; ++__i)
1606
+ *(_M_finish._M_node + __i) = _M_allocate_node();
1607
+ }
1608
+ # ifdef __STL_USE_EXCEPTIONS
1609
+ catch(...) {
1610
+ for (size_type __j = 1; __j < __i; ++__j)
1611
+ _M_deallocate_node(*(_M_finish._M_node + __j));
1612
+ throw;
1613
+ }
1614
+ # endif /* __STL_USE_EXCEPTIONS */
1615
+ }
1616
+
1617
+ template <class _Tp, class _Alloc, size_t __bufsize>
1618
+ void
1619
+ deque<_Tp,_Alloc,__bufsize>::_M_reallocate_map(size_type __nodes_to_add,
1620
+ bool __add_at_front)
1621
+ {
1622
+ size_type __old_num_nodes = _M_finish._M_node - _M_start._M_node + 1;
1623
+ size_type __new_num_nodes = __old_num_nodes + __nodes_to_add;
1624
+
1625
+ _Map_pointer __new_nstart;
1626
+ if (_M_map_size > 2 * __new_num_nodes) {
1627
+ __new_nstart = _M_map + (_M_map_size - __new_num_nodes) / 2
1628
+ + (__add_at_front ? __nodes_to_add : 0);
1629
+ if (__new_nstart < _M_start._M_node)
1630
+ copy(_M_start._M_node, _M_finish._M_node + 1, __new_nstart);
1631
+ else
1632
+ copy_backward(_M_start._M_node, _M_finish._M_node + 1,
1633
+ __new_nstart + __old_num_nodes);
1634
+ }
1635
+ else {
1636
+ size_type __new_map_size =
1637
+ _M_map_size + max(_M_map_size, __nodes_to_add) + 2;
1638
+
1639
+ _Map_pointer __new_map = _M_allocate_map(__new_map_size);
1640
+ __new_nstart = __new_map + (__new_map_size - __new_num_nodes) / 2
1641
+ + (__add_at_front ? __nodes_to_add : 0);
1642
+ copy(_M_start._M_node, _M_finish._M_node + 1, __new_nstart);
1643
+ _M_deallocate_map(_M_map, _M_map_size);
1644
+
1645
+ _M_map = __new_map;
1646
+ _M_map_size = __new_map_size;
1647
+ }
1648
+
1649
+ _M_start._M_set_node(__new_nstart);
1650
+ _M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
1651
+ }
1652
+
1653
+
1654
+ // Nonmember functions.
1655
+
1656
+ #ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
1657
+
1658
+ template <class _Tp, class _Alloc, size_t __bufsiz>
1659
+ bool operator==(const deque<_Tp, _Alloc, __bufsiz>& __x,
1660
+ const deque<_Tp, _Alloc, __bufsiz>& __y)
1661
+ {
1662
+ return __x.size() == __y.size() &&
1663
+ equal(__x.begin(), __x.end(), __y.begin());
1664
+ }
1665
+
1666
+ template <class _Tp, class _Alloc, size_t __bufsiz>
1667
+ bool operator<(const deque<_Tp, _Alloc, __bufsiz>& __x,
1668
+ const deque<_Tp, _Alloc, __bufsiz>& __y)
1669
+ {
1670
+ return lexicographical_compare(__x.begin(), __x.end(),
1671
+ __y.begin(), __y.end());
1672
+ }
1673
+
1674
+ #endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
1675
+
1676
+ #if defined(__STL_FUNCTION_TMPL_PARTIAL_ORDER) && \
1677
+ !defined(__STL_NON_TYPE_TMPL_PARAM_BUG)
1678
+
1679
+ template <class _Tp, class _Alloc, size_t __bufsiz>
1680
+ inline void
1681
+ swap(deque<_Tp,_Alloc,__bufsiz>& __x, deque<_Tp,_Alloc,__bufsiz>& __y)
1682
+ {
1683
+ __x.swap(__y);
1684
+ }
1685
+
1686
+ #endif
1687
+
1688
+ #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
1689
+ #pragma reset woff 1174
1690
+ #pragma reset woff 1375
1691
+ #endif
1692
+
1693
+ __STL_END_NAMESPACE
1694
+
1695
+ #endif /* __SGI_STL_INTERNAL_DEQUE_H */
1696
+
1697
+ // Local Variables:
1698
+ // mode:C++
1699
+ // End: