libstdc++
|
00001 // Profiling deque 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/deque 00026 * This file is a GNU profile extension to the Standard C++ Library. 00027 */ 00028 00029 #ifndef _GLIBCXX_PROFILE_DEQUE 00030 #define _GLIBCXX_PROFILE_DEQUE 1 00031 00032 #include <deque> 00033 00034 namespace std _GLIBCXX_VISIBILITY(default) 00035 { 00036 namespace __profile 00037 { 00038 /// Class std::deque wrapper with performance instrumentation. 00039 template<typename _Tp, typename _Allocator = std::allocator<_Tp> > 00040 class deque 00041 : public _GLIBCXX_STD_C::deque<_Tp, _Allocator> 00042 { 00043 typedef _GLIBCXX_STD_C::deque<_Tp, _Allocator> _Base; 00044 00045 public: 00046 typedef typename _Base::reference reference; 00047 typedef typename _Base::const_reference const_reference; 00048 00049 typedef typename _Base::iterator iterator; 00050 typedef typename _Base::const_iterator const_iterator; 00051 typedef typename _Base::reverse_iterator reverse_iterator; 00052 typedef typename _Base::const_reverse_iterator const_reverse_iterator; 00053 00054 typedef typename _Base::size_type size_type; 00055 typedef typename _Base::difference_type difference_type; 00056 00057 typedef _Tp value_type; 00058 typedef _Allocator allocator_type; 00059 typedef typename _Base::pointer pointer; 00060 typedef typename _Base::const_pointer const_pointer; 00061 00062 // 23.2.1.1 construct/copy/destroy: 00063 explicit 00064 deque(const _Allocator& __a = _Allocator()) 00065 : _Base(__a) { } 00066 00067 #if __cplusplus >= 201103L 00068 explicit 00069 deque(size_type __n) 00070 : _Base(__n) { } 00071 00072 deque(size_type __n, const _Tp& __value, 00073 const _Allocator& __a = _Allocator()) 00074 : _Base(__n, __value, __a) { } 00075 #else 00076 explicit 00077 deque(size_type __n, const _Tp& __value = _Tp(), 00078 const _Allocator& __a = _Allocator()) 00079 : _Base(__n, __value, __a) { } 00080 #endif 00081 00082 #if __cplusplus >= 201103L 00083 template<typename _InputIterator, 00084 typename = std::_RequireInputIter<_InputIterator>> 00085 #else 00086 template<typename _InputIterator> 00087 #endif 00088 deque(_InputIterator __first, _InputIterator __last, 00089 const _Allocator& __a = _Allocator()) 00090 : _Base(__first, __last, __a) 00091 { } 00092 00093 deque(const deque& __x) 00094 : _Base(__x) { } 00095 00096 deque(const _Base& __x) 00097 : _Base(__x) { } 00098 00099 #if __cplusplus >= 201103L 00100 deque(deque&& __x) 00101 : _Base(std::move(__x)) 00102 { } 00103 00104 deque(initializer_list<value_type> __l, 00105 const allocator_type& __a = allocator_type()) 00106 : _Base(__l, __a) { } 00107 #endif 00108 00109 ~deque() _GLIBCXX_NOEXCEPT { } 00110 00111 deque& 00112 operator=(const deque& __x) 00113 { 00114 *static_cast<_Base*>(this) = __x; 00115 return *this; 00116 } 00117 00118 #if __cplusplus >= 201103L 00119 deque& 00120 operator=(deque&& __x) 00121 { 00122 // NB: DR 1204. 00123 // NB: DR 675. 00124 this->clear(); 00125 this->swap(__x); 00126 return *this; 00127 } 00128 00129 deque& 00130 operator=(initializer_list<value_type> __l) 00131 { 00132 *static_cast<_Base*>(this) = __l; 00133 return *this; 00134 } 00135 #endif 00136 00137 #if __cplusplus >= 201103L 00138 template<typename _InputIterator, 00139 typename = std::_RequireInputIter<_InputIterator>> 00140 #else 00141 template<typename _InputIterator> 00142 #endif 00143 void 00144 assign(_InputIterator __first, _InputIterator __last) 00145 { 00146 _Base::assign(__first, __last); 00147 } 00148 00149 void 00150 assign(size_type __n, const _Tp& __t) 00151 { 00152 _Base::assign(__n, __t); 00153 } 00154 00155 #if __cplusplus >= 201103L 00156 void 00157 assign(initializer_list<value_type> __l) 00158 { 00159 _Base::assign(__l); 00160 } 00161 #endif 00162 00163 using _Base::get_allocator; 00164 00165 // iterators: 00166 iterator 00167 begin() _GLIBCXX_NOEXCEPT 00168 { return iterator(_Base::begin()); } 00169 00170 const_iterator 00171 begin() const _GLIBCXX_NOEXCEPT 00172 { return const_iterator(_Base::begin()); } 00173 00174 iterator 00175 end() _GLIBCXX_NOEXCEPT 00176 { return iterator(_Base::end()); } 00177 00178 const_iterator 00179 end() const _GLIBCXX_NOEXCEPT 00180 { return const_iterator(_Base::end()); } 00181 00182 reverse_iterator 00183 rbegin() _GLIBCXX_NOEXCEPT 00184 { return reverse_iterator(end()); } 00185 00186 const_reverse_iterator 00187 rbegin() const _GLIBCXX_NOEXCEPT 00188 { return const_reverse_iterator(end()); } 00189 00190 reverse_iterator 00191 rend() _GLIBCXX_NOEXCEPT 00192 { return reverse_iterator(begin()); } 00193 00194 const_reverse_iterator 00195 rend() const _GLIBCXX_NOEXCEPT 00196 { return const_reverse_iterator(begin()); } 00197 00198 #if __cplusplus >= 201103L 00199 const_iterator 00200 cbegin() const noexcept 00201 { return const_iterator(_Base::begin()); } 00202 00203 const_iterator 00204 cend() const noexcept 00205 { return const_iterator(_Base::end()); } 00206 00207 const_reverse_iterator 00208 crbegin() const noexcept 00209 { return const_reverse_iterator(end()); } 00210 00211 const_reverse_iterator 00212 crend() const noexcept 00213 { return const_reverse_iterator(begin()); } 00214 #endif 00215 00216 // 23.2.1.2 capacity: 00217 using _Base::size; 00218 using _Base::max_size; 00219 00220 #if __cplusplus >= 201103L 00221 void 00222 resize(size_type __sz) 00223 { 00224 _Base::resize(__sz); 00225 } 00226 00227 void 00228 resize(size_type __sz, const _Tp& __c) 00229 { 00230 _Base::resize(__sz, __c); 00231 } 00232 #else 00233 void 00234 resize(size_type __sz, _Tp __c = _Tp()) 00235 { 00236 _Base::resize(__sz, __c); 00237 } 00238 #endif 00239 00240 #if __cplusplus >= 201103L 00241 using _Base::shrink_to_fit; 00242 #endif 00243 00244 using _Base::empty; 00245 00246 // element access: 00247 reference 00248 operator[](size_type __n) 00249 { 00250 return _M_base()[__n]; 00251 } 00252 00253 const_reference 00254 operator[](size_type __n) const 00255 { 00256 return _M_base()[__n]; 00257 } 00258 00259 using _Base::at; 00260 00261 reference 00262 front() 00263 { 00264 return _Base::front(); 00265 } 00266 00267 const_reference 00268 front() const 00269 { 00270 return _Base::front(); 00271 } 00272 00273 reference 00274 back() 00275 { 00276 return _Base::back(); 00277 } 00278 00279 const_reference 00280 back() const 00281 { 00282 return _Base::back(); 00283 } 00284 00285 // 23.2.1.3 modifiers: 00286 void 00287 push_front(const _Tp& __x) 00288 { 00289 _Base::push_front(__x); 00290 } 00291 00292 void 00293 push_back(const _Tp& __x) 00294 { 00295 _Base::push_back(__x); 00296 } 00297 00298 #if __cplusplus >= 201103L 00299 void 00300 push_front(_Tp&& __x) 00301 { emplace_front(std::move(__x)); } 00302 00303 void 00304 push_back(_Tp&& __x) 00305 { emplace_back(std::move(__x)); } 00306 00307 template<typename... _Args> 00308 void 00309 emplace_front(_Args&&... __args) 00310 { 00311 _Base::emplace_front(std::forward<_Args>(__args)...); 00312 } 00313 00314 template<typename... _Args> 00315 void 00316 emplace_back(_Args&&... __args) 00317 { 00318 _Base::emplace_back(std::forward<_Args>(__args)...); 00319 } 00320 00321 template<typename... _Args> 00322 iterator 00323 emplace(iterator __position, _Args&&... __args) 00324 { 00325 typename _Base::iterator __res = _Base::emplace(__position, 00326 std::forward<_Args>(__args)...); 00327 return iterator(__res); 00328 } 00329 #endif 00330 00331 iterator 00332 insert(iterator __position, const _Tp& __x) 00333 { 00334 typename _Base::iterator __res = _Base::insert(__position, __x); 00335 return iterator(__res); 00336 } 00337 00338 #if __cplusplus >= 201103L 00339 iterator 00340 insert(iterator __position, _Tp&& __x) 00341 { return emplace(__position, std::move(__x)); } 00342 00343 void 00344 insert(iterator __p, initializer_list<value_type> __l) 00345 { 00346 _Base::insert(__p, __l); 00347 } 00348 #endif 00349 00350 void 00351 insert(iterator __position, size_type __n, const _Tp& __x) 00352 { 00353 _Base::insert(__position, __n, __x); 00354 } 00355 00356 #if __cplusplus >= 201103L 00357 template<typename _InputIterator, 00358 typename = std::_RequireInputIter<_InputIterator>> 00359 #else 00360 template<typename _InputIterator> 00361 #endif 00362 void 00363 insert(iterator __position, 00364 _InputIterator __first, _InputIterator __last) 00365 { 00366 _Base::insert(__position, __first, __last); 00367 } 00368 00369 void 00370 pop_front() 00371 { 00372 _Base::pop_front(); 00373 } 00374 00375 void 00376 pop_back() 00377 { 00378 _Base::pop_back(); 00379 } 00380 00381 iterator 00382 erase(iterator __position) 00383 { 00384 if (__position == begin() || __position == end()-1) 00385 { 00386 return iterator(_Base::erase(__position)); 00387 } 00388 else 00389 { 00390 typename _Base::iterator __res = _Base::erase(__position); 00391 return iterator(__res); 00392 } 00393 } 00394 00395 iterator 00396 erase(iterator __first, iterator __last) 00397 { 00398 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00399 // 151. can't currently clear() empty container 00400 return iterator(_Base::erase(__first, __last)); 00401 } 00402 00403 void 00404 swap(deque& __x) 00405 { 00406 _Base::swap(__x); 00407 } 00408 00409 void 00410 clear() _GLIBCXX_NOEXCEPT 00411 { 00412 _Base::clear(); 00413 } 00414 00415 _Base& 00416 _M_base() _GLIBCXX_NOEXCEPT { return *this; } 00417 00418 const _Base& 00419 _M_base() const _GLIBCXX_NOEXCEPT { return *this; } 00420 }; 00421 00422 template<typename _Tp, typename _Alloc> 00423 inline bool 00424 operator==(const deque<_Tp, _Alloc>& __lhs, 00425 const deque<_Tp, _Alloc>& __rhs) 00426 { return __lhs._M_base() == __rhs._M_base(); } 00427 00428 template<typename _Tp, typename _Alloc> 00429 inline bool 00430 operator!=(const deque<_Tp, _Alloc>& __lhs, 00431 const deque<_Tp, _Alloc>& __rhs) 00432 { return __lhs._M_base() != __rhs._M_base(); } 00433 00434 template<typename _Tp, typename _Alloc> 00435 inline bool 00436 operator<(const deque<_Tp, _Alloc>& __lhs, 00437 const deque<_Tp, _Alloc>& __rhs) 00438 { return __lhs._M_base() < __rhs._M_base(); } 00439 00440 template<typename _Tp, typename _Alloc> 00441 inline bool 00442 operator<=(const deque<_Tp, _Alloc>& __lhs, 00443 const deque<_Tp, _Alloc>& __rhs) 00444 { return __lhs._M_base() <= __rhs._M_base(); } 00445 00446 template<typename _Tp, typename _Alloc> 00447 inline bool 00448 operator>=(const deque<_Tp, _Alloc>& __lhs, 00449 const deque<_Tp, _Alloc>& __rhs) 00450 { return __lhs._M_base() >= __rhs._M_base(); } 00451 00452 template<typename _Tp, typename _Alloc> 00453 inline bool 00454 operator>(const deque<_Tp, _Alloc>& __lhs, 00455 const deque<_Tp, _Alloc>& __rhs) 00456 { return __lhs._M_base() > __rhs._M_base(); } 00457 00458 template<typename _Tp, typename _Alloc> 00459 inline void 00460 swap(deque<_Tp, _Alloc>& __lhs, deque<_Tp, _Alloc>& __rhs) 00461 { __lhs.swap(__rhs); } 00462 00463 } // namespace __profile 00464 } // namespace std 00465 00466 #endif