4 * Hewlett-Packard Company
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Hewlett-Packard Company makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
15 * Copyright (c) 1996,1997
16 * Silicon Graphics Computer Systems, Inc.
18 * Permission to use, copy, modify, distribute and sell this software
19 * and its documentation for any purpose is hereby granted without fee,
20 * provided that the above copyright notice appear in all copies and
21 * that both that copyright notice and this permission notice appear
22 * in supporting documentation. Silicon Graphics makes no
23 * representations about the suitability of this software for any
24 * purpose. It is provided "as is" without express or implied warranty.
27 /* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
31 #ifndef __SGI_STL_INTERNAL_SET_H
32 #define __SGI_STL_INTERNAL_SET_H
34 #include <bits/concept_check.h>
39 // Forward declarations of operators < and ==, needed for friend declaration.
41 template <class _Key, class _Compare = less<_Key>,
42 class _Alloc = allocator<_Key> >
45 template <class _Key, class _Compare, class _Alloc>
46 inline bool operator==(const set<_Key,_Compare,_Alloc>& __x,
47 const set<_Key,_Compare,_Alloc>& __y);
49 template <class _Key, class _Compare, class _Alloc>
50 inline bool operator<(const set<_Key,_Compare,_Alloc>& __x,
51 const set<_Key,_Compare,_Alloc>& __y);
54 template <class _Key, class _Compare, class _Alloc>
57 // concept requirements
58 glibcpp_class_requires(_Key, SGIAssignableConcept);
59 glibcpp_class_requires4(_Compare, bool, _Key, _Key, BinaryFunctionConcept);
63 typedef _Key key_type;
64 typedef _Key value_type;
65 typedef _Compare key_compare;
66 typedef _Compare value_compare;
68 typedef _Rb_tree<key_type, value_type,
69 _Identity<value_type>, key_compare, _Alloc> _Rep_type;
70 _Rep_type _M_t; // red-black tree representing set
72 typedef typename _Rep_type::const_pointer pointer;
73 typedef typename _Rep_type::const_pointer const_pointer;
74 typedef typename _Rep_type::const_reference reference;
75 typedef typename _Rep_type::const_reference const_reference;
76 typedef typename _Rep_type::const_iterator iterator;
77 typedef typename _Rep_type::const_iterator const_iterator;
78 typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
79 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
80 typedef typename _Rep_type::size_type size_type;
81 typedef typename _Rep_type::difference_type difference_type;
82 typedef typename _Rep_type::allocator_type allocator_type;
84 // allocation/deallocation
86 set() : _M_t(_Compare(), allocator_type()) {}
87 explicit set(const _Compare& __comp,
88 const allocator_type& __a = allocator_type())
89 : _M_t(__comp, __a) {}
91 template <class _InputIterator>
92 set(_InputIterator __first, _InputIterator __last)
93 : _M_t(_Compare(), allocator_type())
94 { _M_t.insert_unique(__first, __last); }
96 template <class _InputIterator>
97 set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
98 const allocator_type& __a = allocator_type())
99 : _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
101 set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
102 set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
110 key_compare key_comp() const { return _M_t.key_comp(); }
111 value_compare value_comp() const { return _M_t.key_comp(); }
112 allocator_type get_allocator() const { return _M_t.get_allocator(); }
114 iterator begin() const { return _M_t.begin(); }
115 iterator end() const { return _M_t.end(); }
116 reverse_iterator rbegin() const { return _M_t.rbegin(); }
117 reverse_iterator rend() const { return _M_t.rend(); }
118 bool empty() const { return _M_t.empty(); }
119 size_type size() const { return _M_t.size(); }
120 size_type max_size() const { return _M_t.max_size(); }
121 void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
124 pair<iterator,bool> insert(const value_type& __x) {
125 pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x);
126 return pair<iterator, bool>(__p.first, __p.second);
128 iterator insert(iterator __position, const value_type& __x) {
129 typedef typename _Rep_type::iterator _Rep_iterator;
130 return _M_t.insert_unique((_Rep_iterator&)__position, __x);
132 template <class _InputIterator>
133 void insert(_InputIterator __first, _InputIterator __last) {
134 _M_t.insert_unique(__first, __last);
136 void erase(iterator __position) {
137 typedef typename _Rep_type::iterator _Rep_iterator;
138 _M_t.erase((_Rep_iterator&)__position);
140 size_type erase(const key_type& __x) {
141 return _M_t.erase(__x);
143 void erase(iterator __first, iterator __last) {
144 typedef typename _Rep_type::iterator _Rep_iterator;
145 _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
147 void clear() { _M_t.clear(); }
151 iterator find(const key_type& __x) const { return _M_t.find(__x); }
152 size_type count(const key_type& __x) const {
153 return _M_t.find(__x) == _M_t.end() ? 0 : 1;
155 iterator lower_bound(const key_type& __x) const {
156 return _M_t.lower_bound(__x);
158 iterator upper_bound(const key_type& __x) const {
159 return _M_t.upper_bound(__x);
161 pair<iterator,iterator> equal_range(const key_type& __x) const {
162 return _M_t.equal_range(__x);
165 template <class _K1, class _C1, class _A1>
166 friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
167 template <class _K1, class _C1, class _A1>
168 friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
171 template <class _Key, class _Compare, class _Alloc>
172 inline bool operator==(const set<_Key,_Compare,_Alloc>& __x,
173 const set<_Key,_Compare,_Alloc>& __y) {
174 return __x._M_t == __y._M_t;
177 template <class _Key, class _Compare, class _Alloc>
178 inline bool operator<(const set<_Key,_Compare,_Alloc>& __x,
179 const set<_Key,_Compare,_Alloc>& __y) {
180 return __x._M_t < __y._M_t;
183 template <class _Key, class _Compare, class _Alloc>
184 inline bool operator!=(const set<_Key,_Compare,_Alloc>& __x,
185 const set<_Key,_Compare,_Alloc>& __y) {
186 return !(__x == __y);
189 template <class _Key, class _Compare, class _Alloc>
190 inline bool operator>(const set<_Key,_Compare,_Alloc>& __x,
191 const set<_Key,_Compare,_Alloc>& __y) {
195 template <class _Key, class _Compare, class _Alloc>
196 inline bool operator<=(const set<_Key,_Compare,_Alloc>& __x,
197 const set<_Key,_Compare,_Alloc>& __y) {
201 template <class _Key, class _Compare, class _Alloc>
202 inline bool operator>=(const set<_Key,_Compare,_Alloc>& __x,
203 const set<_Key,_Compare,_Alloc>& __y) {
207 template <class _Key, class _Compare, class _Alloc>
208 inline void swap(set<_Key,_Compare,_Alloc>& __x,
209 set<_Key,_Compare,_Alloc>& __y) {
215 #endif /* __SGI_STL_INTERNAL_SET_H */