williamr@2
|
1 |
/*
|
williamr@2
|
2 |
*
|
williamr@2
|
3 |
* Copyright (c) 1994
|
williamr@2
|
4 |
* Hewlett-Packard Company
|
williamr@2
|
5 |
*
|
williamr@2
|
6 |
* Copyright (c) 1996,1997
|
williamr@2
|
7 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@2
|
8 |
*
|
williamr@2
|
9 |
* Copyright (c) 1997
|
williamr@2
|
10 |
* Moscow Center for SPARC Technology
|
williamr@2
|
11 |
*
|
williamr@2
|
12 |
* Copyright (c) 1999
|
williamr@2
|
13 |
* Boris Fomitchev
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
16 |
* or implied. Any use is at your own risk.
|
williamr@2
|
17 |
*
|
williamr@2
|
18 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
19 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
20 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
21 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
22 |
* modified is included with the above copyright notice.
|
williamr@2
|
23 |
*
|
williamr@2
|
24 |
*/
|
williamr@2
|
25 |
|
williamr@2
|
26 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@2
|
27 |
* You should not attempt to use it directly.
|
williamr@2
|
28 |
*/
|
williamr@2
|
29 |
|
williamr@2
|
30 |
#ifndef _STLP_INTERNAL_MAP_H
|
williamr@2
|
31 |
#define _STLP_INTERNAL_MAP_H
|
williamr@2
|
32 |
|
williamr@2
|
33 |
#ifndef _STLP_INTERNAL_TREE_H
|
williamr@2
|
34 |
# include <stl/_tree.h>
|
williamr@2
|
35 |
#endif
|
williamr@2
|
36 |
|
williamr@2
|
37 |
#define map __WORKAROUND_RENAME(map)
|
williamr@2
|
38 |
#define multimap __WORKAROUND_RENAME(multimap)
|
williamr@2
|
39 |
|
williamr@2
|
40 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
41 |
|
williamr@2
|
42 |
template <class _Key, class _Tp, __DFL_TMPL_PARAM(_Compare, less<_Key> ),
|
williamr@2
|
43 |
_STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
|
williamr@2
|
44 |
class map
|
williamr@2
|
45 |
{
|
williamr@2
|
46 |
public:
|
williamr@2
|
47 |
|
williamr@2
|
48 |
// typedefs:
|
williamr@2
|
49 |
|
williamr@2
|
50 |
typedef _Key key_type;
|
williamr@2
|
51 |
typedef _Tp data_type;
|
williamr@2
|
52 |
typedef _Tp mapped_type;
|
williamr@2
|
53 |
typedef pair<const _Key, _Tp> value_type;
|
williamr@2
|
54 |
typedef _Compare key_compare;
|
williamr@2
|
55 |
|
williamr@2
|
56 |
class value_compare
|
williamr@2
|
57 |
: public binary_function<value_type, value_type, bool> {
|
williamr@2
|
58 |
friend class map<_Key,_Tp,_Compare,_Alloc>;
|
williamr@2
|
59 |
protected :
|
williamr@2
|
60 |
_Compare _M_comp;
|
williamr@2
|
61 |
value_compare(_Compare __c) : _M_comp(__c) {}
|
williamr@2
|
62 |
public:
|
williamr@2
|
63 |
bool operator()(const value_type& __x, const value_type& __y) const {
|
williamr@2
|
64 |
return _M_comp(__x.first, __y.first);
|
williamr@2
|
65 |
}
|
williamr@2
|
66 |
};
|
williamr@2
|
67 |
|
williamr@2
|
68 |
private:
|
williamr@2
|
69 |
# ifdef _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
|
williamr@2
|
70 |
typedef _Rb_tree<key_type, value_type,
|
williamr@2
|
71 |
_Select1st_hint<value_type, _Key>, key_compare, _Alloc> _Rep_type;
|
williamr@2
|
72 |
# else
|
williamr@2
|
73 |
typedef _Rb_tree<key_type, value_type,
|
williamr@2
|
74 |
_Select1st<value_type>, key_compare, _Alloc> _Rep_type;
|
williamr@2
|
75 |
# endif
|
williamr@2
|
76 |
_Rep_type _M_t; // red-black tree representing map
|
williamr@2
|
77 |
public:
|
williamr@2
|
78 |
typedef typename _Rep_type::pointer pointer;
|
williamr@2
|
79 |
typedef typename _Rep_type::const_pointer const_pointer;
|
williamr@2
|
80 |
typedef typename _Rep_type::reference reference;
|
williamr@2
|
81 |
typedef typename _Rep_type::const_reference const_reference;
|
williamr@2
|
82 |
typedef typename _Rep_type::iterator iterator;
|
williamr@2
|
83 |
typedef typename _Rep_type::const_iterator const_iterator;
|
williamr@2
|
84 |
typedef typename _Rep_type::reverse_iterator reverse_iterator;
|
williamr@2
|
85 |
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
|
williamr@2
|
86 |
typedef typename _Rep_type::size_type size_type;
|
williamr@2
|
87 |
typedef typename _Rep_type::difference_type difference_type;
|
williamr@2
|
88 |
typedef typename _Rep_type::allocator_type allocator_type;
|
williamr@2
|
89 |
typedef map<_Key,_Tp,_Compare,_Alloc> _Self;
|
williamr@2
|
90 |
|
williamr@2
|
91 |
// allocation/deallocation
|
williamr@2
|
92 |
|
williamr@2
|
93 |
map() : _M_t(_Compare(), allocator_type()) {
|
williamr@2
|
94 |
_STLP_POP_IF_CHECK
|
williamr@2
|
95 |
}
|
williamr@2
|
96 |
|
williamr@2
|
97 |
explicit map(const _Compare& __comp,
|
williamr@2
|
98 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
99 |
: _M_t(__comp, __a) {
|
williamr@2
|
100 |
_STLP_POP_IF_CHECK
|
williamr@2
|
101 |
}
|
williamr@2
|
102 |
|
williamr@2
|
103 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
104 |
template <class _InputIterator>
|
williamr@2
|
105 |
map(_InputIterator __first, _InputIterator __last)
|
williamr@2
|
106 |
: _M_t(_Compare(), allocator_type())
|
williamr@2
|
107 |
{
|
williamr@2
|
108 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
109 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
110 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
111 |
}
|
williamr@2
|
112 |
|
williamr@2
|
113 |
template <class _InputIterator>
|
williamr@2
|
114 |
map(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
|
williamr@2
|
115 |
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
|
williamr@2
|
116 |
: _M_t(__comp, __a) {
|
williamr@2
|
117 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
118 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
119 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
120 |
}
|
williamr@2
|
121 |
|
williamr@2
|
122 |
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
|
williamr@2
|
123 |
template <class _InputIterator>
|
williamr@2
|
124 |
map(_InputIterator __first, _InputIterator __last, const _Compare& __comp)
|
williamr@2
|
125 |
: _M_t(__comp, allocator_type())
|
williamr@2
|
126 |
{ _STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
127 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
128 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
129 |
}
|
williamr@2
|
130 |
# endif
|
williamr@2
|
131 |
|
williamr@2
|
132 |
#else
|
williamr@2
|
133 |
map(const value_type* __first, const value_type* __last)
|
williamr@2
|
134 |
: _M_t(_Compare(), allocator_type())
|
williamr@2
|
135 |
{ _STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
136 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
137 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
138 |
}
|
williamr@2
|
139 |
|
williamr@2
|
140 |
map(const value_type* __first,
|
williamr@2
|
141 |
const value_type* __last, const _Compare& __comp,
|
williamr@2
|
142 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
143 |
: _M_t(__comp, __a) {
|
williamr@2
|
144 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
145 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
146 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
147 |
}
|
williamr@2
|
148 |
|
williamr@2
|
149 |
map(const_iterator __first, const_iterator __last)
|
williamr@2
|
150 |
: _M_t(_Compare(), allocator_type())
|
williamr@2
|
151 |
{
|
williamr@2
|
152 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
153 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
154 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
155 |
}
|
williamr@2
|
156 |
|
williamr@2
|
157 |
map(const_iterator __first, const_iterator __last, const _Compare& __comp,
|
williamr@2
|
158 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
159 |
: _M_t(__comp, __a) {
|
williamr@2
|
160 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
161 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
162 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
163 |
}
|
williamr@2
|
164 |
|
williamr@2
|
165 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
166 |
|
williamr@2
|
167 |
# ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
168 |
map(const map<_Key,_Tp,_Compare,_Alloc>& __x)
|
williamr@2
|
169 |
{
|
williamr@2
|
170 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
171 |
_M_t =__x._M_t;
|
williamr@2
|
172 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
173 |
}
|
williamr@2
|
174 |
#else
|
williamr@2
|
175 |
map(const map<_Key,_Tp,_Compare,_Alloc>& __x) :
|
williamr@2
|
176 |
_M_t(__x._M_t) {
|
williamr@2
|
177 |
_STLP_POP_IF_CHECK
|
williamr@2
|
178 |
}
|
williamr@2
|
179 |
# endif
|
williamr@2
|
180 |
map<_Key,_Tp,_Compare,_Alloc>&
|
williamr@2
|
181 |
operator=(const map<_Key, _Tp, _Compare, _Alloc>& __x)
|
williamr@2
|
182 |
{
|
williamr@2
|
183 |
_M_t = __x._M_t;
|
williamr@2
|
184 |
return *this;
|
williamr@2
|
185 |
}
|
williamr@2
|
186 |
|
williamr@2
|
187 |
#ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
188 |
public:
|
williamr@2
|
189 |
static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
190 |
static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
191 |
#endif
|
williamr@2
|
192 |
|
williamr@2
|
193 |
// accessors:
|
williamr@2
|
194 |
|
williamr@2
|
195 |
key_compare key_comp() const { return _M_t.key_comp(); }
|
williamr@2
|
196 |
value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
|
williamr@2
|
197 |
allocator_type get_allocator() const { return _M_t.get_allocator(); }
|
williamr@2
|
198 |
|
williamr@2
|
199 |
iterator begin() { return _M_t.begin(); }
|
williamr@2
|
200 |
const_iterator begin() const { return _M_t.begin(); }
|
williamr@2
|
201 |
iterator end() { return _M_t.end(); }
|
williamr@2
|
202 |
const_iterator end() const { return _M_t.end(); }
|
williamr@2
|
203 |
reverse_iterator rbegin() { return _M_t.rbegin(); }
|
williamr@2
|
204 |
const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
|
williamr@2
|
205 |
reverse_iterator rend() { return _M_t.rend(); }
|
williamr@2
|
206 |
const_reverse_iterator rend() const { return _M_t.rend(); }
|
williamr@2
|
207 |
bool empty() const { return _M_t.empty(); }
|
williamr@2
|
208 |
size_type size() const { return _M_t.size(); }
|
williamr@2
|
209 |
size_type max_size() const { return _M_t.max_size(); }
|
williamr@2
|
210 |
_Tp& operator[](const key_type& __k) {
|
williamr@2
|
211 |
iterator __i = lower_bound(__k);
|
williamr@2
|
212 |
// __i->first is greater than or equivalent to __k.
|
williamr@2
|
213 |
if (__i == end() || key_comp()(__k, (*__i).first)) {
|
williamr@2
|
214 |
# ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
215 |
value_type __tmp(__k, __false_type());
|
williamr@2
|
216 |
_STLP_PUSH_STACK_ITEM(value_type, &__tmp)
|
williamr@2
|
217 |
__i = insert(__i, __tmp);
|
williamr@2
|
218 |
|
williamr@2
|
219 |
# else
|
williamr@2
|
220 |
__i = insert(__i, value_type(__k, _STLP_DEFAULT_CONSTRUCTED(_Tp)));
|
williamr@2
|
221 |
# endif
|
williamr@2
|
222 |
}
|
williamr@2
|
223 |
return (*__i).second;
|
williamr@2
|
224 |
}
|
williamr@2
|
225 |
void swap(map<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
|
williamr@2
|
226 |
|
williamr@2
|
227 |
// insert/erase
|
williamr@2
|
228 |
|
williamr@2
|
229 |
pair<iterator,bool> insert(const value_type& __x)
|
williamr@2
|
230 |
{ return _M_t.insert_unique(__x); }
|
williamr@2
|
231 |
iterator insert(iterator position, const value_type& __x)
|
williamr@2
|
232 |
{ return _M_t.insert_unique(position, __x); }
|
williamr@2
|
233 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
234 |
template <class _InputIterator>
|
williamr@2
|
235 |
void insert(_InputIterator __first, _InputIterator __last) {
|
williamr@2
|
236 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
237 |
}
|
williamr@2
|
238 |
#else
|
williamr@2
|
239 |
void insert(const value_type* __first, const value_type* __last) {
|
williamr@2
|
240 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
241 |
}
|
williamr@2
|
242 |
void insert(const_iterator __first, const_iterator __last) {
|
williamr@2
|
243 |
_M_t.insert_unique(__first, __last);
|
williamr@2
|
244 |
}
|
williamr@2
|
245 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
246 |
|
williamr@2
|
247 |
void erase(iterator __position) { _M_t.erase(__position); }
|
williamr@2
|
248 |
size_type erase(const key_type& __x) { return _M_t.erase(__x); }
|
williamr@2
|
249 |
void erase(iterator __first, iterator __last)
|
williamr@2
|
250 |
{ _M_t.erase(__first, __last); }
|
williamr@2
|
251 |
void clear() { _M_t.clear(); }
|
williamr@2
|
252 |
|
williamr@2
|
253 |
// map operations:
|
williamr@2
|
254 |
|
williamr@2
|
255 |
iterator find(const key_type& __x) { return _M_t.find(__x); }
|
williamr@2
|
256 |
const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
|
williamr@2
|
257 |
size_type count(const key_type& __x) const {
|
williamr@2
|
258 |
return _M_t.find(__x) == _M_t.end() ? 0 : 1;
|
williamr@2
|
259 |
}
|
williamr@2
|
260 |
iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
|
williamr@2
|
261 |
const_iterator lower_bound(const key_type& __x) const {
|
williamr@2
|
262 |
return _M_t.lower_bound(__x);
|
williamr@2
|
263 |
}
|
williamr@2
|
264 |
iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
|
williamr@2
|
265 |
const_iterator upper_bound(const key_type& __x) const {
|
williamr@2
|
266 |
return _M_t.upper_bound(__x);
|
williamr@2
|
267 |
}
|
williamr@2
|
268 |
|
williamr@2
|
269 |
pair<iterator,iterator> equal_range(const key_type& __x) {
|
williamr@2
|
270 |
return _M_t.equal_range(__x);
|
williamr@2
|
271 |
}
|
williamr@2
|
272 |
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
|
williamr@2
|
273 |
return _M_t.equal_range(__x);
|
williamr@2
|
274 |
}
|
williamr@2
|
275 |
};
|
williamr@2
|
276 |
|
williamr@2
|
277 |
|
williamr@2
|
278 |
template <class _Key, class _Tp, __DFL_TMPL_PARAM(_Compare, less<_Key> ),
|
williamr@2
|
279 |
_STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
|
williamr@2
|
280 |
class multimap
|
williamr@2
|
281 |
{
|
williamr@2
|
282 |
public:
|
williamr@2
|
283 |
|
williamr@2
|
284 |
// typedefs:
|
williamr@2
|
285 |
|
williamr@2
|
286 |
typedef _Key key_type;
|
williamr@2
|
287 |
typedef _Tp data_type;
|
williamr@2
|
288 |
typedef _Tp mapped_type;
|
williamr@2
|
289 |
typedef pair<const _Key, _Tp> value_type;
|
williamr@2
|
290 |
typedef _Compare key_compare;
|
williamr@2
|
291 |
|
williamr@2
|
292 |
class value_compare : public binary_function<value_type, value_type, bool> {
|
williamr@2
|
293 |
friend class multimap<_Key,_Tp,_Compare,_Alloc>;
|
williamr@2
|
294 |
protected:
|
williamr@2
|
295 |
_Compare _M_comp;
|
williamr@2
|
296 |
value_compare(_Compare __c) : _M_comp(__c) {}
|
williamr@2
|
297 |
public:
|
williamr@2
|
298 |
bool operator()(const value_type& __x, const value_type& __y) const {
|
williamr@2
|
299 |
return _M_comp(__x.first, __y.first);
|
williamr@2
|
300 |
}
|
williamr@2
|
301 |
};
|
williamr@2
|
302 |
|
williamr@2
|
303 |
private:
|
williamr@2
|
304 |
# ifdef _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
|
williamr@2
|
305 |
typedef _Rb_tree<key_type, value_type,
|
williamr@2
|
306 |
_Select1st_hint<value_type, _Key>, key_compare, _Alloc> _Rep_type;
|
williamr@2
|
307 |
# else
|
williamr@2
|
308 |
typedef _Rb_tree<key_type, value_type,
|
williamr@2
|
309 |
_Select1st<value_type>, key_compare, _Alloc> _Rep_type;
|
williamr@2
|
310 |
# endif
|
williamr@2
|
311 |
_Rep_type _M_t; // red-black tree representing multimap
|
williamr@2
|
312 |
public:
|
williamr@2
|
313 |
typedef typename _Rep_type::pointer pointer;
|
williamr@2
|
314 |
typedef typename _Rep_type::const_pointer const_pointer;
|
williamr@2
|
315 |
typedef typename _Rep_type::reference reference;
|
williamr@2
|
316 |
typedef typename _Rep_type::const_reference const_reference;
|
williamr@2
|
317 |
typedef typename _Rep_type::iterator iterator;
|
williamr@2
|
318 |
typedef typename _Rep_type::const_iterator const_iterator;
|
williamr@2
|
319 |
typedef typename _Rep_type::reverse_iterator reverse_iterator;
|
williamr@2
|
320 |
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
|
williamr@2
|
321 |
typedef typename _Rep_type::size_type size_type;
|
williamr@2
|
322 |
typedef typename _Rep_type::difference_type difference_type;
|
williamr@2
|
323 |
typedef typename _Rep_type::allocator_type allocator_type;
|
williamr@2
|
324 |
typedef multimap<_Key,_Tp,_Compare,_Alloc> _Self;
|
williamr@2
|
325 |
|
williamr@2
|
326 |
// allocation/deallocation
|
williamr@2
|
327 |
|
williamr@2
|
328 |
multimap() : _M_t(_Compare(), allocator_type()) {
|
williamr@2
|
329 |
_STLP_POP_IF_CHECK
|
williamr@2
|
330 |
}
|
williamr@2
|
331 |
|
williamr@2
|
332 |
explicit multimap(const _Compare& __comp,
|
williamr@2
|
333 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
334 |
: _M_t(__comp, __a) {
|
williamr@2
|
335 |
_STLP_POP_IF_CHECK
|
williamr@2
|
336 |
}
|
williamr@2
|
337 |
|
williamr@2
|
338 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
339 |
template <class _InputIterator>
|
williamr@2
|
340 |
multimap(_InputIterator __first, _InputIterator __last)
|
williamr@2
|
341 |
: _M_t(_Compare(), allocator_type())
|
williamr@2
|
342 |
{
|
williamr@2
|
343 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
344 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
345 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
346 |
}
|
williamr@2
|
347 |
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
|
williamr@2
|
348 |
template <class _InputIterator>
|
williamr@2
|
349 |
multimap(_InputIterator __first, _InputIterator __last,
|
williamr@2
|
350 |
const _Compare& __comp)
|
williamr@2
|
351 |
: _M_t(__comp, allocator_type()) {
|
williamr@2
|
352 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
353 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
354 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
355 |
}
|
williamr@2
|
356 |
# endif
|
williamr@2
|
357 |
template <class _InputIterator>
|
williamr@2
|
358 |
multimap(_InputIterator __first, _InputIterator __last,
|
williamr@2
|
359 |
const _Compare& __comp,
|
williamr@2
|
360 |
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
|
williamr@2
|
361 |
: _M_t(__comp, __a) {
|
williamr@2
|
362 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
363 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
364 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
365 |
}
|
williamr@2
|
366 |
#else
|
williamr@2
|
367 |
multimap(const value_type* __first, const value_type* __last)
|
williamr@2
|
368 |
: _M_t(_Compare(), allocator_type())
|
williamr@2
|
369 |
{
|
williamr@2
|
370 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
371 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
372 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
373 |
}
|
williamr@2
|
374 |
multimap(const value_type* __first, const value_type* __last,
|
williamr@2
|
375 |
const _Compare& __comp,
|
williamr@2
|
376 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
377 |
: _M_t(__comp, __a) {
|
williamr@2
|
378 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
379 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
380 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
381 |
}
|
williamr@2
|
382 |
|
williamr@2
|
383 |
multimap(const_iterator __first, const_iterator __last)
|
williamr@2
|
384 |
: _M_t(_Compare(), allocator_type())
|
williamr@2
|
385 |
{
|
williamr@2
|
386 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
387 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
388 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
389 |
}
|
williamr@2
|
390 |
multimap(const_iterator __first, const_iterator __last,
|
williamr@2
|
391 |
const _Compare& __comp,
|
williamr@2
|
392 |
const allocator_type& __a = allocator_type())
|
williamr@2
|
393 |
: _M_t(__comp, __a) {
|
williamr@2
|
394 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
395 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
396 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
397 |
|
williamr@2
|
398 |
}
|
williamr@2
|
399 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
400 |
|
williamr@2
|
401 |
|
williamr@2
|
402 |
# ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
403 |
multimap(const multimap<_Key,_Tp,_Compare,_Alloc>& __x)
|
williamr@2
|
404 |
{
|
williamr@2
|
405 |
_STLP_PUSH_CLEANUP_ITEM(_Self, this)
|
williamr@2
|
406 |
_M_t =__x._M_t;
|
williamr@2
|
407 |
_STLP_POP_CLEANUP_ITEM
|
williamr@2
|
408 |
}
|
williamr@2
|
409 |
# else
|
williamr@2
|
410 |
multimap(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {
|
williamr@2
|
411 |
}
|
williamr@2
|
412 |
# endif
|
williamr@2
|
413 |
multimap<_Key,_Tp,_Compare,_Alloc>&
|
williamr@2
|
414 |
operator=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) {
|
williamr@2
|
415 |
_M_t = __x._M_t;
|
williamr@2
|
416 |
return *this;
|
williamr@2
|
417 |
}
|
williamr@2
|
418 |
|
williamr@2
|
419 |
#ifdef _STLP_USE_TRAP_LEAVE
|
williamr@2
|
420 |
public:
|
williamr@2
|
421 |
static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
422 |
static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
|
williamr@2
|
423 |
#endif
|
williamr@2
|
424 |
|
williamr@2
|
425 |
// accessors:
|
williamr@2
|
426 |
|
williamr@2
|
427 |
key_compare key_comp() const { return _M_t.key_comp(); }
|
williamr@2
|
428 |
value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
|
williamr@2
|
429 |
allocator_type get_allocator() const { return _M_t.get_allocator(); }
|
williamr@2
|
430 |
|
williamr@2
|
431 |
iterator begin() { return _M_t.begin(); }
|
williamr@2
|
432 |
const_iterator begin() const { return _M_t.begin(); }
|
williamr@2
|
433 |
iterator end() { return _M_t.end(); }
|
williamr@2
|
434 |
const_iterator end() const { return _M_t.end(); }
|
williamr@2
|
435 |
reverse_iterator rbegin() { return _M_t.rbegin(); }
|
williamr@2
|
436 |
const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
|
williamr@2
|
437 |
reverse_iterator rend() { return _M_t.rend(); }
|
williamr@2
|
438 |
const_reverse_iterator rend() const { return _M_t.rend(); }
|
williamr@2
|
439 |
bool empty() const { return _M_t.empty(); }
|
williamr@2
|
440 |
size_type size() const { return _M_t.size(); }
|
williamr@2
|
441 |
size_type max_size() const { return _M_t.max_size(); }
|
williamr@2
|
442 |
void swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
|
williamr@2
|
443 |
|
williamr@2
|
444 |
// insert/erase
|
williamr@2
|
445 |
|
williamr@2
|
446 |
iterator insert(const value_type& __x) { return _M_t.insert_equal(__x); }
|
williamr@2
|
447 |
iterator insert(iterator __position, const value_type& __x) {
|
williamr@2
|
448 |
return _M_t.insert_equal(__position, __x);
|
williamr@2
|
449 |
}
|
williamr@2
|
450 |
#ifdef _STLP_MEMBER_TEMPLATES
|
williamr@2
|
451 |
template <class _InputIterator>
|
williamr@2
|
452 |
void insert(_InputIterator __first, _InputIterator __last) {
|
williamr@2
|
453 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
454 |
}
|
williamr@2
|
455 |
#else
|
williamr@2
|
456 |
void insert(const value_type* __first, const value_type* __last) {
|
williamr@2
|
457 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
458 |
}
|
williamr@2
|
459 |
void insert(const_iterator __first, const_iterator __last) {
|
williamr@2
|
460 |
_M_t.insert_equal(__first, __last);
|
williamr@2
|
461 |
}
|
williamr@2
|
462 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@2
|
463 |
void erase(iterator __position) { _M_t.erase(__position); }
|
williamr@2
|
464 |
size_type erase(const key_type& __x) { return _M_t.erase(__x); }
|
williamr@2
|
465 |
void erase(iterator __first, iterator __last)
|
williamr@2
|
466 |
{ _M_t.erase(__first, __last); }
|
williamr@2
|
467 |
void clear() { _M_t.clear(); }
|
williamr@2
|
468 |
|
williamr@2
|
469 |
// multimap operations:
|
williamr@2
|
470 |
|
williamr@2
|
471 |
iterator find(const key_type& __x) { return _M_t.find(__x); }
|
williamr@2
|
472 |
const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
|
williamr@2
|
473 |
size_type count(const key_type& __x) const { return _M_t.count(__x); }
|
williamr@2
|
474 |
iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
|
williamr@2
|
475 |
const_iterator lower_bound(const key_type& __x) const {
|
williamr@2
|
476 |
return _M_t.lower_bound(__x);
|
williamr@2
|
477 |
}
|
williamr@2
|
478 |
iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
|
williamr@2
|
479 |
const_iterator upper_bound(const key_type& __x) const {
|
williamr@2
|
480 |
return _M_t.upper_bound(__x);
|
williamr@2
|
481 |
}
|
williamr@2
|
482 |
pair<iterator,iterator> equal_range(const key_type& __x) {
|
williamr@2
|
483 |
return _M_t.equal_range(__x);
|
williamr@2
|
484 |
}
|
williamr@2
|
485 |
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
|
williamr@2
|
486 |
return _M_t.equal_range(__x);
|
williamr@2
|
487 |
}
|
williamr@2
|
488 |
};
|
williamr@2
|
489 |
|
williamr@2
|
490 |
# define _STLP_TEMPLATE_HEADER template <class _Key, class _Tp, class _Compare, class _Alloc>
|
williamr@2
|
491 |
|
williamr@2
|
492 |
# define _STLP_TEMPLATE_CONTAINER map<_Key,_Tp,_Compare,_Alloc>
|
williamr@2
|
493 |
|
williamr@2
|
494 |
// fbp : if this template header gets protected against your will, report it !
|
williamr@2
|
495 |
# include <stl/_relops_cont.h>
|
williamr@2
|
496 |
|
williamr@2
|
497 |
# undef _STLP_TEMPLATE_CONTAINER
|
williamr@2
|
498 |
# define _STLP_TEMPLATE_CONTAINER multimap<_Key,_Tp,_Compare,_Alloc>
|
williamr@2
|
499 |
|
williamr@2
|
500 |
// fbp : if this template header gets protected against your will, report it !
|
williamr@2
|
501 |
# include <stl/_relops_cont.h>
|
williamr@2
|
502 |
|
williamr@2
|
503 |
# undef _STLP_TEMPLATE_CONTAINER
|
williamr@2
|
504 |
# undef _STLP_TEMPLATE_HEADER
|
williamr@2
|
505 |
|
williamr@2
|
506 |
_STLP_END_NAMESPACE
|
williamr@2
|
507 |
|
williamr@2
|
508 |
// do a cleanup
|
williamr@2
|
509 |
# undef map
|
williamr@2
|
510 |
# undef multimap
|
williamr@2
|
511 |
// provide a way to access full funclionality
|
williamr@2
|
512 |
# define __map__ __FULL_NAME(map)
|
williamr@2
|
513 |
# define __multimap__ __FULL_NAME(multimap)
|
williamr@2
|
514 |
|
williamr@2
|
515 |
# ifdef _STLP_USE_WRAPPER_FOR_ALLOC_PARAM
|
williamr@2
|
516 |
# include <stl/wrappers/_map.h>
|
williamr@2
|
517 |
# endif
|
williamr@2
|
518 |
|
williamr@2
|
519 |
#endif /* _STLP_INTERNAL_MAP_H */
|
williamr@2
|
520 |
|
williamr@2
|
521 |
// Local Variables:
|
williamr@2
|
522 |
// mode:C++
|
williamr@2
|
523 |
// End:
|
williamr@2
|
524 |
|