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