]>
Commit | Line | Data |
---|---|---|
42526146 PE |
1 | // Map implementation -*- C++ -*- |
2 | ||
fd58f127 | 3 | // Copyright (C) 2001, 2002 Free Software Foundation, Inc. |
42526146 PE |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
8 | // Free Software Foundation; either version 2, or (at your option) | |
9 | // any later version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License along | |
17 | // with this library; see the file COPYING. If not, write to the Free | |
18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
19 | // USA. | |
20 | ||
21 | // As a special exception, you may use this file as part of a free software | |
22 | // library without restriction. Specifically, if other files instantiate | |
23 | // templates or use macros or inline functions from this file, or you compile | |
24 | // this file and link it with other files to produce an executable, this | |
25 | // file does not by itself cause the resulting executable to be covered by | |
26 | // the GNU General Public License. This exception does not however | |
27 | // invalidate any other reasons why the executable file might be covered by | |
28 | // the GNU General Public License. | |
29 | ||
725dc051 BK |
30 | /* |
31 | * | |
32 | * Copyright (c) 1994 | |
33 | * Hewlett-Packard Company | |
34 | * | |
35 | * Permission to use, copy, modify, distribute and sell this software | |
36 | * and its documentation for any purpose is hereby granted without fee, | |
37 | * provided that the above copyright notice appear in all copies and | |
38 | * that both that copyright notice and this permission notice appear | |
39 | * in supporting documentation. Hewlett-Packard Company makes no | |
40 | * representations about the suitability of this software for any | |
41 | * purpose. It is provided "as is" without express or implied warranty. | |
42 | * | |
43 | * | |
44 | * Copyright (c) 1996,1997 | |
45 | * Silicon Graphics Computer Systems, Inc. | |
46 | * | |
47 | * Permission to use, copy, modify, distribute and sell this software | |
48 | * and its documentation for any purpose is hereby granted without fee, | |
49 | * provided that the above copyright notice appear in all copies and | |
50 | * that both that copyright notice and this permission notice appear | |
51 | * in supporting documentation. Silicon Graphics makes no | |
52 | * representations about the suitability of this software for any | |
53 | * purpose. It is provided "as is" without express or implied warranty. | |
54 | */ | |
55 | ||
729e3d3f PE |
56 | /** @file stl_map.h |
57 | * This is an internal header file, included by other library headers. | |
58 | * You should not attempt to use it directly. | |
725dc051 BK |
59 | */ |
60 | ||
3d7c150e BK |
61 | #ifndef _MAP_H |
62 | #define _MAP_H 1 | |
725dc051 | 63 | |
30a20a1e | 64 | #include <bits/concept_check.h> |
725dc051 | 65 | |
d53d7f6e PE |
66 | namespace std |
67 | { | |
224a45d0 | 68 | /** |
3971a4d2 PE |
69 | * @brief A standard container made up of (key,value) pairs, which can be |
70 | * retrieved based on a key, in logarithmic time. | |
224a45d0 | 71 | * |
3971a4d2 PE |
72 | * @ingroup Containers |
73 | * @ingroup Assoc_containers | |
224a45d0 | 74 | * |
3971a4d2 PE |
75 | * Meets the requirements of a <a href="tables.html#65">container</a>, a |
76 | * <a href="tables.html#66">reversible container</a>, and an | |
77 | * <a href="tables.html#69">associative container</a> (using unique keys). | |
78 | * For a @c map<Key,T> the key_type is Key, the mapped_type is T, and the | |
79 | * value_type is std::pair<const Key,T>. | |
224a45d0 | 80 | * |
3971a4d2 | 81 | * Maps support bidirectional iterators. |
224a45d0 | 82 | * |
3971a4d2 PE |
83 | * @if maint |
84 | * The private tree data is declared exactly the same way for map and | |
85 | * multimap; the distinction is made entirely in how the tree functions are | |
86 | * called (*_unique versus *_equal, same as the standard). | |
87 | * @endif | |
88 | */ | |
89 | template <typename _Key, typename _Tp, typename _Compare = less<_Key>, | |
90 | typename _Alloc = allocator<pair<const _Key, _Tp> > > | |
91 | class map | |
224a45d0 PE |
92 | { |
93 | // concept requirements | |
3d7c150e BK |
94 | __glibcxx_class_requires(_Tp, _SGIAssignableConcept) |
95 | __glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept) | |
3971a4d2 PE |
96 | |
97 | public: | |
98 | typedef _Key key_type; | |
99 | typedef _Tp mapped_type; | |
100 | typedef pair<const _Key, _Tp> value_type; | |
101 | typedef _Compare key_compare; | |
102 | ||
103 | class value_compare | |
104 | : public binary_function<value_type, value_type, bool> | |
105 | { | |
106 | friend class map<_Key,_Tp,_Compare,_Alloc>; | |
107 | protected: | |
108 | _Compare comp; | |
109 | value_compare(_Compare __c) : comp(__c) {} | |
110 | public: | |
111 | bool operator()(const value_type& __x, const value_type& __y) const | |
6dc5fdfd | 112 | { return comp(__x.first, __y.first); } |
3971a4d2 PE |
113 | }; |
114 | ||
115 | private: | |
116 | /// @if maint This turns a red-black tree into a [multi]map. @endif | |
117 | typedef _Rb_tree<key_type, value_type, | |
118 | _Select1st<value_type>, key_compare, _Alloc> _Rep_type; | |
119 | /// @if maint The actual tree structure. @endif | |
120 | _Rep_type _M_t; | |
121 | ||
122 | public: | |
123 | // many of these are specified differently in ISO, but the following are | |
124 | // "functionally equivalent" | |
125 | typedef typename _Rep_type::allocator_type allocator_type; | |
126 | typedef typename _Rep_type::reference reference; | |
127 | typedef typename _Rep_type::const_reference const_reference; | |
128 | typedef typename _Rep_type::iterator iterator; | |
129 | typedef typename _Rep_type::const_iterator const_iterator; | |
130 | typedef typename _Rep_type::size_type size_type; | |
131 | typedef typename _Rep_type::difference_type difference_type; | |
132 | typedef typename _Rep_type::pointer pointer; | |
133 | typedef typename _Rep_type::const_pointer const_pointer; | |
134 | typedef typename _Rep_type::reverse_iterator reverse_iterator; | |
135 | typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; | |
136 | ||
137 | ||
138 | // [23.3.1.1] construct/copy/destroy | |
139 | // (get_allocator() is normally listed in this section, but seems to have | |
140 | // been accidentally omitted in the printed standard) | |
141 | /** | |
142 | * @brief Default constructor creates no elements. | |
143 | */ | |
144 | map() : _M_t(_Compare(), allocator_type()) { } | |
145 | ||
146 | // for some reason this was made a separate function | |
147 | /** | |
148 | * @brief Default constructor creates no elements. | |
149 | */ | |
150 | explicit | |
151 | map(const _Compare& __comp, const allocator_type& __a = allocator_type()) | |
152 | : _M_t(__comp, __a) { } | |
153 | ||
154 | /** | |
155 | * @brief Map copy constructor. | |
156 | * @param x A %map of identical element and allocator types. | |
157 | * | |
158 | * The newly-created %map uses a copy of the allocation object used | |
159 | * by @a x. | |
160 | */ | |
161 | map(const map& __x) | |
162 | : _M_t(__x._M_t) { } | |
163 | ||
164 | /** | |
165 | * @brief Builds a %map from a range. | |
166 | * @param first An input iterator. | |
167 | * @param last An input iterator. | |
168 | * | |
169 | * Create a %map consisting of copies of the elements from [first,last). | |
170 | * This is linear in N if the range is already sorted, and NlogN | |
171 | * otherwise (where N is distance(first,last)). | |
172 | */ | |
173 | template <typename _InputIterator> | |
174 | map(_InputIterator __first, _InputIterator __last) | |
175 | : _M_t(_Compare(), allocator_type()) | |
224a45d0 | 176 | { _M_t.insert_unique(__first, __last); } |
3971a4d2 PE |
177 | |
178 | /** | |
179 | * @brief Builds a %map from a range. | |
180 | * @param first An input iterator. | |
181 | * @param last An input iterator. | |
182 | * @param comp A comparison functor. | |
183 | * @param a An allocator object. | |
184 | * | |
185 | * Create a %map consisting of copies of the elements from [first,last). | |
186 | * This is linear in N if the range is already sorted, and NlogN | |
187 | * otherwise (where N is distance(first,last)). | |
188 | */ | |
189 | template <typename _InputIterator> | |
190 | map(_InputIterator __first, _InputIterator __last, | |
191 | const _Compare& __comp, const allocator_type& __a = allocator_type()) | |
192 | : _M_t(__comp, __a) | |
193 | { _M_t.insert_unique(__first, __last); } | |
194 | ||
195 | // FIXME There is no dtor declared, but we should have something generated | |
196 | // by Doxygen. I don't know what tags to add to this paragraph to make | |
197 | // that happen: | |
198 | /** | |
199 | * The dtor only erases the elements, and note that if the elements | |
200 | * themselves are pointers, the pointed-to memory is not touched in any | |
201 | * way. Managing the pointer is the user's responsibilty. | |
202 | */ | |
203 | ||
204 | /** | |
205 | * @brief Map assignment operator. | |
206 | * @param x A %map of identical element and allocator types. | |
207 | * | |
208 | * All the elements of @a x are copied, but unlike the copy constructor, | |
209 | * the allocator object is not copied. | |
210 | */ | |
211 | map& | |
212 | operator=(const map& __x) | |
213 | { | |
214 | _M_t = __x._M_t; | |
215 | return *this; | |
216 | } | |
217 | ||
218 | /// Get a copy of the memory allocation object. | |
219 | allocator_type | |
220 | get_allocator() const { return _M_t.get_allocator(); } | |
221 | ||
222 | // iterators | |
223 | /** | |
224 | * Returns a read/write iterator that points to the first pair in the %map. | |
225 | * Iteration is done in ascending order according to the keys. | |
226 | */ | |
227 | iterator | |
228 | begin() { return _M_t.begin(); } | |
229 | ||
230 | /** | |
231 | * Returns a read-only (constant) iterator that points to the first pair | |
232 | * in the %map. Iteration is done in ascending order according to the | |
233 | * keys. | |
234 | */ | |
235 | const_iterator | |
236 | begin() const { return _M_t.begin(); } | |
237 | ||
238 | /** | |
239 | * Returns a read/write iterator that points one past the last pair in the | |
240 | * %map. Iteration is done in ascending order according to the keys. | |
241 | */ | |
242 | iterator | |
243 | end() { return _M_t.end(); } | |
244 | ||
245 | /** | |
246 | * Returns a read-only (constant) iterator that points one past the last | |
247 | * pair in the %map. Iteration is done in ascending order according to the | |
248 | * keys. | |
249 | */ | |
250 | const_iterator | |
251 | end() const { return _M_t.end(); } | |
252 | ||
253 | /** | |
254 | * Returns a read/write reverse iterator that points to the last pair in | |
255 | * the %map. Iteration is done in descending order according to the keys. | |
256 | */ | |
257 | reverse_iterator | |
258 | rbegin() { return _M_t.rbegin(); } | |
259 | ||
260 | /** | |
261 | * Returns a read-only (constant) reverse iterator that points to the last | |
262 | * pair in the %map. Iteration is done in descending order according to | |
263 | * the keys. | |
264 | */ | |
265 | const_reverse_iterator | |
266 | rbegin() const { return _M_t.rbegin(); } | |
267 | ||
268 | /** | |
269 | * Returns a read/write reverse iterator that points to one before the | |
270 | * first pair in the %map. Iteration is done in descending order according | |
271 | * to the keys. | |
272 | */ | |
273 | reverse_iterator | |
274 | rend() { return _M_t.rend(); } | |
275 | ||
276 | /** | |
277 | * Returns a read-only (constant) reverse iterator that points to one | |
278 | * before the first pair in the %map. Iteration is done in descending | |
279 | * order according to the keys. | |
280 | */ | |
281 | const_reverse_iterator | |
282 | rend() const { return _M_t.rend(); } | |
283 | ||
284 | // capacity | |
285 | /** Returns true if the %map is empty. (Thus begin() would equal end().) */ | |
286 | bool | |
287 | empty() const { return _M_t.empty(); } | |
288 | ||
289 | /** Returns the size of the %map. */ | |
290 | size_type | |
291 | size() const { return _M_t.size(); } | |
292 | ||
293 | /** Returns the maximum size of the %map. */ | |
294 | size_type | |
295 | max_size() const { return _M_t.max_size(); } | |
296 | ||
297 | // [23.3.1.2] element access | |
298 | /** | |
299 | * @brief Subscript ( @c [] ) access to %map data. | |
300 | * @param k The key for which data should be retrieved. | |
301 | * @return A reference to the data of the (key,data) %pair. | |
302 | * | |
303 | * Allows for easy lookup with the subscript ( @c [] ) operator. Returns | |
304 | * data associated with the key specified in subscript. If the key does | |
305 | * not exist, a pair with that key is created using default values, which | |
306 | * is then returned. | |
307 | * | |
308 | * Lookup requires logarithmic time. | |
309 | */ | |
310 | mapped_type& | |
311 | operator[](const key_type& __k) | |
312 | { | |
313 | // concept requirements | |
3d7c150e | 314 | __glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) |
3971a4d2 PE |
315 | |
316 | iterator __i = lower_bound(__k); | |
317 | // __i->first is greater than or equivalent to __k. | |
318 | if (__i == end() || key_comp()(__k, (*__i).first)) | |
319 | __i = insert(__i, value_type(__k, mapped_type())); | |
320 | return (*__i).second; | |
321 | } | |
322 | ||
323 | // modifiers | |
324 | /** | |
325 | * @brief Attempts to insert a std::pair into the %map. | |
326 | * @param x Pair to be inserted (see std::make_pair for easy creation of | |
327 | * pairs). | |
328 | * @return A pair, of which the first element is an iterator that points | |
329 | * to the possibly inserted pair, and the second is a bool that | |
330 | * is true if the pair was actually inserted. | |
331 | * | |
332 | * This function attempts to insert a (key, value) %pair into the %map. | |
333 | * A %map relies on unique keys and thus a %pair is only inserted if its | |
334 | * first element (the key) is not already present in the %map. | |
335 | * | |
336 | * Insertion requires logarithmic time. | |
337 | */ | |
338 | pair<iterator,bool> | |
339 | insert(const value_type& __x) | |
6dc5fdfd | 340 | { return _M_t.insert_unique(__x); } |
3971a4d2 PE |
341 | |
342 | /** | |
343 | * @brief Attempts to insert a std::pair into the %map. | |
344 | * @param position An iterator that serves as a hint as to where the | |
345 | * pair should be inserted. | |
346 | * @param x Pair to be inserted (see std::make_pair for easy creation of | |
347 | * pairs). | |
348 | * @return An iterator that points to the element with key of @a x (may | |
349 | * or may not be the %pair passed in). | |
350 | * | |
351 | * This function is not concerned about whether the insertion took place, | |
352 | * and thus does not return a boolean like the single-argument | |
353 | * insert() does. Note that the first parameter is only a hint and can | |
354 | * potentially improve the performance of the insertion process. A bad | |
355 | * hint would cause no gains in efficiency. | |
356 | * | |
357 | * See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4 | |
358 | * for more on "hinting". | |
359 | * | |
360 | * Insertion requires logarithmic time (if the hint is not taken). | |
361 | */ | |
362 | iterator | |
363 | insert(iterator position, const value_type& __x) | |
6dc5fdfd | 364 | { return _M_t.insert_unique(position, __x); } |
3971a4d2 PE |
365 | |
366 | /** | |
367 | * @brief A template function that attemps to insert a range of elements. | |
368 | * @param first Iterator pointing to the start of the range to be | |
369 | * inserted. | |
370 | * @param last Iterator pointing to the end of the range. | |
371 | * | |
372 | * Complexity similar to that of the range constructor. | |
373 | */ | |
374 | template <typename _InputIterator> | |
375 | void | |
376 | insert(_InputIterator __first, _InputIterator __last) | |
6dc5fdfd | 377 | { _M_t.insert_unique(__first, __last); } |
3971a4d2 PE |
378 | |
379 | /** | |
380 | * @brief Erases an element from a %map. | |
381 | * @param position An iterator pointing to the element to be erased. | |
382 | * | |
383 | * This function erases an element, pointed to by the given iterator, from | |
384 | * a %map. Note that this function only erases the element, and that if | |
385 | * the element is itself a pointer, the pointed-to memory is not touched | |
386 | * in any way. Managing the pointer is the user's responsibilty. | |
387 | */ | |
388 | void | |
389 | erase(iterator __position) { _M_t.erase(__position); } | |
390 | ||
391 | /** | |
392 | * @brief Erases elements according to the provided key. | |
393 | * @param x Key of element to be erased. | |
394 | * @return The number of elements erased. | |
395 | * | |
396 | * This function erases all the elements located by the given key from | |
397 | * a %map. | |
398 | * Note that this function only erases the element, and that if | |
399 | * the element is itself a pointer, the pointed-to memory is not touched | |
400 | * in any way. Managing the pointer is the user's responsibilty. | |
401 | */ | |
402 | size_type | |
403 | erase(const key_type& __x) { return _M_t.erase(__x); } | |
404 | ||
405 | /** | |
406 | * @brief Erases a [first,last) range of elements from a %map. | |
407 | * @param first Iterator pointing to the start of the range to be erased. | |
408 | * @param last Iterator pointing to the end of the range to be erased. | |
409 | * | |
410 | * This function erases a sequence of elements from a %map. | |
411 | * Note that this function only erases the element, and that if | |
412 | * the element is itself a pointer, the pointed-to memory is not touched | |
413 | * in any way. Managing the pointer is the user's responsibilty. | |
414 | */ | |
415 | void | |
416 | erase(iterator __first, iterator __last) { _M_t.erase(__first, __last); } | |
417 | ||
418 | /** | |
419 | * @brief Swaps data with another %map. | |
420 | * @param x A %map of the same element and allocator types. | |
421 | * | |
422 | * This exchanges the elements between two maps in constant time. | |
423 | * (It is only swapping a pointer, an integer, and an instance of | |
424 | * the @c Compare type (which itself is often stateless and empty), so it | |
425 | * should be quite fast.) | |
426 | * Note that the global std::swap() function is specialized such that | |
427 | * std::swap(m1,m2) will feed to this function. | |
428 | */ | |
429 | void | |
430 | swap(map& __x) { _M_t.swap(__x._M_t); } | |
431 | ||
432 | /** | |
433 | * Erases all elements in a %map. Note that this function only erases | |
434 | * the elements, and that if the elements themselves are pointers, the | |
435 | * pointed-to memory is not touched in any way. Managing the pointer is | |
436 | * the user's responsibilty. | |
437 | */ | |
438 | void | |
439 | clear() { _M_t.clear(); } | |
440 | ||
441 | // observers | |
442 | /** | |
443 | * Returns the key comparison object out of which the %map was constructed. | |
444 | */ | |
445 | key_compare | |
446 | key_comp() const { return _M_t.key_comp(); } | |
447 | ||
448 | /** | |
449 | * Returns a value comparison object, built from the key comparison | |
450 | * object out of which the %map was constructed. | |
451 | */ | |
452 | value_compare | |
453 | value_comp() const { return value_compare(_M_t.key_comp()); } | |
454 | ||
455 | // [23.3.1.3] map operations | |
456 | /** | |
457 | * @brief Tries to locate an element in a %map. | |
458 | * @param x Key of (key, value) %pair to be located. | |
459 | * @return Iterator pointing to sought-after element, or end() if not | |
460 | * found. | |
461 | * | |
462 | * This function takes a key and tries to locate the element with which | |
463 | * the key matches. If successful the function returns an iterator | |
464 | * pointing to the sought after %pair. If unsuccessful it returns the | |
465 | * past-the-end ( @c end() ) iterator. | |
466 | */ | |
467 | iterator | |
468 | find(const key_type& __x) { return _M_t.find(__x); } | |
469 | ||
470 | /** | |
471 | * @brief Tries to locate an element in a %map. | |
472 | * @param x Key of (key, value) %pair to be located. | |
473 | * @return Read-only (constant) iterator pointing to sought-after | |
474 | * element, or end() if not found. | |
475 | * | |
476 | * This function takes a key and tries to locate the element with which | |
477 | * the key matches. If successful the function returns a constant iterator | |
478 | * pointing to the sought after %pair. If unsuccessful it returns the | |
479 | * past-the-end ( @c end() ) iterator. | |
480 | */ | |
481 | const_iterator | |
482 | find(const key_type& __x) const { return _M_t.find(__x); } | |
483 | ||
484 | /** | |
485 | * @brief Finds the number of elements with given key. | |
486 | * @param x Key of (key, value) pairs to be located. | |
487 | * @return Number of elements with specified key. | |
488 | * | |
489 | * This function only makes sense for multimaps; for map the result will | |
490 | * either be 0 (not present) or 1 (present). | |
491 | */ | |
492 | size_type | |
493 | count(const key_type& __x) const | |
6dc5fdfd | 494 | { return _M_t.find(__x) == _M_t.end() ? 0 : 1; } |
3971a4d2 PE |
495 | |
496 | /** | |
497 | * @brief Finds the beginning of a subsequence matching given key. | |
498 | * @param x Key of (key, value) pair to be located. | |
63b1a6ba SS |
499 | * @return Iterator pointing to first element equal to or greater |
500 | * than key, or end(). | |
3971a4d2 | 501 | * |
63b1a6ba SS |
502 | * This function returns the first element of a subsequence of elements |
503 | * that matches the given key. If unsuccessful it returns an iterator | |
504 | * pointing to the first element that has a greater value than given key | |
505 | * or end() if no such element exists. | |
3971a4d2 PE |
506 | */ |
507 | iterator | |
508 | lower_bound(const key_type& __x) { return _M_t.lower_bound(__x); } | |
509 | ||
510 | /** | |
511 | * @brief Finds the beginning of a subsequence matching given key. | |
512 | * @param x Key of (key, value) pair to be located. | |
513 | * @return Read-only (constant) iterator pointing to first element | |
63b1a6ba | 514 | * equal to or greater than key, or end(). |
3971a4d2 | 515 | * |
63b1a6ba SS |
516 | * This function returns the first element of a subsequence of elements |
517 | * that matches the given key. If unsuccessful it returns an iterator | |
518 | * pointing to the first element that has a greater value than given key | |
519 | * or end() if no such element exists. | |
3971a4d2 PE |
520 | */ |
521 | const_iterator | |
522 | lower_bound(const key_type& __x) const { return _M_t.lower_bound(__x); } | |
523 | ||
524 | /** | |
525 | * @brief Finds the end of a subsequence matching given key. | |
526 | * @param x Key of (key, value) pair to be located. | |
63b1a6ba SS |
527 | * @return Iterator pointing to the first element |
528 | * greater than key, or end(). | |
3971a4d2 PE |
529 | */ |
530 | iterator | |
531 | upper_bound(const key_type& __x) { return _M_t.upper_bound(__x); } | |
532 | ||
533 | /** | |
534 | * @brief Finds the end of a subsequence matching given key. | |
535 | * @param x Key of (key, value) pair to be located. | |
63b1a6ba SS |
536 | * @return Read-only (constant) iterator pointing to first iterator |
537 | * greater than key, or end(). | |
3971a4d2 PE |
538 | */ |
539 | const_iterator | |
540 | upper_bound(const key_type& __x) const | |
6dc5fdfd | 541 | { return _M_t.upper_bound(__x); } |
3971a4d2 PE |
542 | |
543 | /** | |
544 | * @brief Finds a subsequence matching given key. | |
545 | * @param x Key of (key, value) pairs to be located. | |
546 | * @return Pair of iterators that possibly points to the subsequence | |
547 | * matching given key. | |
548 | * | |
63b1a6ba SS |
549 | * This function is equivalent to |
550 | * @code | |
551 | * std::make_pair(c.lower_bound(val), | |
552 | * c.upper_bound(val)) | |
553 | * @endcode | |
554 | * (but is faster than making the calls separately). | |
3971a4d2 | 555 | * |
63b1a6ba | 556 | * This function probably only makes sense for multimaps. |
3971a4d2 PE |
557 | */ |
558 | pair<iterator,iterator> | |
559 | equal_range(const key_type& __x) | |
6dc5fdfd | 560 | { return _M_t.equal_range(__x); } |
3971a4d2 PE |
561 | |
562 | /** | |
563 | * @brief Finds a subsequence matching given key. | |
564 | * @param x Key of (key, value) pairs to be located. | |
565 | * @return Pair of read-only (constant) iterators that possibly points to | |
566 | * the subsequence matching given key. | |
567 | * | |
63b1a6ba SS |
568 | * This function is equivalent to |
569 | * @code | |
570 | * std::make_pair(c.lower_bound(val), | |
571 | * c.upper_bound(val)) | |
572 | * @endcode | |
573 | * (but is faster than making the calls separately). | |
3971a4d2 | 574 | * |
63b1a6ba | 575 | * This function probably only makes sense for multimaps. |
3971a4d2 PE |
576 | */ |
577 | pair<const_iterator,const_iterator> | |
578 | equal_range(const key_type& __x) const | |
6dc5fdfd | 579 | { return _M_t.equal_range(__x); } |
3971a4d2 PE |
580 | |
581 | template <typename _K1, typename _T1, typename _C1, typename _A1> | |
582 | friend bool operator== (const map<_K1,_T1,_C1,_A1>&, | |
583 | const map<_K1,_T1,_C1,_A1>&); | |
584 | template <typename _K1, typename _T1, typename _C1, typename _A1> | |
585 | friend bool operator< (const map<_K1,_T1,_C1,_A1>&, | |
586 | const map<_K1,_T1,_C1,_A1>&); | |
587 | }; | |
588 | ||
589 | ||
590 | /** | |
591 | * @brief Map equality comparison. | |
592 | * @param x A %map. | |
593 | * @param y A %map of the same type as @a x. | |
594 | * @return True iff the size and elements of the maps are equal. | |
fd58f127 | 595 | * |
3971a4d2 PE |
596 | * This is an equivalence relation. It is linear in the size of the |
597 | * maps. Maps are considered equivalent if their sizes are equal, | |
598 | * and if corresponding elements compare equal. | |
599 | */ | |
600 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> | |
601 | inline bool | |
602 | operator==(const map<_Key,_Tp,_Compare,_Alloc>& __x, | |
603 | const map<_Key,_Tp,_Compare,_Alloc>& __y) | |
604 | { return __x._M_t == __y._M_t; } | |
605 | ||
606 | /** | |
607 | * @brief Map ordering relation. | |
608 | * @param x A %map. | |
609 | * @param y A %map of the same type as @a x. | |
9536ca34 | 610 | * @return True iff @a x is lexicographically less than @a y. |
fd58f127 | 611 | * |
3971a4d2 PE |
612 | * This is a total ordering relation. It is linear in the size of the |
613 | * maps. The elements must be comparable with @c <. | |
fd58f127 | 614 | * |
9536ca34 | 615 | * See std::lexicographical_compare() for how the determination is made. |
3971a4d2 PE |
616 | */ |
617 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> | |
618 | inline bool | |
619 | operator<(const map<_Key,_Tp,_Compare,_Alloc>& __x, | |
620 | const map<_Key,_Tp,_Compare,_Alloc>& __y) | |
621 | { return __x._M_t < __y._M_t; } | |
622 | ||
623 | /// Based on operator== | |
624 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> | |
625 | inline bool | |
626 | operator!=(const map<_Key,_Tp,_Compare,_Alloc>& __x, | |
627 | const map<_Key,_Tp,_Compare,_Alloc>& __y) | |
628 | { return !(__x == __y); } | |
629 | ||
630 | /// Based on operator< | |
631 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> | |
632 | inline bool | |
633 | operator>(const map<_Key,_Tp,_Compare,_Alloc>& __x, | |
634 | const map<_Key,_Tp,_Compare,_Alloc>& __y) | |
635 | { return __y < __x; } | |
636 | ||
637 | /// Based on operator< | |
638 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> | |
639 | inline bool | |
640 | operator<=(const map<_Key,_Tp,_Compare,_Alloc>& __x, | |
641 | const map<_Key,_Tp,_Compare,_Alloc>& __y) | |
642 | { return !(__y < __x); } | |
643 | ||
644 | /// Based on operator< | |
645 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> | |
646 | inline bool | |
647 | operator>=(const map<_Key,_Tp,_Compare,_Alloc>& __x, | |
648 | const map<_Key,_Tp,_Compare,_Alloc>& __y) | |
649 | { return !(__x < __y); } | |
650 | ||
651 | /// See std::map::swap(). | |
652 | template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> | |
653 | inline void | |
654 | swap(map<_Key,_Tp,_Compare,_Alloc>& __x, map<_Key,_Tp,_Compare,_Alloc>& __y) | |
655 | { __x.swap(__y); } | |
d53d7f6e | 656 | } // namespace std |
725dc051 | 657 | |
3d7c150e | 658 | #endif /* _MAP_H */ |