Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

stl_multiset.h

Go to the documentation of this file.
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
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_MULTISET_H
00032 #define __SGI_STL_INTERNAL_MULTISET_H
00033 
00034 #include <bits/concept_check.h>
00035 
00036 namespace std
00037 {
00038 
00039 // Forward declaration of operators < and ==, needed for friend declaration.
00040 
00041 template <class _Key, class _Compare = less<_Key>,
00042           class _Alloc = allocator<_Key> >
00043 class multiset;
00044 
00045 template <class _Key, class _Compare, class _Alloc>
00046 inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x, 
00047                        const multiset<_Key,_Compare,_Alloc>& __y);
00048 
00049 template <class _Key, class _Compare, class _Alloc>
00050 inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, 
00051                       const multiset<_Key,_Compare,_Alloc>& __y);
00052 
00053 template <class _Key, class _Compare, class _Alloc>
00054 class multiset
00055 {
00056   // concept requirements
00057   __glibcpp_class_requires(_Key, _SGIAssignableConcept);
00058   __glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept);
00059 
00060 public:
00061 
00062   // typedefs:
00063 
00064   typedef _Key     key_type;
00065   typedef _Key     value_type;
00066   typedef _Compare key_compare;
00067   typedef _Compare value_compare;
00068 private:
00069   typedef _Rb_tree<key_type, value_type, 
00070                   _Identity<value_type>, key_compare, _Alloc> _Rep_type;
00071   _Rep_type _M_t;  // red-black tree representing multiset
00072 public:
00073   typedef typename _Rep_type::const_pointer pointer;
00074   typedef typename _Rep_type::const_pointer const_pointer;
00075   typedef typename _Rep_type::const_reference reference;
00076   typedef typename _Rep_type::const_reference const_reference;
00077   typedef typename _Rep_type::const_iterator iterator;
00078   typedef typename _Rep_type::const_iterator const_iterator;
00079   typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
00080   typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00081   typedef typename _Rep_type::size_type size_type;
00082   typedef typename _Rep_type::difference_type difference_type;
00083   typedef typename _Rep_type::allocator_type allocator_type;
00084 
00085   // allocation/deallocation
00086 
00087   multiset() : _M_t(_Compare(), allocator_type()) {}
00088   explicit multiset(const _Compare& __comp,
00089                     const allocator_type& __a = allocator_type())
00090     : _M_t(__comp, __a) {}
00091 
00092   template <class _InputIterator>
00093   multiset(_InputIterator __first, _InputIterator __last)
00094     : _M_t(_Compare(), allocator_type())
00095     { _M_t.insert_equal(__first, __last); }
00096 
00097   template <class _InputIterator>
00098   multiset(_InputIterator __first, _InputIterator __last,
00099            const _Compare& __comp,
00100            const allocator_type& __a = allocator_type())
00101     : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
00102 
00103   multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
00104 
00105   multiset<_Key,_Compare,_Alloc>&
00106   operator=(const multiset<_Key,_Compare,_Alloc>& __x) {
00107     _M_t = __x._M_t; 
00108     return *this;
00109   }
00110 
00111   // accessors:
00112 
00113   key_compare key_comp() const { return _M_t.key_comp(); }
00114   value_compare value_comp() const { return _M_t.key_comp(); }
00115   allocator_type get_allocator() const { return _M_t.get_allocator(); }
00116 
00117   iterator begin() const { return _M_t.begin(); }
00118   iterator end() const { return _M_t.end(); }
00119   reverse_iterator rbegin() const { return _M_t.rbegin(); } 
00120   reverse_iterator rend() const { return _M_t.rend(); }
00121   bool empty() const { return _M_t.empty(); }
00122   size_type size() const { return _M_t.size(); }
00123   size_type max_size() const { return _M_t.max_size(); }
00124   void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
00125 
00126   // insert/erase
00127   iterator insert(const value_type& __x) { 
00128     return _M_t.insert_equal(__x);
00129   }
00130   iterator insert(iterator __position, const value_type& __x) {
00131     typedef typename _Rep_type::iterator _Rep_iterator;
00132     return _M_t.insert_equal((_Rep_iterator&)__position, __x);
00133   }
00134 
00135   template <class _InputIterator>
00136   void insert(_InputIterator __first, _InputIterator __last) {
00137     _M_t.insert_equal(__first, __last);
00138   }
00139   void erase(iterator __position) { 
00140     typedef typename _Rep_type::iterator _Rep_iterator;
00141     _M_t.erase((_Rep_iterator&)__position); 
00142   }
00143   size_type erase(const key_type& __x) { 
00144     return _M_t.erase(__x); 
00145   }
00146   void erase(iterator __first, iterator __last) { 
00147     typedef typename _Rep_type::iterator _Rep_iterator;
00148     _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); 
00149   }
00150   void clear() { _M_t.clear(); }
00151 
00152   // multiset operations:
00153 
00154   iterator find(const key_type& __x) const { return _M_t.find(__x); }
00155   size_type count(const key_type& __x) const { return _M_t.count(__x); }
00156   iterator lower_bound(const key_type& __x) const {
00157     return _M_t.lower_bound(__x);
00158   }
00159   iterator upper_bound(const key_type& __x) const {
00160     return _M_t.upper_bound(__x); 
00161   }
00162   pair<iterator,iterator> equal_range(const key_type& __x) const {
00163     return _M_t.equal_range(__x);
00164   }
00165 
00166   template <class _K1, class _C1, class _A1>
00167   friend bool operator== (const multiset<_K1,_C1,_A1>&,
00168                           const multiset<_K1,_C1,_A1>&);
00169   template <class _K1, class _C1, class _A1>
00170   friend bool operator< (const multiset<_K1,_C1,_A1>&,
00171                          const multiset<_K1,_C1,_A1>&);
00172 };
00173 
00174 template <class _Key, class _Compare, class _Alloc>
00175 inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x, 
00176                        const multiset<_Key,_Compare,_Alloc>& __y) {
00177   return __x._M_t == __y._M_t;
00178 }
00179 
00180 template <class _Key, class _Compare, class _Alloc>
00181 inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, 
00182                       const multiset<_Key,_Compare,_Alloc>& __y) {
00183   return __x._M_t < __y._M_t;
00184 }
00185 
00186 template <class _Key, class _Compare, class _Alloc>
00187 inline bool operator!=(const multiset<_Key,_Compare,_Alloc>& __x, 
00188                        const multiset<_Key,_Compare,_Alloc>& __y) {
00189   return !(__x == __y);
00190 }
00191 
00192 template <class _Key, class _Compare, class _Alloc>
00193 inline bool operator>(const multiset<_Key,_Compare,_Alloc>& __x, 
00194                       const multiset<_Key,_Compare,_Alloc>& __y) {
00195   return __y < __x;
00196 }
00197 
00198 template <class _Key, class _Compare, class _Alloc>
00199 inline bool operator<=(const multiset<_Key,_Compare,_Alloc>& __x, 
00200                        const multiset<_Key,_Compare,_Alloc>& __y) {
00201   return !(__y < __x);
00202 }
00203 
00204 template <class _Key, class _Compare, class _Alloc>
00205 inline bool operator>=(const multiset<_Key,_Compare,_Alloc>& __x, 
00206                        const multiset<_Key,_Compare,_Alloc>& __y) {
00207   return !(__x < __y);
00208 }
00209 
00210 template <class _Key, class _Compare, class _Alloc>
00211 inline void swap(multiset<_Key,_Compare,_Alloc>& __x, 
00212                  multiset<_Key,_Compare,_Alloc>& __y) {
00213   __x.swap(__y);
00214 }
00215 
00216 } // namespace std
00217 
00218 #endif /* __SGI_STL_INTERNAL_MULTISET_H */
00219 
00220 // Local Variables:
00221 // mode:C++
00222 // End:

Generated at Tue May 1 16:28:39 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001