stl_bvector.h: Change calls to 3-argument distance() into standard 2-argument version.
[official-gcc.git] / libstdc++-v3 / include / bits / stl_multimap.h
blob27b4d12faf0850c77e390a5261ef6f59a08b3e60
1 // Multimap implementation -*- C++ -*-
3 // Copyright (C) 2001 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
32 * Copyright (c) 1994
33 * Hewlett-Packard Company
35 * Permission to use, copy, modify, distribute and sell this software
36 * and its documentation for any purpose is hereby granted without fee,
37 * provided that the above copyright notice appear in all copies and
38 * that both that copyright notice and this permission notice appear
39 * in supporting documentation. Hewlett-Packard Company makes no
40 * representations about the suitability of this software for any
41 * purpose. It is provided "as is" without express or implied warranty.
44 * Copyright (c) 1996,1997
45 * Silicon Graphics Computer Systems, Inc.
47 * Permission to use, copy, modify, distribute and sell this software
48 * and its documentation for any purpose is hereby granted without fee,
49 * provided that the above copyright notice appear in all copies and
50 * that both that copyright notice and this permission notice appear
51 * in supporting documentation. Silicon Graphics makes no
52 * representations about the suitability of this software for any
53 * purpose. It is provided "as is" without express or implied warranty.
56 /** @file stl_multimap.h
57 * This is an internal header file, included by other library headers.
58 * You should not attempt to use it directly.
61 #ifndef __GLIBCPP_INTERNAL_MULTIMAP_H
62 #define __GLIBCPP_INTERNAL_MULTIMAP_H
64 #include <bits/concept_check.h>
66 namespace std
69 // Forward declaration of operators < and ==, needed for friend declaration.
71 template <class _Key, class _Tp,
72 class _Compare = less<_Key>,
73 class _Alloc = allocator<pair<const _Key, _Tp> > >
74 class multimap;
76 template <class _Key, class _Tp, class _Compare, class _Alloc>
77 inline bool operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
78 const multimap<_Key,_Tp,_Compare,_Alloc>& __y);
80 template <class _Key, class _Tp, class _Compare, class _Alloc>
81 inline bool operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
82 const multimap<_Key,_Tp,_Compare,_Alloc>& __y);
84 template <class _Key, class _Tp, class _Compare, class _Alloc>
85 class multimap
87 // concept requirements
88 __glibcpp_class_requires(_Tp, _SGIAssignableConcept)
89 __glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept);
91 public:
93 // typedefs:
95 typedef _Key key_type;
96 typedef _Tp data_type;
97 typedef _Tp mapped_type;
98 typedef pair<const _Key, _Tp> value_type;
99 typedef _Compare key_compare;
101 class value_compare : public binary_function<value_type, value_type, bool> {
102 friend class multimap<_Key,_Tp,_Compare,_Alloc>;
103 protected:
104 _Compare comp;
105 value_compare(_Compare __c) : comp(__c) {}
106 public:
107 bool operator()(const value_type& __x, const value_type& __y) const {
108 return comp(__x.first, __y.first);
112 private:
113 typedef _Rb_tree<key_type, value_type,
114 _Select1st<value_type>, key_compare, _Alloc> _Rep_type;
115 _Rep_type _M_t; // red-black tree representing multimap
116 public:
117 typedef typename _Rep_type::pointer pointer;
118 typedef typename _Rep_type::const_pointer const_pointer;
119 typedef typename _Rep_type::reference reference;
120 typedef typename _Rep_type::const_reference const_reference;
121 typedef typename _Rep_type::iterator iterator;
122 typedef typename _Rep_type::const_iterator const_iterator;
123 typedef typename _Rep_type::reverse_iterator reverse_iterator;
124 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
125 typedef typename _Rep_type::size_type size_type;
126 typedef typename _Rep_type::difference_type difference_type;
127 typedef typename _Rep_type::allocator_type allocator_type;
129 // allocation/deallocation
131 multimap() : _M_t(_Compare(), allocator_type()) { }
132 explicit multimap(const _Compare& __comp,
133 const allocator_type& __a = allocator_type())
134 : _M_t(__comp, __a) { }
136 template <class _InputIterator>
137 multimap(_InputIterator __first, _InputIterator __last)
138 : _M_t(_Compare(), allocator_type())
139 { _M_t.insert_equal(__first, __last); }
141 template <class _InputIterator>
142 multimap(_InputIterator __first, _InputIterator __last,
143 const _Compare& __comp,
144 const allocator_type& __a = allocator_type())
145 : _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
146 multimap(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) : _M_t(__x._M_t) { }
148 multimap<_Key,_Tp,_Compare,_Alloc>&
149 operator=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) {
150 _M_t = __x._M_t;
151 return *this;
154 // accessors:
156 key_compare key_comp() const { return _M_t.key_comp(); }
157 value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
158 allocator_type get_allocator() const { return _M_t.get_allocator(); }
160 iterator begin() { return _M_t.begin(); }
161 const_iterator begin() const { return _M_t.begin(); }
162 iterator end() { return _M_t.end(); }
163 const_iterator end() const { return _M_t.end(); }
164 reverse_iterator rbegin() { return _M_t.rbegin(); }
165 const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
166 reverse_iterator rend() { return _M_t.rend(); }
167 const_reverse_iterator rend() const { return _M_t.rend(); }
168 bool empty() const { return _M_t.empty(); }
169 size_type size() const { return _M_t.size(); }
170 size_type max_size() const { return _M_t.max_size(); }
171 void swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
173 // insert/erase
175 iterator insert(const value_type& __x) { return _M_t.insert_equal(__x); }
176 iterator insert(iterator __position, const value_type& __x) {
177 return _M_t.insert_equal(__position, __x);
179 template <class _InputIterator>
180 void insert(_InputIterator __first, _InputIterator __last) {
181 _M_t.insert_equal(__first, __last);
183 void erase(iterator __position) { _M_t.erase(__position); }
184 size_type erase(const key_type& __x) { return _M_t.erase(__x); }
185 void erase(iterator __first, iterator __last)
186 { _M_t.erase(__first, __last); }
187 void clear() { _M_t.clear(); }
189 // multimap operations:
191 iterator find(const key_type& __x) { return _M_t.find(__x); }
192 const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
193 size_type count(const key_type& __x) const { return _M_t.count(__x); }
194 iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
195 const_iterator lower_bound(const key_type& __x) const {
196 return _M_t.lower_bound(__x);
198 iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
199 const_iterator upper_bound(const key_type& __x) const {
200 return _M_t.upper_bound(__x);
202 pair<iterator,iterator> equal_range(const key_type& __x) {
203 return _M_t.equal_range(__x);
205 pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
206 return _M_t.equal_range(__x);
209 template <class _K1, class _T1, class _C1, class _A1>
210 friend bool operator== (const multimap<_K1, _T1, _C1, _A1>&,
211 const multimap<_K1, _T1, _C1, _A1>&);
212 template <class _K1, class _T1, class _C1, class _A1>
213 friend bool operator< (const multimap<_K1, _T1, _C1, _A1>&,
214 const multimap<_K1, _T1, _C1, _A1>&);
217 template <class _Key, class _Tp, class _Compare, class _Alloc>
218 inline bool operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
219 const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
220 return __x._M_t == __y._M_t;
223 template <class _Key, class _Tp, class _Compare, class _Alloc>
224 inline bool operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
225 const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
226 return __x._M_t < __y._M_t;
229 template <class _Key, class _Tp, class _Compare, class _Alloc>
230 inline bool operator!=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
231 const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
232 return !(__x == __y);
235 template <class _Key, class _Tp, class _Compare, class _Alloc>
236 inline bool operator>(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
237 const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
238 return __y < __x;
241 template <class _Key, class _Tp, class _Compare, class _Alloc>
242 inline bool operator<=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
243 const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
244 return !(__y < __x);
247 template <class _Key, class _Tp, class _Compare, class _Alloc>
248 inline bool operator>=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
249 const multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
250 return !(__x < __y);
253 template <class _Key, class _Tp, class _Compare, class _Alloc>
254 inline void swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x,
255 multimap<_Key,_Tp,_Compare,_Alloc>& __y) {
256 __x.swap(__y);
259 } // namespace std
261 #endif /* __GLIBCPP_INTERNAL_MULTIMAP_H */
263 // Local Variables:
264 // mode:C++
265 // End: