00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __SGI_STL_INTERNAL_SET_H
00032 #define __SGI_STL_INTERNAL_SET_H
00033
00034 #include <bits/concept_check.h>
00035
00036 namespace std
00037 {
00038
00039
00040
00041 template <class _Key, class _Compare = less<_Key>,
00042 class _Alloc = allocator<_Key> >
00043 class set;
00044
00045 template <class _Key, class _Compare, class _Alloc>
00046 inline bool operator==(const set<_Key,_Compare,_Alloc>& __x,
00047 const set<_Key,_Compare,_Alloc>& __y);
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
00054 template <class _Key, class _Compare, class _Alloc>
00055 class set
00056 {
00057
00058 __glibcpp_class_requires(_Key, _SGIAssignableConcept);
00059 __glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept);
00060
00061 public:
00062
00063 typedef _Key key_type;
00064 typedef _Key value_type;
00065 typedef _Compare key_compare;
00066 typedef _Compare value_compare;
00067 private:
00068 typedef _Rb_tree<key_type, value_type,
00069 _Identity<value_type>, key_compare, _Alloc> _Rep_type;
00070 _Rep_type _M_t;
00071 public:
00072 typedef typename _Rep_type::const_pointer pointer;
00073 typedef typename _Rep_type::const_pointer const_pointer;
00074 typedef typename _Rep_type::const_reference reference;
00075 typedef typename _Rep_type::const_reference const_reference;
00076 typedef typename _Rep_type::const_iterator iterator;
00077 typedef typename _Rep_type::const_iterator const_iterator;
00078 typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
00079 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00080 typedef typename _Rep_type::size_type size_type;
00081 typedef typename _Rep_type::difference_type difference_type;
00082 typedef typename _Rep_type::allocator_type allocator_type;
00083
00084
00085
00086 set() : _M_t(_Compare(), allocator_type()) {}
00087 explicit set(const _Compare& __comp,
00088 const allocator_type& __a = allocator_type())
00089 : _M_t(__comp, __a) {}
00090
00091 template <class _InputIterator>
00092 set(_InputIterator __first, _InputIterator __last)
00093 : _M_t(_Compare(), allocator_type())
00094 { _M_t.insert_unique(__first, __last); }
00095
00096 template <class _InputIterator>
00097 set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
00098 const allocator_type& __a = allocator_type())
00099 : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
00100
00101 set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
00102 set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
00103 {
00104 _M_t = __x._M_t;
00105 return *this;
00106 }
00107
00108
00109
00110 key_compare key_comp() const { return _M_t.key_comp(); }
00111 value_compare value_comp() const { return _M_t.key_comp(); }
00112 allocator_type get_allocator() const { return _M_t.get_allocator(); }
00113
00114 iterator begin() const { return _M_t.begin(); }
00115 iterator end() const { return _M_t.end(); }
00116 reverse_iterator rbegin() const { return _M_t.rbegin(); }
00117 reverse_iterator rend() const { return _M_t.rend(); }
00118 bool empty() const { return _M_t.empty(); }
00119 size_type size() const { return _M_t.size(); }
00120 size_type max_size() const { return _M_t.max_size(); }
00121 void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
00122
00123
00124 pair<iterator,bool> insert(const value_type& __x) {
00125 pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x);
00126 return pair<iterator, bool>(__p.first, __p.second);
00127 }
00128 iterator insert(iterator __position, const value_type& __x) {
00129 typedef typename _Rep_type::iterator _Rep_iterator;
00130 return _M_t.insert_unique((_Rep_iterator&)__position, __x);
00131 }
00132 template <class _InputIterator>
00133 void insert(_InputIterator __first, _InputIterator __last) {
00134 _M_t.insert_unique(__first, __last);
00135 }
00136 void erase(iterator __position) {
00137 typedef typename _Rep_type::iterator _Rep_iterator;
00138 _M_t.erase((_Rep_iterator&)__position);
00139 }
00140 size_type erase(const key_type& __x) {
00141 return _M_t.erase(__x);
00142 }
00143 void erase(iterator __first, iterator __last) {
00144 typedef typename _Rep_type::iterator _Rep_iterator;
00145 _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
00146 }
00147 void clear() { _M_t.clear(); }
00148
00149
00150
00151 iterator find(const key_type& __x) const { return _M_t.find(__x); }
00152 size_type count(const key_type& __x) const {
00153 return _M_t.find(__x) == _M_t.end() ? 0 : 1;
00154 }
00155 iterator lower_bound(const key_type& __x) const {
00156 return _M_t.lower_bound(__x);
00157 }
00158 iterator upper_bound(const key_type& __x) const {
00159 return _M_t.upper_bound(__x);
00160 }
00161 pair<iterator,iterator> equal_range(const key_type& __x) const {
00162 return _M_t.equal_range(__x);
00163 }
00164
00165 template <class _K1, class _C1, class _A1>
00166 friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
00167 template <class _K1, class _C1, class _A1>
00168 friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
00169 };
00170
00171 template <class _Key, class _Compare, class _Alloc>
00172 inline bool operator==(const set<_Key,_Compare,_Alloc>& __x,
00173 const set<_Key,_Compare,_Alloc>& __y) {
00174 return __x._M_t == __y._M_t;
00175 }
00176
00177 template <class _Key, class _Compare, class _Alloc>
00178 inline bool operator<(const set<_Key,_Compare,_Alloc>& __x,
00179 const set<_Key,_Compare,_Alloc>& __y) {
00180 return __x._M_t < __y._M_t;
00181 }
00182
00183 template <class _Key, class _Compare, class _Alloc>
00184 inline bool operator!=(const set<_Key,_Compare,_Alloc>& __x,
00185 const set<_Key,_Compare,_Alloc>& __y) {
00186 return !(__x == __y);
00187 }
00188
00189 template <class _Key, class _Compare, class _Alloc>
00190 inline bool operator>(const set<_Key,_Compare,_Alloc>& __x,
00191 const set<_Key,_Compare,_Alloc>& __y) {
00192 return __y < __x;
00193 }
00194
00195 template <class _Key, class _Compare, class _Alloc>
00196 inline bool operator<=(const set<_Key,_Compare,_Alloc>& __x,
00197 const set<_Key,_Compare,_Alloc>& __y) {
00198 return !(__y < __x);
00199 }
00200
00201 template <class _Key, class _Compare, class _Alloc>
00202 inline bool operator>=(const set<_Key,_Compare,_Alloc>& __x,
00203 const set<_Key,_Compare,_Alloc>& __y) {
00204 return !(__x < __y);
00205 }
00206
00207 template <class _Key, class _Compare, class _Alloc>
00208 inline void swap(set<_Key,_Compare,_Alloc>& __x,
00209 set<_Key,_Compare,_Alloc>& __y) {
00210 __x.swap(__y);
00211 }
00212
00213 }
00214
00215 #endif
00216
00217
00218
00219