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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00061 #ifndef __GLIBCPP_INTERNAL_MULTIMAP_H
00062 #define __GLIBCPP_INTERNAL_MULTIMAP_H
00063
00064 #include <bits/concept_check.h>
00065
00066 namespace std
00067 {
00068
00069
00070 template <typename _Key, typename _Tp,
00071 typename _Compare = less<_Key>,
00072 typename _Alloc = allocator<pair<const _Key, _Tp> > >
00073 class multimap;
00074
00075 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00076 inline bool operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
00077 const multimap<_Key,_Tp,_Compare,_Alloc>& __y);
00078
00079 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00080 inline bool operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
00081 const multimap<_Key,_Tp,_Compare,_Alloc>& __y);
00082
00104 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00105 class multimap
00106 {
00107
00108 __glibcpp_class_requires(_Tp, _SGIAssignableConcept)
00109 __glibcpp_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept)
00110
00111 public:
00112 typedef _Key key_type;
00113 typedef _Tp mapped_type;
00114 typedef pair<const _Key, _Tp> value_type;
00115 typedef _Compare key_compare;
00116
00117 class value_compare
00118 : public binary_function<value_type, value_type, bool>
00119 {
00120 friend class multimap<_Key,_Tp,_Compare,_Alloc>;
00121 protected:
00122 _Compare comp;
00123 value_compare(_Compare __c) : comp(__c) {}
00124 public:
00125 bool operator()(const value_type& __x, const value_type& __y) const
00126 { return comp(__x.first, __y.first); }
00127 };
00128
00129 private:
00131 typedef _Rb_tree<key_type, value_type,
00132 _Select1st<value_type>, key_compare, _Alloc> _Rep_type;
00134 _Rep_type _M_t;
00135
00136 public:
00137
00138
00139 typedef typename _Rep_type::allocator_type allocator_type;
00140 typedef typename _Rep_type::reference reference;
00141 typedef typename _Rep_type::const_reference const_reference;
00142 typedef typename _Rep_type::iterator iterator;
00143 typedef typename _Rep_type::const_iterator const_iterator;
00144 typedef typename _Rep_type::size_type size_type;
00145 typedef typename _Rep_type::difference_type difference_type;
00146 typedef typename _Rep_type::pointer pointer;
00147 typedef typename _Rep_type::const_pointer const_pointer;
00148 typedef typename _Rep_type::reverse_iterator reverse_iterator;
00149 typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
00150
00151
00152
00153
00157 multimap() : _M_t(_Compare(), allocator_type()) { }
00158
00159
00163 explicit
00164 multimap(const _Compare& __comp, const allocator_type& __a = allocator_type())
00165 : _M_t(__comp, __a) { }
00166
00174 multimap(const multimap& __x)
00175 : _M_t(__x._M_t) { }
00176
00186 template <typename _InputIterator>
00187 multimap(_InputIterator __first, _InputIterator __last)
00188 : _M_t(_Compare(), allocator_type())
00189 { _M_t.insert_equal(__first, __last); }
00190
00202 template <typename _InputIterator>
00203 multimap(_InputIterator __first, _InputIterator __last,
00204 const _Compare& __comp,
00205 const allocator_type& __a = allocator_type())
00206 : _M_t(__comp, __a)
00207 { _M_t.insert_equal(__first, __last); }
00208
00209
00210
00211
00225 multimap&
00226 operator=(const multimap& __x)
00227 {
00228 _M_t = __x._M_t;
00229 return *this;
00230 }
00231
00233 allocator_type
00234 get_allocator() const { return _M_t.get_allocator(); }
00235
00236
00241 iterator
00242 begin() { return _M_t.begin(); }
00243
00249 const_iterator
00250 begin() const { return _M_t.begin(); }
00251
00256 iterator
00257 end() { return _M_t.end(); }
00258
00264 const_iterator
00265 end() const { return _M_t.end(); }
00266
00272 reverse_iterator
00273 rbegin() { return _M_t.rbegin(); }
00274
00280 const_reverse_iterator
00281 rbegin() const { return _M_t.rbegin(); }
00282
00288 reverse_iterator
00289 rend() { return _M_t.rend(); }
00290
00296 const_reverse_iterator
00297 rend() const { return _M_t.rend(); }
00298
00299
00301 bool
00302 empty() const { return _M_t.empty(); }
00303
00305 size_type
00306 size() const { return _M_t.size(); }
00307
00309 size_type
00310 max_size() const { return _M_t.max_size(); }
00311
00312
00325 iterator
00326 insert(const value_type& __x) { return _M_t.insert_equal(__x); }
00327
00348 iterator
00349 insert(iterator __position, const value_type& __x)
00350 { return _M_t.insert_equal(__position, __x); }
00351
00360 template <typename _InputIterator>
00361 void
00362 insert(_InputIterator __first, _InputIterator __last)
00363 { _M_t.insert_equal(__first, __last); }
00364
00374 void
00375 erase(iterator __position) { _M_t.erase(__position); }
00376
00388 size_type
00389 erase(const key_type& __x) { return _M_t.erase(__x); }
00390
00401 void
00402 erase(iterator __first, iterator __last) { _M_t.erase(__first, __last); }
00403
00415 void
00416 swap(multimap& __x) { _M_t.swap(__x._M_t); }
00417
00424 void
00425 clear() { _M_t.clear(); }
00426
00427
00432 key_compare
00433 key_comp() const { return _M_t.key_comp(); }
00434
00439 value_compare
00440 value_comp() const { return value_compare(_M_t.key_comp()); }
00441
00442
00454 iterator
00455 find(const key_type& __x) { return _M_t.find(__x); }
00456
00468 const_iterator
00469 find(const key_type& __x) const { return _M_t.find(__x); }
00470
00476 size_type
00477 count(const key_type& __x) const { return _M_t.count(__x); }
00478
00490 iterator
00491 lower_bound(const key_type& __x) { return _M_t.lower_bound(__x); }
00492
00504 const_iterator
00505 lower_bound(const key_type& __x) const { return _M_t.lower_bound(__x); }
00506
00512 iterator
00513 upper_bound(const key_type& __x) { return _M_t.upper_bound(__x); }
00514
00521 const_iterator
00522 upper_bound(const key_type& __x) const { return _M_t.upper_bound(__x); }
00523
00537 pair<iterator,iterator>
00538 equal_range(const key_type& __x) { return _M_t.equal_range(__x); }
00539
00553 pair<const_iterator,const_iterator>
00554 equal_range(const key_type& __x) const { return _M_t.equal_range(__x); }
00555
00556 template <typename _K1, typename _T1, typename _C1, typename _A1>
00557 friend bool operator== (const multimap<_K1,_T1,_C1,_A1>&,
00558 const multimap<_K1,_T1,_C1,_A1>&);
00559 template <typename _K1, typename _T1, typename _C1, typename _A1>
00560 friend bool operator< (const multimap<_K1,_T1,_C1,_A1>&,
00561 const multimap<_K1,_T1,_C1,_A1>&);
00562 };
00563
00564
00575 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00576 inline bool
00577 operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
00578 const multimap<_Key,_Tp,_Compare,_Alloc>& __y)
00579 {
00580 return __x._M_t == __y._M_t;
00581 }
00582
00594 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00595 inline bool
00596 operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
00597 const multimap<_Key,_Tp,_Compare,_Alloc>& __y)
00598 { return __x._M_t < __y._M_t; }
00599
00601 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00602 inline bool
00603 operator!=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
00604 const multimap<_Key,_Tp,_Compare,_Alloc>& __y)
00605 { return !(__x == __y); }
00606
00608 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00609 inline bool
00610 operator>(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
00611 const multimap<_Key,_Tp,_Compare,_Alloc>& __y)
00612 { return __y < __x; }
00613
00615 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00616 inline bool
00617 operator<=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
00618 const multimap<_Key,_Tp,_Compare,_Alloc>& __y)
00619 { return !(__y < __x); }
00620
00622 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00623 inline bool
00624 operator>=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
00625 const multimap<_Key,_Tp,_Compare,_Alloc>& __y)
00626 { return !(__x < __y); }
00627
00629 template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
00630 inline void
00631 swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x,
00632 multimap<_Key,_Tp,_Compare,_Alloc>& __y)
00633 { __x.swap(__y); }
00634 }
00635
00636 #endif