stl_set.h

00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  *
00015  * Copyright (c) 1996,1997
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */
00026 
00027 /* NOTE: This is an internal header file, included by other STL headers.
00028  *   You should not attempt to use it directly.
00029  */
00030 
00031 #ifndef __SGI_STL_INTERNAL_SET_H
00032 #define __SGI_STL_INTERNAL_SET_H
00033 
00034 #include <concept_checks.h>
00035 
00036 __STL_BEGIN_NAMESPACE
00037 
00038 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00039 #pragma set woff 1174
00040 #pragma set woff 1375
00041 #endif
00042 
00043 // Forward declarations of operators < and ==, needed for friend declaration.
00044 
00045 template <class _Key, class _Compare __STL_DEPENDENT_DEFAULT_TMPL(less<_Key>),
00046           class _Alloc = __STL_DEFAULT_ALLOCATOR(_Key) >
00047 class set;
00048 
00049 template <class _Key, class _Compare, class _Alloc>
00050 inline bool operator==(const set<_Key,_Compare,_Alloc>& __x, 
00051                        const set<_Key,_Compare,_Alloc>& __y);
00052 
00053 template <class _Key, class _Compare, class _Alloc>
00054 inline bool operator<(const set<_Key,_Compare,_Alloc>& __x, 
00055                       const set<_Key,_Compare,_Alloc>& __y);
00056 
00057 
00058 template <class _Key, class _Compare, class _Alloc>
00059 class set {
00060   // requirements:
00061 
00062   __STL_CLASS_REQUIRES(_Key, _Assignable);
00063   __STL_CLASS_BINARY_FUNCTION_CHECK(_Compare, bool, _Key, _Key);
00064 
00065 public:
00066   // typedefs:
00067 
00068   typedef _Key     key_type;
00069   typedef _Key     value_type;
00070   typedef _Compare key_compare;
00071   typedef _Compare value_compare;
00072 private:
00073   typedef _Rb_tree<key_type, value_type, 
00074                   _Identity<value_type>, key_compare, _Alloc> _Rep_type;
00075   _Rep_type _M_t;  // red-black tree representing set
00076 public:
00077   typedef typename _Rep_type::const_pointer pointer;
00078   typedef typename _Rep_type::const_pointer const_pointer;
00079   typedef typename _Rep_type::const_reference reference;
00080   typedef typename _Rep_type::const_reference const_reference;
00081   typedef typename _Rep_type::const_iterator iterator;
00082   typedef typename _Rep_type::const_iterator const_iterator;
00083   typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
00084   typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00085   typedef typename _Rep_type::size_type size_type;
00086   typedef typename _Rep_type::difference_type difference_type;
00087   typedef typename _Rep_type::allocator_type allocator_type;
00088 
00089   // allocation/deallocation
00090 
00091   set() : _M_t(_Compare(), allocator_type()) {}
00092   explicit set(const _Compare& __comp,
00093                const allocator_type& __a = allocator_type())
00094     : _M_t(__comp, __a) {}
00095 
00096 #ifdef __STL_MEMBER_TEMPLATES
00097   template <class _InputIterator>
00098   set(_InputIterator __first, _InputIterator __last)
00099     : _M_t(_Compare(), allocator_type())
00100     { _M_t.insert_unique(__first, __last); }
00101 
00102   template <class _InputIterator>
00103   set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
00104       const allocator_type& __a = allocator_type())
00105     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00106 #else
00107   set(const value_type* __first, const value_type* __last) 
00108     : _M_t(_Compare(), allocator_type()) 
00109     { _M_t.insert_unique(__first, __last); }
00110 
00111   set(const value_type* __first, 
00112       const value_type* __last, const _Compare& __comp,
00113       const allocator_type& __a = allocator_type())
00114     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00115 
00116   set(const_iterator __first, const_iterator __last)
00117     : _M_t(_Compare(), allocator_type()) 
00118     { _M_t.insert_unique(__first, __last); }
00119 
00120   set(const_iterator __first, const_iterator __last, const _Compare& __comp,
00121       const allocator_type& __a = allocator_type())
00122     : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00123 #endif /* __STL_MEMBER_TEMPLATES */
00124 
00125   set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
00126   set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
00127   { 
00128     _M_t = __x._M_t; 
00129     return *this;
00130   }
00131 
00132   // accessors:
00133 
00134   key_compare key_comp() const { return _M_t.key_comp(); }
00135   value_compare value_comp() const { return _M_t.key_comp(); }
00136   allocator_type get_allocator() const { return _M_t.get_allocator(); }
00137 
00138   iterator begin() const { return _M_t.begin(); }
00139   iterator end() const { return _M_t.end(); }
00140   reverse_iterator rbegin() const { return _M_t.rbegin(); } 
00141   reverse_iterator rend() const { return _M_t.rend(); }
00142   bool empty() const { return _M_t.empty(); }
00143   size_type size() const { return _M_t.size(); }
00144   size_type max_size() const { return _M_t.max_size(); }
00145   void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
00146 
00147   // insert/erase
00148   pair<iterator,bool> insert(const value_type& __x) { 
00149     pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x); 
00150     return pair<iterator, bool>(__p.first, __p.second);
00151   }
00152   iterator insert(iterator __position, const value_type& __x) {
00153     typedef typename _Rep_type::iterator _Rep_iterator;
00154     return _M_t.insert_unique((_Rep_iterator&)__position, __x);
00155   }
00156 #ifdef __STL_MEMBER_TEMPLATES
00157   template <class _InputIterator>
00158   void insert(_InputIterator __first, _InputIterator __last) {
00159     _M_t.insert_unique(__first, __last);
00160   }
00161 #else
00162   void insert(const_iterator __first, const_iterator __last) {
00163     _M_t.insert_unique(__first, __last);
00164   }
00165   void insert(const value_type* __first, const value_type* __last) {
00166     _M_t.insert_unique(__first, __last);
00167   }
00168 #endif /* __STL_MEMBER_TEMPLATES */
00169   void erase(iterator __position) { 
00170     typedef typename _Rep_type::iterator _Rep_iterator;
00171     _M_t.erase((_Rep_iterator&)__position); 
00172   }
00173   size_type erase(const key_type& __x) { 
00174     return _M_t.erase(__x); 
00175   }
00176   void erase(iterator __first, iterator __last) { 
00177     typedef typename _Rep_type::iterator _Rep_iterator;
00178     _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); 
00179   }
00180   void clear() { _M_t.clear(); }
00181 
00182   // set operations:
00183 
00184   iterator find(const key_type& __x) const { return _M_t.find(__x); }
00185   size_type count(const key_type& __x) const {
00186     return _M_t.find(__x) == _M_t.end() ? 0 : 1;
00187   }
00188   iterator lower_bound(const key_type& __x) const {
00189     return _M_t.lower_bound(__x);
00190   }
00191   iterator upper_bound(const key_type& __x) const {
00192     return _M_t.upper_bound(__x); 
00193   }
00194   pair<iterator,iterator> equal_range(const key_type& __x) const {
00195     return _M_t.equal_range(__x);
00196   }
00197 
00198 #ifdef __STL_TEMPLATE_FRIENDS
00199   template <class _K1, class _C1, class _A1>
00200   friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
00201   template <class _K1, class _C1, class _A1>
00202   friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
00203 #else /* __STL_TEMPLATE_FRIENDS */
00204   friend bool __STD_QUALIFIER
00205   operator== __STL_NULL_TMPL_ARGS (const set&, const set&);
00206   friend bool __STD_QUALIFIER
00207   operator<  __STL_NULL_TMPL_ARGS (const set&, const set&);
00208 #endif /* __STL_TEMPLATE_FRIENDS */
00209 };
00210 
00211 template <class _Key, class _Compare, class _Alloc>
00212 inline bool operator==(const set<_Key,_Compare,_Alloc>& __x, 
00213                        const set<_Key,_Compare,_Alloc>& __y) {
00214   return __x._M_t == __y._M_t;
00215 }
00216 
00217 template <class _Key, class _Compare, class _Alloc>
00218 inline bool operator<(const set<_Key,_Compare,_Alloc>& __x, 
00219                       const set<_Key,_Compare,_Alloc>& __y) {
00220   return __x._M_t < __y._M_t;
00221 }
00222 
00223 #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
00224 
00225 template <class _Key, class _Compare, class _Alloc>
00226 inline bool operator!=(const set<_Key,_Compare,_Alloc>& __x, 
00227                        const set<_Key,_Compare,_Alloc>& __y) {
00228   return !(__x == __y);
00229 }
00230 
00231 template <class _Key, class _Compare, class _Alloc>
00232 inline bool operator>(const set<_Key,_Compare,_Alloc>& __x, 
00233                       const set<_Key,_Compare,_Alloc>& __y) {
00234   return __y < __x;
00235 }
00236 
00237 template <class _Key, class _Compare, class _Alloc>
00238 inline bool operator<=(const set<_Key,_Compare,_Alloc>& __x, 
00239                        const set<_Key,_Compare,_Alloc>& __y) {
00240   return !(__y < __x);
00241 }
00242 
00243 template <class _Key, class _Compare, class _Alloc>
00244 inline bool operator>=(const set<_Key,_Compare,_Alloc>& __x, 
00245                        const set<_Key,_Compare,_Alloc>& __y) {
00246   return !(__x < __y);
00247 }
00248 
00249 template <class _Key, class _Compare, class _Alloc>
00250 inline void swap(set<_Key,_Compare,_Alloc>& __x, 
00251                  set<_Key,_Compare,_Alloc>& __y) {
00252   __x.swap(__y);
00253 }
00254 
00255 #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
00256 
00257 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00258 #pragma reset woff 1174
00259 #pragma reset woff 1375
00260 #endif
00261 
00262 __STL_END_NAMESPACE
00263 
00264 #endif /* __SGI_STL_INTERNAL_SET_H */
00265 
00266 // Local Variables:
00267 // mode:C++
00268 // End:

Generated on Mon Jun 5 10:20:44 2006 for Intelligence.kdevelop by  doxygen 1.4.6