libstdc++
|
00001 // Set implementation -*- C++ -*- 00002 00003 // Copyright (C) 2001-2013 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /* 00026 * 00027 * Copyright (c) 1994 00028 * Hewlett-Packard Company 00029 * 00030 * Permission to use, copy, modify, distribute and sell this software 00031 * and its documentation for any purpose is hereby granted without fee, 00032 * provided that the above copyright notice appear in all copies and 00033 * that both that copyright notice and this permission notice appear 00034 * in supporting documentation. Hewlett-Packard Company makes no 00035 * representations about the suitability of this software for any 00036 * purpose. It is provided "as is" without express or implied warranty. 00037 * 00038 * 00039 * Copyright (c) 1996,1997 00040 * Silicon Graphics Computer Systems, Inc. 00041 * 00042 * Permission to use, copy, modify, distribute and sell this software 00043 * and its documentation for any purpose is hereby granted without fee, 00044 * provided that the above copyright notice appear in all copies and 00045 * that both that copyright notice and this permission notice appear 00046 * in supporting documentation. Silicon Graphics makes no 00047 * representations about the suitability of this software for any 00048 * purpose. It is provided "as is" without express or implied warranty. 00049 */ 00050 00051 /** @file bits/stl_set.h 00052 * This is an internal header file, included by other library headers. 00053 * Do not attempt to use it directly. @headername{set} 00054 */ 00055 00056 #ifndef _STL_SET_H 00057 #define _STL_SET_H 1 00058 00059 #include <bits/concept_check.h> 00060 #if __cplusplus >= 201103L 00061 #include <initializer_list> 00062 #endif 00063 00064 namespace std _GLIBCXX_VISIBILITY(default) 00065 { 00066 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER 00067 00068 /** 00069 * @brief A standard container made up of unique keys, which can be 00070 * retrieved in logarithmic time. 00071 * 00072 * @ingroup associative_containers 00073 * 00074 * @tparam _Key Type of key objects. 00075 * @tparam _Compare Comparison function object type, defaults to less<_Key>. 00076 * @tparam _Alloc Allocator type, defaults to allocator<_Key>. 00077 * 00078 * Meets the requirements of a <a href="tables.html#65">container</a>, a 00079 * <a href="tables.html#66">reversible container</a>, and an 00080 * <a href="tables.html#69">associative container</a> (using unique keys). 00081 * 00082 * Sets support bidirectional iterators. 00083 * 00084 * The private tree data is declared exactly the same way for set and 00085 * multiset; the distinction is made entirely in how the tree functions are 00086 * called (*_unique versus *_equal, same as the standard). 00087 */ 00088 template<typename _Key, typename _Compare = std::less<_Key>, 00089 typename _Alloc = std::allocator<_Key> > 00090 class set 00091 { 00092 // concept requirements 00093 typedef typename _Alloc::value_type _Alloc_value_type; 00094 __glibcxx_class_requires(_Key, _SGIAssignableConcept) 00095 __glibcxx_class_requires4(_Compare, bool, _Key, _Key, 00096 _BinaryFunctionConcept) 00097 __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept) 00098 00099 public: 00100 // typedefs: 00101 //@{ 00102 /// Public typedefs. 00103 typedef _Key key_type; 00104 typedef _Key value_type; 00105 typedef _Compare key_compare; 00106 typedef _Compare value_compare; 00107 typedef _Alloc allocator_type; 00108 //@} 00109 00110 private: 00111 typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type; 00112 00113 typedef _Rb_tree<key_type, value_type, _Identity<value_type>, 00114 key_compare, _Key_alloc_type> _Rep_type; 00115 _Rep_type _M_t; // Red-black tree representing set. 00116 00117 public: 00118 //@{ 00119 /// Iterator-related typedefs. 00120 typedef typename _Key_alloc_type::pointer pointer; 00121 typedef typename _Key_alloc_type::const_pointer const_pointer; 00122 typedef typename _Key_alloc_type::reference reference; 00123 typedef typename _Key_alloc_type::const_reference const_reference; 00124 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00125 // DR 103. set::iterator is required to be modifiable, 00126 // but this allows modification of keys. 00127 typedef typename _Rep_type::const_iterator iterator; 00128 typedef typename _Rep_type::const_iterator const_iterator; 00129 typedef typename _Rep_type::const_reverse_iterator reverse_iterator; 00130 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; 00131 typedef typename _Rep_type::size_type size_type; 00132 typedef typename _Rep_type::difference_type difference_type; 00133 //@} 00134 00135 // allocation/deallocation 00136 /** 00137 * @brief Default constructor creates no elements. 00138 */ 00139 set() 00140 : _M_t() { } 00141 00142 /** 00143 * @brief Creates a %set with no elements. 00144 * @param __comp Comparator to use. 00145 * @param __a An allocator object. 00146 */ 00147 explicit 00148 set(const _Compare& __comp, 00149 const allocator_type& __a = allocator_type()) 00150 : _M_t(__comp, _Key_alloc_type(__a)) { } 00151 00152 /** 00153 * @brief Builds a %set from a range. 00154 * @param __first An input iterator. 00155 * @param __last An input iterator. 00156 * 00157 * Create a %set consisting of copies of the elements from 00158 * [__first,__last). This is linear in N if the range is 00159 * already sorted, and NlogN otherwise (where N is 00160 * distance(__first,__last)). 00161 */ 00162 template<typename _InputIterator> 00163 set(_InputIterator __first, _InputIterator __last) 00164 : _M_t() 00165 { _M_t._M_insert_unique(__first, __last); } 00166 00167 /** 00168 * @brief Builds a %set from a range. 00169 * @param __first An input iterator. 00170 * @param __last An input iterator. 00171 * @param __comp A comparison functor. 00172 * @param __a An allocator object. 00173 * 00174 * Create a %set consisting of copies of the elements from 00175 * [__first,__last). This is linear in N if the range is 00176 * already sorted, and NlogN otherwise (where N is 00177 * distance(__first,__last)). 00178 */ 00179 template<typename _InputIterator> 00180 set(_InputIterator __first, _InputIterator __last, 00181 const _Compare& __comp, 00182 const allocator_type& __a = allocator_type()) 00183 : _M_t(__comp, _Key_alloc_type(__a)) 00184 { _M_t._M_insert_unique(__first, __last); } 00185 00186 /** 00187 * @brief %Set copy constructor. 00188 * @param __x A %set of identical element and allocator types. 00189 * 00190 * The newly-created %set uses a copy of the allocation object used 00191 * by @a __x. 00192 */ 00193 set(const set& __x) 00194 : _M_t(__x._M_t) { } 00195 00196 #if __cplusplus >= 201103L 00197 /** 00198 * @brief %Set move constructor 00199 * @param __x A %set of identical element and allocator types. 00200 * 00201 * The newly-created %set contains the exact contents of @a x. 00202 * The contents of @a x are a valid, but unspecified %set. 00203 */ 00204 set(set&& __x) 00205 noexcept(is_nothrow_copy_constructible<_Compare>::value) 00206 : _M_t(std::move(__x._M_t)) { } 00207 00208 /** 00209 * @brief Builds a %set from an initializer_list. 00210 * @param __l An initializer_list. 00211 * @param __comp A comparison functor. 00212 * @param __a An allocator object. 00213 * 00214 * Create a %set consisting of copies of the elements in the list. 00215 * This is linear in N if the list is already sorted, and NlogN 00216 * otherwise (where N is @a __l.size()). 00217 */ 00218 set(initializer_list<value_type> __l, 00219 const _Compare& __comp = _Compare(), 00220 const allocator_type& __a = allocator_type()) 00221 : _M_t(__comp, _Key_alloc_type(__a)) 00222 { _M_t._M_insert_unique(__l.begin(), __l.end()); } 00223 #endif 00224 00225 /** 00226 * @brief %Set assignment operator. 00227 * @param __x A %set of identical element and allocator types. 00228 * 00229 * All the elements of @a __x are copied, but unlike the copy 00230 * constructor, the allocator object is not copied. 00231 */ 00232 set& 00233 operator=(const set& __x) 00234 { 00235 _M_t = __x._M_t; 00236 return *this; 00237 } 00238 00239 #if __cplusplus >= 201103L 00240 /** 00241 * @brief %Set move assignment operator. 00242 * @param __x A %set of identical element and allocator types. 00243 * 00244 * The contents of @a __x are moved into this %set (without copying). 00245 * @a __x is a valid, but unspecified %set. 00246 */ 00247 set& 00248 operator=(set&& __x) 00249 { 00250 // NB: DR 1204. 00251 // NB: DR 675. 00252 this->clear(); 00253 this->swap(__x); 00254 return *this; 00255 } 00256 00257 /** 00258 * @brief %Set list assignment operator. 00259 * @param __l An initializer_list. 00260 * 00261 * This function fills a %set with copies of the elements in the 00262 * initializer list @a __l. 00263 * 00264 * Note that the assignment completely changes the %set and 00265 * that the resulting %set's size is the same as the number 00266 * of elements assigned. Old data may be lost. 00267 */ 00268 set& 00269 operator=(initializer_list<value_type> __l) 00270 { 00271 this->clear(); 00272 this->insert(__l.begin(), __l.end()); 00273 return *this; 00274 } 00275 #endif 00276 00277 // accessors: 00278 00279 /// Returns the comparison object with which the %set was constructed. 00280 key_compare 00281 key_comp() const 00282 { return _M_t.key_comp(); } 00283 /// Returns the comparison object with which the %set was constructed. 00284 value_compare 00285 value_comp() const 00286 { return _M_t.key_comp(); } 00287 /// Returns the allocator object with which the %set was constructed. 00288 allocator_type 00289 get_allocator() const _GLIBCXX_NOEXCEPT 00290 { return allocator_type(_M_t.get_allocator()); } 00291 00292 /** 00293 * Returns a read-only (constant) iterator that points to the first 00294 * element in the %set. Iteration is done in ascending order according 00295 * to the keys. 00296 */ 00297 iterator 00298 begin() const _GLIBCXX_NOEXCEPT 00299 { return _M_t.begin(); } 00300 00301 /** 00302 * Returns a read-only (constant) iterator that points one past the last 00303 * element in the %set. Iteration is done in ascending order according 00304 * to the keys. 00305 */ 00306 iterator 00307 end() const _GLIBCXX_NOEXCEPT 00308 { return _M_t.end(); } 00309 00310 /** 00311 * Returns a read-only (constant) iterator that points to the last 00312 * element in the %set. Iteration is done in descending order according 00313 * to the keys. 00314 */ 00315 reverse_iterator 00316 rbegin() const _GLIBCXX_NOEXCEPT 00317 { return _M_t.rbegin(); } 00318 00319 /** 00320 * Returns a read-only (constant) reverse iterator that points to the 00321 * last pair in the %set. Iteration is done in descending order 00322 * according to the keys. 00323 */ 00324 reverse_iterator 00325 rend() const _GLIBCXX_NOEXCEPT 00326 { return _M_t.rend(); } 00327 00328 #if __cplusplus >= 201103L 00329 /** 00330 * Returns a read-only (constant) iterator that points to the first 00331 * element in the %set. Iteration is done in ascending order according 00332 * to the keys. 00333 */ 00334 iterator 00335 cbegin() const noexcept 00336 { return _M_t.begin(); } 00337 00338 /** 00339 * Returns a read-only (constant) iterator that points one past the last 00340 * element in the %set. Iteration is done in ascending order according 00341 * to the keys. 00342 */ 00343 iterator 00344 cend() const noexcept 00345 { return _M_t.end(); } 00346 00347 /** 00348 * Returns a read-only (constant) iterator that points to the last 00349 * element in the %set. Iteration is done in descending order according 00350 * to the keys. 00351 */ 00352 reverse_iterator 00353 crbegin() const noexcept 00354 { return _M_t.rbegin(); } 00355 00356 /** 00357 * Returns a read-only (constant) reverse iterator that points to the 00358 * last pair in the %set. Iteration is done in descending order 00359 * according to the keys. 00360 */ 00361 reverse_iterator 00362 crend() const noexcept 00363 { return _M_t.rend(); } 00364 #endif 00365 00366 /// Returns true if the %set is empty. 00367 bool 00368 empty() const _GLIBCXX_NOEXCEPT 00369 { return _M_t.empty(); } 00370 00371 /// Returns the size of the %set. 00372 size_type 00373 size() const _GLIBCXX_NOEXCEPT 00374 { return _M_t.size(); } 00375 00376 /// Returns the maximum size of the %set. 00377 size_type 00378 max_size() const _GLIBCXX_NOEXCEPT 00379 { return _M_t.max_size(); } 00380 00381 /** 00382 * @brief Swaps data with another %set. 00383 * @param __x A %set of the same element and allocator types. 00384 * 00385 * This exchanges the elements between two sets in constant 00386 * time. (It is only swapping a pointer, an integer, and an 00387 * instance of the @c Compare type (which itself is often 00388 * stateless and empty), so it should be quite fast.) Note 00389 * that the global std::swap() function is specialized such 00390 * that std::swap(s1,s2) will feed to this function. 00391 */ 00392 void 00393 swap(set& __x) 00394 { _M_t.swap(__x._M_t); } 00395 00396 // insert/erase 00397 #if __cplusplus >= 201103L 00398 /** 00399 * @brief Attempts to build and insert an element into the %set. 00400 * @param __args Arguments used to generate an element. 00401 * @return A pair, of which the first element is an iterator that points 00402 * to the possibly inserted element, and the second is a bool 00403 * that is true if the element was actually inserted. 00404 * 00405 * This function attempts to build and insert an element into the %set. 00406 * A %set relies on unique keys and thus an element is only inserted if 00407 * it is not already present in the %set. 00408 * 00409 * Insertion requires logarithmic time. 00410 */ 00411 template<typename... _Args> 00412 std::pair<iterator, bool> 00413 emplace(_Args&&... __args) 00414 { return _M_t._M_emplace_unique(std::forward<_Args>(__args)...); } 00415 00416 /** 00417 * @brief Attempts to insert an element into the %set. 00418 * @param __pos An iterator that serves as a hint as to where the 00419 * element should be inserted. 00420 * @param __args Arguments used to generate the element to be 00421 * inserted. 00422 * @return An iterator that points to the element with key equivalent to 00423 * the one generated from @a __args (may or may not be the 00424 * element itself). 00425 * 00426 * This function is not concerned about whether the insertion took place, 00427 * and thus does not return a boolean like the single-argument emplace() 00428 * does. Note that the first parameter is only a hint and can 00429 * potentially improve the performance of the insertion process. A bad 00430 * hint would cause no gains in efficiency. 00431 * 00432 * For more on @a hinting, see: 00433 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html 00434 * 00435 * Insertion requires logarithmic time (if the hint is not taken). 00436 */ 00437 template<typename... _Args> 00438 iterator 00439 emplace_hint(const_iterator __pos, _Args&&... __args) 00440 { 00441 return _M_t._M_emplace_hint_unique(__pos, 00442 std::forward<_Args>(__args)...); 00443 } 00444 #endif 00445 00446 /** 00447 * @brief Attempts to insert an element into the %set. 00448 * @param __x Element to be inserted. 00449 * @return A pair, of which the first element is an iterator that points 00450 * to the possibly inserted element, and the second is a bool 00451 * that is true if the element was actually inserted. 00452 * 00453 * This function attempts to insert an element into the %set. A %set 00454 * relies on unique keys and thus an element is only inserted if it is 00455 * not already present in the %set. 00456 * 00457 * Insertion requires logarithmic time. 00458 */ 00459 std::pair<iterator, bool> 00460 insert(const value_type& __x) 00461 { 00462 std::pair<typename _Rep_type::iterator, bool> __p = 00463 _M_t._M_insert_unique(__x); 00464 return std::pair<iterator, bool>(__p.first, __p.second); 00465 } 00466 00467 #if __cplusplus >= 201103L 00468 std::pair<iterator, bool> 00469 insert(value_type&& __x) 00470 { 00471 std::pair<typename _Rep_type::iterator, bool> __p = 00472 _M_t._M_insert_unique(std::move(__x)); 00473 return std::pair<iterator, bool>(__p.first, __p.second); 00474 } 00475 #endif 00476 00477 /** 00478 * @brief Attempts to insert an element into the %set. 00479 * @param __position An iterator that serves as a hint as to where the 00480 * element should be inserted. 00481 * @param __x Element to be inserted. 00482 * @return An iterator that points to the element with key of 00483 * @a __x (may or may not be the element passed in). 00484 * 00485 * This function is not concerned about whether the insertion took place, 00486 * and thus does not return a boolean like the single-argument insert() 00487 * does. Note that the first parameter is only a hint and can 00488 * potentially improve the performance of the insertion process. A bad 00489 * hint would cause no gains in efficiency. 00490 * 00491 * For more on @a hinting, see: 00492 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt07ch17.html 00493 * 00494 * Insertion requires logarithmic time (if the hint is not taken). 00495 */ 00496 iterator 00497 insert(const_iterator __position, const value_type& __x) 00498 { return _M_t._M_insert_unique_(__position, __x); } 00499 00500 #if __cplusplus >= 201103L 00501 iterator 00502 insert(const_iterator __position, value_type&& __x) 00503 { return _M_t._M_insert_unique_(__position, std::move(__x)); } 00504 #endif 00505 00506 /** 00507 * @brief A template function that attempts to insert a range 00508 * of elements. 00509 * @param __first Iterator pointing to the start of the range to be 00510 * inserted. 00511 * @param __last Iterator pointing to the end of the range. 00512 * 00513 * Complexity similar to that of the range constructor. 00514 */ 00515 template<typename _InputIterator> 00516 void 00517 insert(_InputIterator __first, _InputIterator __last) 00518 { _M_t._M_insert_unique(__first, __last); } 00519 00520 #if __cplusplus >= 201103L 00521 /** 00522 * @brief Attempts to insert a list of elements into the %set. 00523 * @param __l A std::initializer_list<value_type> of elements 00524 * to be inserted. 00525 * 00526 * Complexity similar to that of the range constructor. 00527 */ 00528 void 00529 insert(initializer_list<value_type> __l) 00530 { this->insert(__l.begin(), __l.end()); } 00531 #endif 00532 00533 #if __cplusplus >= 201103L 00534 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00535 // DR 130. Associative erase should return an iterator. 00536 /** 00537 * @brief Erases an element from a %set. 00538 * @param __position An iterator pointing to the element to be erased. 00539 * @return An iterator pointing to the element immediately following 00540 * @a __position prior to the element being erased. If no such 00541 * element exists, end() is returned. 00542 * 00543 * This function erases an element, pointed to by the given iterator, 00544 * from a %set. Note that this function only erases the element, and 00545 * that if the element is itself a pointer, the pointed-to memory is not 00546 * touched in any way. Managing the pointer is the user's 00547 * responsibility. 00548 */ 00549 _GLIBCXX_ABI_TAG_CXX11 00550 iterator 00551 erase(const_iterator __position) 00552 { return _M_t.erase(__position); } 00553 #else 00554 /** 00555 * @brief Erases an element from a %set. 00556 * @param position An iterator pointing to the element to be erased. 00557 * 00558 * This function erases an element, pointed to by the given iterator, 00559 * from a %set. Note that this function only erases the element, and 00560 * that if the element is itself a pointer, the pointed-to memory is not 00561 * touched in any way. Managing the pointer is the user's 00562 * responsibility. 00563 */ 00564 void 00565 erase(iterator __position) 00566 { _M_t.erase(__position); } 00567 #endif 00568 00569 /** 00570 * @brief Erases elements according to the provided key. 00571 * @param __x Key of element to be erased. 00572 * @return The number of elements erased. 00573 * 00574 * This function erases all the elements located by the given key from 00575 * a %set. 00576 * Note that this function only erases the element, and that if 00577 * the element is itself a pointer, the pointed-to memory is not touched 00578 * in any way. Managing the pointer is the user's responsibility. 00579 */ 00580 size_type 00581 erase(const key_type& __x) 00582 { return _M_t.erase(__x); } 00583 00584 #if __cplusplus >= 201103L 00585 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00586 // DR 130. Associative erase should return an iterator. 00587 /** 00588 * @brief Erases a [__first,__last) range of elements from a %set. 00589 * @param __first Iterator pointing to the start of the range to be 00590 * erased. 00591 00592 * @param __last Iterator pointing to the end of the range to 00593 * be erased. 00594 * @return The iterator @a __last. 00595 * 00596 * This function erases a sequence of elements from a %set. 00597 * Note that this function only erases the element, and that if 00598 * the element is itself a pointer, the pointed-to memory is not touched 00599 * in any way. Managing the pointer is the user's responsibility. 00600 */ 00601 _GLIBCXX_ABI_TAG_CXX11 00602 iterator 00603 erase(const_iterator __first, const_iterator __last) 00604 { return _M_t.erase(__first, __last); } 00605 #else 00606 /** 00607 * @brief Erases a [first,last) range of elements from a %set. 00608 * @param __first Iterator pointing to the start of the range to be 00609 * erased. 00610 * @param __last Iterator pointing to the end of the range to 00611 * be erased. 00612 * 00613 * This function erases a sequence of elements from a %set. 00614 * Note that this function only erases the element, and that if 00615 * the element is itself a pointer, the pointed-to memory is not touched 00616 * in any way. Managing the pointer is the user's responsibility. 00617 */ 00618 void 00619 erase(iterator __first, iterator __last) 00620 { _M_t.erase(__first, __last); } 00621 #endif 00622 00623 /** 00624 * Erases all elements in a %set. Note that this function only erases 00625 * the elements, and that if the elements themselves are pointers, the 00626 * pointed-to memory is not touched in any way. Managing the pointer is 00627 * the user's responsibility. 00628 */ 00629 void 00630 clear() _GLIBCXX_NOEXCEPT 00631 { _M_t.clear(); } 00632 00633 // set operations: 00634 00635 /** 00636 * @brief Finds the number of elements. 00637 * @param __x Element to located. 00638 * @return Number of elements with specified key. 00639 * 00640 * This function only makes sense for multisets; for set the result will 00641 * either be 0 (not present) or 1 (present). 00642 */ 00643 size_type 00644 count(const key_type& __x) const 00645 { return _M_t.find(__x) == _M_t.end() ? 0 : 1; } 00646 00647 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00648 // 214. set::find() missing const overload 00649 //@{ 00650 /** 00651 * @brief Tries to locate an element in a %set. 00652 * @param __x Element to be located. 00653 * @return Iterator pointing to sought-after element, or end() if not 00654 * found. 00655 * 00656 * This function takes a key and tries to locate the element with which 00657 * the key matches. If successful the function returns an iterator 00658 * pointing to the sought after element. If unsuccessful it returns the 00659 * past-the-end ( @c end() ) iterator. 00660 */ 00661 iterator 00662 find(const key_type& __x) 00663 { return _M_t.find(__x); } 00664 00665 const_iterator 00666 find(const key_type& __x) const 00667 { return _M_t.find(__x); } 00668 //@} 00669 00670 //@{ 00671 /** 00672 * @brief Finds the beginning of a subsequence matching given key. 00673 * @param __x Key to be located. 00674 * @return Iterator pointing to first element equal to or greater 00675 * than key, or end(). 00676 * 00677 * This function returns the first element of a subsequence of elements 00678 * that matches the given key. If unsuccessful it returns an iterator 00679 * pointing to the first element that has a greater value than given key 00680 * or end() if no such element exists. 00681 */ 00682 iterator 00683 lower_bound(const key_type& __x) 00684 { return _M_t.lower_bound(__x); } 00685 00686 const_iterator 00687 lower_bound(const key_type& __x) const 00688 { return _M_t.lower_bound(__x); } 00689 //@} 00690 00691 //@{ 00692 /** 00693 * @brief Finds the end of a subsequence matching given key. 00694 * @param __x Key to be located. 00695 * @return Iterator pointing to the first element 00696 * greater than key, or end(). 00697 */ 00698 iterator 00699 upper_bound(const key_type& __x) 00700 { return _M_t.upper_bound(__x); } 00701 00702 const_iterator 00703 upper_bound(const key_type& __x) const 00704 { return _M_t.upper_bound(__x); } 00705 //@} 00706 00707 //@{ 00708 /** 00709 * @brief Finds a subsequence matching given key. 00710 * @param __x Key to be located. 00711 * @return Pair of iterators that possibly points to the subsequence 00712 * matching given key. 00713 * 00714 * This function is equivalent to 00715 * @code 00716 * std::make_pair(c.lower_bound(val), 00717 * c.upper_bound(val)) 00718 * @endcode 00719 * (but is faster than making the calls separately). 00720 * 00721 * This function probably only makes sense for multisets. 00722 */ 00723 std::pair<iterator, iterator> 00724 equal_range(const key_type& __x) 00725 { return _M_t.equal_range(__x); } 00726 00727 std::pair<const_iterator, const_iterator> 00728 equal_range(const key_type& __x) const 00729 { return _M_t.equal_range(__x); } 00730 //@} 00731 00732 template<typename _K1, typename _C1, typename _A1> 00733 friend bool 00734 operator==(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&); 00735 00736 template<typename _K1, typename _C1, typename _A1> 00737 friend bool 00738 operator<(const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&); 00739 }; 00740 00741 00742 /** 00743 * @brief Set equality comparison. 00744 * @param __x A %set. 00745 * @param __y A %set of the same type as @a x. 00746 * @return True iff the size and elements of the sets are equal. 00747 * 00748 * This is an equivalence relation. It is linear in the size of the sets. 00749 * Sets are considered equivalent if their sizes are equal, and if 00750 * corresponding elements compare equal. 00751 */ 00752 template<typename _Key, typename _Compare, typename _Alloc> 00753 inline bool 00754 operator==(const set<_Key, _Compare, _Alloc>& __x, 00755 const set<_Key, _Compare, _Alloc>& __y) 00756 { return __x._M_t == __y._M_t; } 00757 00758 /** 00759 * @brief Set ordering relation. 00760 * @param __x A %set. 00761 * @param __y A %set of the same type as @a x. 00762 * @return True iff @a __x is lexicographically less than @a __y. 00763 * 00764 * This is a total ordering relation. It is linear in the size of the 00765 * maps. The elements must be comparable with @c <. 00766 * 00767 * See std::lexicographical_compare() for how the determination is made. 00768 */ 00769 template<typename _Key, typename _Compare, typename _Alloc> 00770 inline bool 00771 operator<(const set<_Key, _Compare, _Alloc>& __x, 00772 const set<_Key, _Compare, _Alloc>& __y) 00773 { return __x._M_t < __y._M_t; } 00774 00775 /// Returns !(x == y). 00776 template<typename _Key, typename _Compare, typename _Alloc> 00777 inline bool 00778 operator!=(const set<_Key, _Compare, _Alloc>& __x, 00779 const set<_Key, _Compare, _Alloc>& __y) 00780 { return !(__x == __y); } 00781 00782 /// Returns y < x. 00783 template<typename _Key, typename _Compare, typename _Alloc> 00784 inline bool 00785 operator>(const set<_Key, _Compare, _Alloc>& __x, 00786 const set<_Key, _Compare, _Alloc>& __y) 00787 { return __y < __x; } 00788 00789 /// Returns !(y < x) 00790 template<typename _Key, typename _Compare, typename _Alloc> 00791 inline bool 00792 operator<=(const set<_Key, _Compare, _Alloc>& __x, 00793 const set<_Key, _Compare, _Alloc>& __y) 00794 { return !(__y < __x); } 00795 00796 /// Returns !(x < y) 00797 template<typename _Key, typename _Compare, typename _Alloc> 00798 inline bool 00799 operator>=(const set<_Key, _Compare, _Alloc>& __x, 00800 const set<_Key, _Compare, _Alloc>& __y) 00801 { return !(__x < __y); } 00802 00803 /// See std::set::swap(). 00804 template<typename _Key, typename _Compare, typename _Alloc> 00805 inline void 00806 swap(set<_Key, _Compare, _Alloc>& __x, set<_Key, _Compare, _Alloc>& __y) 00807 { __x.swap(__y); } 00808 00809 _GLIBCXX_END_NAMESPACE_CONTAINER 00810 } //namespace std 00811 #endif /* _STL_SET_H */