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.
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 #ifndef __SGI_STL_MULTISET_H
28 #define __SGI_STL_MULTISET_H
32 #ifndef __STL_LIMITED_DEFAULT_TEMPLATES
33 template <class Key, class Compare = less<Key>, class Alloc = alloc>
35 template <class Key, class Compare, class Alloc = alloc>
42 typedef Key value_type;
43 typedef Compare key_compare;
44 typedef Compare value_compare;
46 typedef rb_tree<key_type, value_type,
47 identity<value_type>, key_compare, Alloc> rep_type;
48 rep_type t; // red-black tree representing multiset
50 typedef rep_type::const_pointer pointer;
51 typedef rep_type::const_reference reference;
52 typedef rep_type::const_reference const_reference;
53 typedef rep_type::const_iterator iterator;
54 typedef rep_type::const_iterator const_iterator;
55 typedef rep_type::const_reverse_iterator reverse_iterator;
56 typedef rep_type::const_reverse_iterator const_reverse_iterator;
57 typedef rep_type::size_type size_type;
58 typedef rep_type::difference_type difference_type;
60 // allocation/deallocation
62 multiset() : t(Compare()) {}
63 explicit multiset(const Compare& comp) : t(comp) {}
65 #ifdef __STL_MEMBER_TEMPLATES
66 template <class InputIterator>
67 multiset(InputIterator first, InputIterator last)
68 : t(Compare()) { t.insert_equal(first, last); }
69 template <class InputIterator>
70 multiset(InputIterator first, InputIterator last, const Compare& comp)
71 : t(comp) { t.insert_equal(first, last); }
73 multiset(const value_type* first, const value_type* last)
74 : t(Compare()) { t.insert_equal(first, last); }
75 multiset(const value_type* first, const value_type* last,
77 : t(comp) { t.insert_equal(first, last); }
79 multiset(const_iterator first, const_iterator last)
80 : t(Compare()) { t.insert_equal(first, last); }
81 multiset(const_iterator first, const_iterator last, const Compare& comp)
82 : t(comp) { t.insert_equal(first, last); }
83 #endif /* __STL_MEMBER_TEMPLATES */
85 multiset(const multiset<Key, Compare, Alloc>& x) : t(x.t) {}
86 multiset<Key, Compare, Alloc>&
87 operator=(const multiset<Key, Compare, Alloc>& x) {
94 key_compare key_comp() const { return t.key_comp(); }
95 value_compare value_comp() const { return t.key_comp(); }
96 iterator begin() const { return t.begin(); }
97 iterator end() const { return t.end(); }
98 reverse_iterator rbegin() const { return t.rbegin(); }
99 reverse_iterator rend() const { return t.rend(); }
100 bool empty() const { return t.empty(); }
101 size_type size() const { return t.size(); }
102 size_type max_size() const { return t.max_size(); }
103 void swap(multiset<Key, Compare, Alloc>& x) { t.swap(x.t); }
106 iterator insert(const value_type& x) {
107 return t.insert_equal(x);
109 iterator insert(iterator position, const value_type& x) {
110 return t.insert_equal((rep_type::iterator&)position, x);
113 #ifdef __STL_MEMBER_TEMPLATES
114 template <class InputIterator>
115 void insert(InputIterator first, InputIterator last) {
116 t.insert_equal(first, last);
119 void insert(const value_type* first, const value_type* last) {
120 t.insert_equal(first, last);
122 void insert(const_iterator first, const_iterator last) {
123 t.insert_equal(first, last);
125 #endif /* __STL_MEMBER_TEMPLATES */
126 void erase(iterator position) {
127 t.erase((rep_type::iterator&)position);
129 size_type erase(const key_type& x) {
132 void erase(iterator first, iterator last) {
133 t.erase((rep_type::iterator&)first,
134 (rep_type::iterator&)last);
136 void clear() { t.clear(); }
138 // multiset operations:
140 iterator find(const key_type& x) const { return t.find(x); }
141 size_type count(const key_type& x) const { return t.count(x); }
142 iterator lower_bound(const key_type& x) const {
143 return t.lower_bound(x);
145 iterator upper_bound(const key_type& x) const {
146 return t.upper_bound(x);
148 pair<iterator,iterator> equal_range(const key_type& x) const {
149 return t.equal_range(x);
151 friend bool operator==(const multiset&, const multiset&);
152 friend bool operator<(const multiset&, const multiset&);
155 template <class Key, class Compare, class Alloc>
156 inline bool operator==(const multiset<Key, Compare, Alloc>& x,
157 const multiset<Key, Compare, Alloc>& y) {
161 template <class Key, class Compare, class Alloc>
162 inline bool operator<(const multiset<Key, Compare, Alloc>& x,
163 const multiset<Key, Compare, Alloc>& y) {
167 #endif /* __SGI_STL_MULTISET_H */