libstdc++
|
00001 // Profiling multimap implementation -*- C++ -*- 00002 00003 // Copyright (C) 2009-2013 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file profile/multimap.h 00026 * This file is a GNU profile extension to the Standard C++ Library. 00027 */ 00028 00029 #ifndef _GLIBCXX_PROFILE_MULTIMAP_H 00030 #define _GLIBCXX_PROFILE_MULTIMAP_H 1 00031 00032 #include <utility> 00033 00034 namespace std _GLIBCXX_VISIBILITY(default) 00035 { 00036 namespace __profile 00037 { 00038 /// Class std::multimap wrapper with performance instrumentation. 00039 template<typename _Key, typename _Tp, typename _Compare = std::less<_Key>, 00040 typename _Allocator = std::allocator<std::pair<const _Key, _Tp> > > 00041 class multimap 00042 : public _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator> 00043 { 00044 typedef _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Allocator> _Base; 00045 00046 public: 00047 // types: 00048 typedef _Key key_type; 00049 typedef _Tp mapped_type; 00050 typedef std::pair<const _Key, _Tp> value_type; 00051 typedef _Compare key_compare; 00052 typedef _Allocator allocator_type; 00053 typedef typename _Base::reference reference; 00054 typedef typename _Base::const_reference const_reference; 00055 00056 typedef typename _Base::iterator iterator; 00057 typedef typename _Base::const_iterator const_iterator; 00058 typedef typename _Base::reverse_iterator reverse_iterator; 00059 typedef typename _Base::const_reverse_iterator const_reverse_iterator; 00060 00061 typedef typename _Base::size_type size_type; 00062 typedef typename _Base::difference_type difference_type; 00063 typedef typename _Base::pointer pointer; 00064 typedef typename _Base::const_pointer const_pointer; 00065 00066 // 23.3.1.1 construct/copy/destroy: 00067 explicit multimap(const _Compare& __comp = _Compare(), 00068 const _Allocator& __a = _Allocator()) 00069 : _Base(__comp, __a) { } 00070 00071 #if __cplusplus >= 201103L 00072 template<typename _InputIterator, 00073 typename = std::_RequireInputIter<_InputIterator>> 00074 #else 00075 template<typename _InputIterator> 00076 #endif 00077 multimap(_InputIterator __first, _InputIterator __last, 00078 const _Compare& __comp = _Compare(), 00079 const _Allocator& __a = _Allocator()) 00080 : _Base(__first, __last, __comp, __a) { } 00081 00082 multimap(const multimap& __x) 00083 : _Base(__x) { } 00084 00085 multimap(const _Base& __x) 00086 : _Base(__x) { } 00087 00088 #if __cplusplus >= 201103L 00089 multimap(multimap&& __x) 00090 noexcept(is_nothrow_copy_constructible<_Compare>::value) 00091 : _Base(std::move(__x)) 00092 { } 00093 00094 multimap(initializer_list<value_type> __l, 00095 const _Compare& __c = _Compare(), 00096 const allocator_type& __a = allocator_type()) 00097 : _Base(__l, __c, __a) { } 00098 #endif 00099 00100 ~multimap() _GLIBCXX_NOEXCEPT { } 00101 00102 multimap& 00103 operator=(const multimap& __x) 00104 { 00105 *static_cast<_Base*>(this) = __x; 00106 return *this; 00107 } 00108 00109 #if __cplusplus >= 201103L 00110 multimap& 00111 operator=(multimap&& __x) 00112 { 00113 // NB: DR 1204. 00114 // NB: DR 675. 00115 this->clear(); 00116 this->swap(__x); 00117 return *this; 00118 } 00119 00120 multimap& 00121 operator=(initializer_list<value_type> __l) 00122 { 00123 this->clear(); 00124 this->insert(__l); 00125 return *this; 00126 } 00127 #endif 00128 00129 using _Base::get_allocator; 00130 00131 // iterators: 00132 iterator 00133 begin() _GLIBCXX_NOEXCEPT 00134 { return iterator(_Base::begin()); } 00135 00136 const_iterator 00137 begin() const _GLIBCXX_NOEXCEPT 00138 { return const_iterator(_Base::begin()); } 00139 00140 iterator 00141 end() _GLIBCXX_NOEXCEPT 00142 { return iterator(_Base::end()); } 00143 00144 const_iterator 00145 end() const _GLIBCXX_NOEXCEPT 00146 { return const_iterator(_Base::end()); } 00147 00148 reverse_iterator 00149 rbegin() _GLIBCXX_NOEXCEPT 00150 { return reverse_iterator(end()); } 00151 00152 const_reverse_iterator 00153 rbegin() const _GLIBCXX_NOEXCEPT 00154 { return const_reverse_iterator(end()); } 00155 00156 reverse_iterator 00157 rend() _GLIBCXX_NOEXCEPT 00158 { return reverse_iterator(begin()); } 00159 00160 const_reverse_iterator 00161 rend() const _GLIBCXX_NOEXCEPT 00162 { return const_reverse_iterator(begin()); } 00163 00164 #if __cplusplus >= 201103L 00165 const_iterator 00166 cbegin() const noexcept 00167 { return const_iterator(_Base::begin()); } 00168 00169 const_iterator 00170 cend() const noexcept 00171 { return const_iterator(_Base::end()); } 00172 00173 const_reverse_iterator 00174 crbegin() const noexcept 00175 { return const_reverse_iterator(end()); } 00176 00177 const_reverse_iterator 00178 crend() const noexcept 00179 { return const_reverse_iterator(begin()); } 00180 #endif 00181 00182 // capacity: 00183 using _Base::empty; 00184 using _Base::size; 00185 using _Base::max_size; 00186 00187 // modifiers: 00188 #if __cplusplus >= 201103L 00189 template<typename... _Args> 00190 iterator 00191 emplace(_Args&&... __args) 00192 { 00193 return iterator(_Base::emplace(std::forward<_Args>(__args)...)); 00194 } 00195 00196 template<typename... _Args> 00197 iterator 00198 emplace_hint(const_iterator __pos, _Args&&... __args) 00199 { 00200 return iterator(_Base::emplace_hint(__pos, 00201 std::forward<_Args>(__args)...)); 00202 } 00203 #endif 00204 00205 iterator 00206 insert(const value_type& __x) 00207 { return iterator(_Base::insert(__x)); } 00208 00209 #if __cplusplus >= 201103L 00210 template<typename _Pair, typename = typename 00211 std::enable_if<std::is_constructible<value_type, 00212 _Pair&&>::value>::type> 00213 iterator 00214 insert(_Pair&& __x) 00215 { return iterator(_Base::insert(std::forward<_Pair>(__x))); } 00216 #endif 00217 00218 #if __cplusplus >= 201103L 00219 void 00220 insert(std::initializer_list<value_type> __list) 00221 { _Base::insert(__list); } 00222 #endif 00223 00224 iterator 00225 #if __cplusplus >= 201103L 00226 insert(const_iterator __position, const value_type& __x) 00227 #else 00228 insert(iterator __position, const value_type& __x) 00229 #endif 00230 { return iterator(_Base::insert(__position, __x)); } 00231 00232 #if __cplusplus >= 201103L 00233 template<typename _Pair, typename = typename 00234 std::enable_if<std::is_constructible<value_type, 00235 _Pair&&>::value>::type> 00236 iterator 00237 insert(const_iterator __position, _Pair&& __x) 00238 { return iterator(_Base::insert(__position, 00239 std::forward<_Pair>(__x))); } 00240 #endif 00241 00242 #if __cplusplus >= 201103L 00243 template<typename _InputIterator, 00244 typename = std::_RequireInputIter<_InputIterator>> 00245 #else 00246 template<typename _InputIterator> 00247 #endif 00248 void 00249 insert(_InputIterator __first, _InputIterator __last) 00250 { _Base::insert(__first, __last); } 00251 00252 #if __cplusplus >= 201103L 00253 iterator 00254 erase(const_iterator __position) 00255 { return iterator(_Base::erase(__position)); } 00256 00257 iterator 00258 erase(iterator __position) 00259 { return iterator(_Base::erase(__position)); } 00260 #else 00261 void 00262 erase(iterator __position) 00263 { _Base::erase(__position); } 00264 #endif 00265 00266 size_type 00267 erase(const key_type& __x) 00268 { 00269 std::pair<iterator, iterator> __victims = this->equal_range(__x); 00270 size_type __count = 0; 00271 while (__victims.first != __victims.second) 00272 { 00273 iterator __victim = __victims.first++; 00274 _Base::erase(__victim); 00275 ++__count; 00276 } 00277 return __count; 00278 } 00279 00280 #if __cplusplus >= 201103L 00281 iterator 00282 erase(const_iterator __first, const_iterator __last) 00283 { return iterator(_Base::erase(__first, __last)); } 00284 #else 00285 void 00286 erase(iterator __first, iterator __last) 00287 { _Base::erase(__first, __last); } 00288 #endif 00289 00290 void 00291 swap(multimap& __x) 00292 { _Base::swap(__x); } 00293 00294 void 00295 clear() _GLIBCXX_NOEXCEPT 00296 { this->erase(begin(), end()); } 00297 00298 // observers: 00299 using _Base::key_comp; 00300 using _Base::value_comp; 00301 00302 // 23.3.1.3 multimap operations: 00303 iterator 00304 find(const key_type& __x) 00305 { return iterator(_Base::find(__x)); } 00306 00307 const_iterator 00308 find(const key_type& __x) const 00309 { return const_iterator(_Base::find(__x)); } 00310 00311 using _Base::count; 00312 00313 iterator 00314 lower_bound(const key_type& __x) 00315 { return iterator(_Base::lower_bound(__x)); } 00316 00317 const_iterator 00318 lower_bound(const key_type& __x) const 00319 { return const_iterator(_Base::lower_bound(__x)); } 00320 00321 iterator 00322 upper_bound(const key_type& __x) 00323 { return iterator(_Base::upper_bound(__x)); } 00324 00325 const_iterator 00326 upper_bound(const key_type& __x) const 00327 { return const_iterator(_Base::upper_bound(__x)); } 00328 00329 std::pair<iterator,iterator> 00330 equal_range(const key_type& __x) 00331 { 00332 typedef typename _Base::iterator _Base_iterator; 00333 std::pair<_Base_iterator, _Base_iterator> __res = 00334 _Base::equal_range(__x); 00335 return std::make_pair(iterator(__res.first), 00336 iterator(__res.second)); 00337 } 00338 00339 std::pair<const_iterator,const_iterator> 00340 equal_range(const key_type& __x) const 00341 { 00342 typedef typename _Base::const_iterator _Base_const_iterator; 00343 std::pair<_Base_const_iterator, _Base_const_iterator> __res = 00344 _Base::equal_range(__x); 00345 return std::make_pair(const_iterator(__res.first), 00346 const_iterator(__res.second)); 00347 } 00348 00349 _Base& 00350 _M_base() _GLIBCXX_NOEXCEPT { return *this; } 00351 00352 const _Base& 00353 _M_base() const _GLIBCXX_NOEXCEPT { return *this; } 00354 }; 00355 00356 template<typename _Key, typename _Tp, 00357 typename _Compare, typename _Allocator> 00358 inline bool 00359 operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, 00360 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) 00361 { return __lhs._M_base() == __rhs._M_base(); } 00362 00363 template<typename _Key, typename _Tp, 00364 typename _Compare, typename _Allocator> 00365 inline bool 00366 operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, 00367 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) 00368 { return __lhs._M_base() != __rhs._M_base(); } 00369 00370 template<typename _Key, typename _Tp, 00371 typename _Compare, typename _Allocator> 00372 inline bool 00373 operator<(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, 00374 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) 00375 { return __lhs._M_base() < __rhs._M_base(); } 00376 00377 template<typename _Key, typename _Tp, 00378 typename _Compare, typename _Allocator> 00379 inline bool 00380 operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, 00381 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) 00382 { return __lhs._M_base() <= __rhs._M_base(); } 00383 00384 template<typename _Key, typename _Tp, 00385 typename _Compare, typename _Allocator> 00386 inline bool 00387 operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, 00388 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) 00389 { return __lhs._M_base() >= __rhs._M_base(); } 00390 00391 template<typename _Key, typename _Tp, 00392 typename _Compare, typename _Allocator> 00393 inline bool 00394 operator>(const multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, 00395 const multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) 00396 { return __lhs._M_base() > __rhs._M_base(); } 00397 00398 template<typename _Key, typename _Tp, 00399 typename _Compare, typename _Allocator> 00400 inline void 00401 swap(multimap<_Key, _Tp, _Compare, _Allocator>& __lhs, 00402 multimap<_Key, _Tp, _Compare, _Allocator>& __rhs) 00403 { __lhs.swap(__rhs); } 00404 00405 } // namespace __profile 00406 } // namespace std 00407 00408 #endif