|
libstdc++
|
00001 // <forward_list> -*- C++ -*- 00002 00003 // Copyright (C) 2010, 2011, 2012 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 debug/forward_list 00026 * This file is a GNU debug extension to the Standard C++ Library. 00027 */ 00028 00029 #ifndef _GLIBCXX_DEBUG_FORWARD_LIST 00030 #define _GLIBCXX_DEBUG_FORWARD_LIST 1 00031 00032 #pragma GCC system_header 00033 00034 #include <forward_list> 00035 #include <debug/safe_sequence.h> 00036 #include <debug/safe_iterator.h> 00037 00038 namespace std _GLIBCXX_VISIBILITY(default) 00039 { 00040 namespace __debug 00041 { 00042 /// Class std::forward_list with safety/checking/debug instrumentation. 00043 template<typename _Tp, typename _Alloc = std::allocator<_Tp> > 00044 class forward_list 00045 : public _GLIBCXX_STD_C::forward_list<_Tp, _Alloc>, 00046 public __gnu_debug::_Safe_sequence<forward_list<_Tp, _Alloc> > 00047 { 00048 typedef _GLIBCXX_STD_C::forward_list<_Tp, _Alloc> _Base; 00049 00050 typedef typename _Base::iterator _Base_iterator; 00051 typedef typename _Base::const_iterator _Base_const_iterator; 00052 public: 00053 typedef typename _Base::reference reference; 00054 typedef typename _Base::const_reference const_reference; 00055 00056 typedef __gnu_debug::_Safe_iterator<_Base_iterator, 00057 forward_list> iterator; 00058 typedef __gnu_debug::_Safe_iterator<_Base_const_iterator, 00059 forward_list> const_iterator; 00060 00061 typedef typename _Base::size_type size_type; 00062 typedef typename _Base::difference_type difference_type; 00063 00064 typedef _Tp value_type; 00065 typedef _Alloc allocator_type; 00066 typedef typename _Base::pointer pointer; 00067 typedef typename _Base::const_pointer const_pointer; 00068 00069 // 23.2.3.1 construct/copy/destroy: 00070 explicit 00071 forward_list(const _Alloc& __al = _Alloc()) 00072 : _Base(__al) { } 00073 00074 forward_list(const forward_list& __list, const _Alloc& __al) 00075 : _Base(__list, __al) 00076 { } 00077 00078 forward_list(forward_list&& __list, const _Alloc& __al) 00079 : _Base(std::move(__list._M_base()), __al) 00080 { 00081 this->_M_swap(__list); 00082 } 00083 00084 explicit 00085 forward_list(size_type __n) 00086 : _Base(__n) 00087 { } 00088 00089 forward_list(size_type __n, const _Tp& __value, 00090 const _Alloc& __al = _Alloc()) 00091 : _Base(__n, __value, __al) 00092 { } 00093 00094 template<typename _InputIterator, 00095 typename = std::_RequireInputIter<_InputIterator>> 00096 forward_list(_InputIterator __first, _InputIterator __last, 00097 const _Alloc& __al = _Alloc()) 00098 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first, 00099 __last)), 00100 __gnu_debug::__base(__last), __al) 00101 { } 00102 00103 forward_list(const forward_list& __list) 00104 : _Base(__list) 00105 { } 00106 00107 forward_list(forward_list&& __list) noexcept 00108 : _Base(std::move(__list._M_base())) 00109 { 00110 this->_M_swap(__list); 00111 } 00112 00113 forward_list(std::initializer_list<_Tp> __il, 00114 const _Alloc& __al = _Alloc()) 00115 : _Base(__il, __al) 00116 { } 00117 00118 ~forward_list() noexcept 00119 { } 00120 00121 forward_list& 00122 operator=(const forward_list& __list) 00123 { 00124 static_cast<_Base&>(*this) = __list; 00125 this->_M_invalidate_all(); 00126 return *this; 00127 } 00128 00129 forward_list& 00130 operator=(forward_list&& __list) 00131 { 00132 // NB: DR 1204. 00133 // NB: DR 675. 00134 __glibcxx_check_self_move_assign(__list); 00135 clear(); 00136 swap(__list); 00137 return *this; 00138 } 00139 00140 forward_list& 00141 operator=(std::initializer_list<_Tp> __il) 00142 { 00143 static_cast<_Base&>(*this) = __il; 00144 this->_M_invalidate_all(); 00145 return *this; 00146 } 00147 00148 template<typename _InputIterator, 00149 typename = std::_RequireInputIter<_InputIterator>> 00150 void 00151 assign(_InputIterator __first, _InputIterator __last) 00152 { 00153 __glibcxx_check_valid_range(__first, __last); 00154 _Base::assign(__gnu_debug::__base(__first), 00155 __gnu_debug::__base(__last)); 00156 this->_M_invalidate_all(); 00157 } 00158 00159 void 00160 assign(size_type __n, const _Tp& __val) 00161 { 00162 _Base::assign(__n, __val); 00163 this->_M_invalidate_all(); 00164 } 00165 00166 void 00167 assign(std::initializer_list<_Tp> __il) 00168 { 00169 _Base::assign(__il); 00170 this->_M_invalidate_all(); 00171 } 00172 00173 using _Base::get_allocator; 00174 00175 // iterators: 00176 00177 iterator 00178 before_begin() noexcept 00179 { return iterator(_Base::before_begin(), this); } 00180 00181 const_iterator 00182 before_begin() const noexcept 00183 { return const_iterator(_Base::before_begin(), this); } 00184 00185 iterator 00186 begin() noexcept 00187 { return iterator(_Base::begin(), this); } 00188 00189 const_iterator 00190 begin() const noexcept 00191 { return const_iterator(_Base::begin(), this); } 00192 00193 iterator 00194 end() noexcept 00195 { return iterator(_Base::end(), this); } 00196 00197 const_iterator 00198 end() const noexcept 00199 { return const_iterator(_Base::end(), this); } 00200 00201 const_iterator 00202 cbegin() const noexcept 00203 { return const_iterator(_Base::cbegin(), this); } 00204 00205 const_iterator 00206 cbefore_begin() const noexcept 00207 { return const_iterator(_Base::cbefore_begin(), this); } 00208 00209 const_iterator 00210 cend() const noexcept 00211 { return const_iterator(_Base::cend(), this); } 00212 00213 using _Base::empty; 00214 using _Base::max_size; 00215 00216 // element access: 00217 00218 reference 00219 front() 00220 { 00221 __glibcxx_check_nonempty(); 00222 return _Base::front(); 00223 } 00224 00225 const_reference 00226 front() const 00227 { 00228 __glibcxx_check_nonempty(); 00229 return _Base::front(); 00230 } 00231 00232 // modiļ¬ers: 00233 00234 using _Base::emplace_front; 00235 using _Base::push_front; 00236 00237 void 00238 pop_front() 00239 { 00240 __glibcxx_check_nonempty(); 00241 this->_M_invalidate_if([this](_Base_const_iterator __it) 00242 { return __it == this->_M_base().cbegin(); }); 00243 _Base::pop_front(); 00244 } 00245 00246 template<typename... _Args> 00247 iterator 00248 emplace_after(const_iterator __pos, _Args&&... __args) 00249 { 00250 __glibcxx_check_insert_after(__pos); 00251 return iterator(_Base::emplace_after(__pos.base(), 00252 std::forward<_Args>(__args)...), 00253 this); 00254 } 00255 00256 iterator 00257 insert_after(const_iterator __pos, const _Tp& __val) 00258 { 00259 __glibcxx_check_insert_after(__pos); 00260 return iterator(_Base::insert_after(__pos.base(), __val), this); 00261 } 00262 00263 iterator 00264 insert_after(const_iterator __pos, _Tp&& __val) 00265 { 00266 __glibcxx_check_insert_after(__pos); 00267 return iterator(_Base::insert_after(__pos.base(), std::move(__val)), 00268 this); 00269 } 00270 00271 iterator 00272 insert_after(const_iterator __pos, size_type __n, const _Tp& __val) 00273 { 00274 __glibcxx_check_insert_after(__pos); 00275 return iterator(_Base::insert_after(__pos.base(), __n, __val), 00276 this); 00277 } 00278 00279 template<typename _InputIterator, 00280 typename = std::_RequireInputIter<_InputIterator>> 00281 iterator 00282 insert_after(const_iterator __pos, 00283 _InputIterator __first, _InputIterator __last) 00284 { 00285 __glibcxx_check_insert_range_after(__pos, __first, __last); 00286 return iterator(_Base::insert_after(__pos.base(), 00287 __gnu_debug::__base(__first), 00288 __gnu_debug::__base(__last)), 00289 this); 00290 } 00291 00292 iterator 00293 insert_after(const_iterator __pos, std::initializer_list<_Tp> __il) 00294 { 00295 __glibcxx_check_insert_after(__pos); 00296 return iterator(_Base::insert_after(__pos.base(), __il), this); 00297 } 00298 00299 private: 00300 _Base_iterator 00301 _M_erase_after(_Base_const_iterator __pos) 00302 { 00303 _Base_const_iterator __next = std::next(__pos); 00304 this->_M_invalidate_if([__next](_Base_const_iterator __it) 00305 { return __it == __next; }); 00306 return _Base::erase_after(__pos); 00307 } 00308 public: 00309 iterator 00310 erase_after(const_iterator __pos) 00311 { 00312 __glibcxx_check_erase_after(__pos); 00313 return iterator(_M_erase_after(__pos.base()), this); 00314 } 00315 00316 iterator 00317 erase_after(const_iterator __pos, const_iterator __last) 00318 { 00319 __glibcxx_check_erase_range_after(__pos, __last); 00320 for (_Base_const_iterator __victim = std::next(__pos.base()); 00321 __victim != __last.base(); ++__victim) 00322 { 00323 _GLIBCXX_DEBUG_VERIFY(__victim != _Base::end(), 00324 _M_message(__gnu_debug::__msg_valid_range2) 00325 ._M_sequence(*this, "this") 00326 ._M_iterator(__pos, "pos") 00327 ._M_iterator(__last, "last")); 00328 this->_M_invalidate_if([__victim](_Base_const_iterator __it) 00329 { return __it == __victim; }); 00330 } 00331 return iterator(_Base::erase_after(__pos.base(), __last.base()), this); 00332 } 00333 00334 void 00335 swap(forward_list& __list) 00336 { 00337 _Base::swap(__list); 00338 this->_M_swap(__list); 00339 } 00340 00341 void 00342 resize(size_type __sz) 00343 { 00344 this->_M_detach_singular(); 00345 00346 // if __sz < size(), invalidate all iterators in [begin+__sz, end() 00347 _Base_iterator __victim = _Base::begin(); 00348 _Base_iterator __end = _Base::end(); 00349 for (size_type __i = __sz; __victim != __end && __i > 0; --__i) 00350 ++__victim; 00351 00352 for (; __victim != __end; ++__victim) 00353 { 00354 this->_M_invalidate_if([__victim](_Base_const_iterator __it) 00355 { return __it == __victim; }); 00356 } 00357 00358 __try 00359 { 00360 _Base::resize(__sz); 00361 } 00362 __catch(...) 00363 { 00364 this->_M_revalidate_singular(); 00365 __throw_exception_again; 00366 } 00367 } 00368 00369 void 00370 resize(size_type __sz, const value_type& __val) 00371 { 00372 this->_M_detach_singular(); 00373 00374 // if __sz < size(), invalidate all iterators in [begin+__sz, end()) 00375 _Base_iterator __victim = _Base::begin(); 00376 _Base_iterator __end = _Base::end(); 00377 for (size_type __i = __sz; __victim != __end && __i > 0; --__i) 00378 ++__victim; 00379 00380 for (; __victim != __end; ++__victim) 00381 { 00382 this->_M_invalidate_if([__victim](_Base_const_iterator __it) 00383 { return __it == __victim; }); 00384 } 00385 00386 __try 00387 { 00388 _Base::resize(__sz, __val); 00389 } 00390 __catch(...) 00391 { 00392 this->_M_revalidate_singular(); 00393 __throw_exception_again; 00394 } 00395 } 00396 00397 void 00398 clear() noexcept 00399 { 00400 _Base::clear(); 00401 this->_M_invalidate_all(); 00402 } 00403 00404 // 23.2.3.5 forward_list operations: 00405 void 00406 splice_after(const_iterator __pos, forward_list&& __list) 00407 { 00408 __glibcxx_check_insert_after(__pos); 00409 _GLIBCXX_DEBUG_VERIFY(&__list != this, 00410 _M_message(__gnu_debug::__msg_self_splice) 00411 ._M_sequence(*this, "this")); 00412 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(), 00413 _M_message(__gnu_debug::__msg_splice_alloc) 00414 ._M_sequence(*this) 00415 ._M_sequence(__list, "__list")); 00416 this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it) 00417 { 00418 return __it != __list._M_base().cbefore_begin() 00419 && __it != __list._M_base().end(); 00420 }); 00421 _Base::splice_after(__pos.base(), std::move(__list._M_base())); 00422 } 00423 00424 void 00425 splice_after(const_iterator __pos, forward_list& __list) 00426 { splice_after(__pos, std::move(__list)); } 00427 00428 void 00429 splice_after(const_iterator __pos, forward_list&& __list, 00430 const_iterator __i) 00431 { 00432 __glibcxx_check_insert_after(__pos); 00433 _GLIBCXX_DEBUG_VERIFY(__i._M_before_dereferenceable(), 00434 _M_message(__gnu_debug::__msg_splice_bad) 00435 ._M_iterator(__i, "__i")); 00436 _GLIBCXX_DEBUG_VERIFY(__i._M_attached_to(&__list), 00437 _M_message(__gnu_debug::__msg_splice_other) 00438 ._M_iterator(__i, "__i") 00439 ._M_sequence(__list, "__list")); 00440 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(), 00441 _M_message(__gnu_debug::__msg_splice_alloc) 00442 ._M_sequence(*this) 00443 ._M_sequence(__list, "__list")); 00444 00445 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00446 // 250. splicing invalidates iterators 00447 _Base_const_iterator __next = std::next(__i.base()); 00448 this->_M_transfer_from_if(__list, [__next](_Base_const_iterator __it) 00449 { return __it == __next; }); 00450 _Base::splice_after(__pos.base(), std::move(__list._M_base()), 00451 __i.base()); 00452 } 00453 00454 void 00455 splice_after(const_iterator __pos, forward_list& __list, 00456 const_iterator __i) 00457 { splice_after(__pos, std::move(__list), __i); } 00458 00459 void 00460 splice_after(const_iterator __pos, forward_list&& __list, 00461 const_iterator __before, const_iterator __last) 00462 { 00463 __glibcxx_check_insert_after(__pos); 00464 __glibcxx_check_valid_range(__before, __last); 00465 _GLIBCXX_DEBUG_VERIFY(__before._M_attached_to(&__list), 00466 _M_message(__gnu_debug::__msg_splice_other) 00467 ._M_sequence(__list, "list") 00468 ._M_iterator(__before, "before")); 00469 _GLIBCXX_DEBUG_VERIFY(__before._M_dereferenceable() 00470 || __before._M_is_before_begin(), 00471 _M_message(__gnu_debug::__msg_valid_range2) 00472 ._M_sequence(__list, "list") 00473 ._M_iterator(__before, "before") 00474 ._M_iterator(__last, "last")); 00475 _GLIBCXX_DEBUG_VERIFY(__before != __last, 00476 _M_message(__gnu_debug::__msg_valid_range2) 00477 ._M_sequence(__list, "list") 00478 ._M_iterator(__before, "before") 00479 ._M_iterator(__last, "last")); 00480 _GLIBCXX_DEBUG_VERIFY(__list.get_allocator() == this->get_allocator(), 00481 _M_message(__gnu_debug::__msg_splice_alloc) 00482 ._M_sequence(*this) 00483 ._M_sequence(__list, "__list")); 00484 00485 for (_Base_const_iterator __tmp = std::next(__before.base()); 00486 __tmp != __last.base(); ++__tmp) 00487 { 00488 _GLIBCXX_DEBUG_VERIFY(__tmp != __list._M_base().end(), 00489 _M_message(__gnu_debug::__msg_valid_range2) 00490 ._M_sequence(__list, "list") 00491 ._M_iterator(__before, "before") 00492 ._M_iterator(__last, "last")); 00493 _GLIBCXX_DEBUG_VERIFY(&__list != this || __tmp != __pos.base(), 00494 _M_message(__gnu_debug::__msg_splice_overlap) 00495 ._M_iterator(__tmp, "position") 00496 ._M_iterator(__before, "before") 00497 ._M_iterator(__last, "last")); 00498 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00499 // 250. splicing invalidates iterators 00500 this->_M_transfer_from_if(__list, [__tmp](_Base_const_iterator __it) 00501 { return __it == __tmp; }); 00502 } 00503 00504 _Base::splice_after(__pos.base(), std::move(__list._M_base()), 00505 __before.base(), __last.base()); 00506 } 00507 00508 void 00509 splice_after(const_iterator __pos, forward_list& __list, 00510 const_iterator __before, const_iterator __last) 00511 { splice_after(__pos, std::move(__list), __before, __last); } 00512 00513 void 00514 remove(const _Tp& __val) 00515 { 00516 _Base_iterator __x = _Base::before_begin(); 00517 _Base_iterator __old = __x++; 00518 while (__x != _Base::end()) 00519 { 00520 if (*__x == __val) 00521 __x = _M_erase_after(__old); 00522 else 00523 __old = __x++; 00524 } 00525 } 00526 00527 template<typename _Pred> 00528 void 00529 remove_if(_Pred __pred) 00530 { 00531 _Base_iterator __x = _Base::before_begin(); 00532 _Base_iterator __old = __x++; 00533 while (__x != _Base::end()) 00534 { 00535 if (__pred(*__x)) 00536 __x = _M_erase_after(__old); 00537 else 00538 __old = __x++; 00539 } 00540 } 00541 00542 void 00543 unique() 00544 { 00545 _Base_iterator __first = _Base::begin(); 00546 _Base_iterator __last = _Base::end(); 00547 if (__first == __last) 00548 return; 00549 _Base_iterator __next = std::next(__first); 00550 while (__next != __last) 00551 { 00552 if (*__first == *__next) 00553 __next = _M_erase_after(__first); 00554 else 00555 __first = __next++; 00556 } 00557 } 00558 00559 template<typename _BinPred> 00560 void 00561 unique(_BinPred __binary_pred) 00562 { 00563 _Base_iterator __first = _Base::begin(); 00564 _Base_iterator __last = _Base::end(); 00565 if (__first == __last) 00566 return; 00567 _Base_iterator __next = std::next(__first); 00568 while (__next != __last) 00569 { 00570 if (__binary_pred(*__first, *__next)) 00571 __next = _M_erase_after(__first); 00572 else 00573 __first = __next++; 00574 } 00575 } 00576 00577 void 00578 merge(forward_list&& __list) 00579 { 00580 if (this != &__list) 00581 { 00582 __glibcxx_check_sorted(_Base::begin(), _Base::end()); 00583 __glibcxx_check_sorted(__list._M_base().begin(), 00584 __list._M_base().end()); 00585 this->_M_transfer_from_if(__list, [&__list](_Base_const_iterator __it) 00586 { 00587 return __it != __list._M_base().cbefore_begin() 00588 && __it != __list._M_base().cend(); 00589 }); 00590 _Base::merge(std::move(__list._M_base())); 00591 } 00592 } 00593 00594 void 00595 merge(forward_list& __list) 00596 { merge(std::move(__list)); } 00597 00598 template<typename _Comp> 00599 void 00600 merge(forward_list&& __list, _Comp __comp) 00601 { 00602 if (this != &__list) 00603 { 00604 __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(), __comp); 00605 __glibcxx_check_sorted_pred(__list._M_base().begin(), 00606 __list._M_base().end(), __comp); 00607 this->_M_transfer_from_if(__list, 00608 [&__list](_Base_const_iterator __it) 00609 { 00610 return __it != __list._M_base().cbefore_begin() 00611 && __it != __list._M_base().cend(); 00612 }); 00613 _Base::merge(std::move(__list._M_base()), __comp); 00614 } 00615 } 00616 00617 template<typename _Comp> 00618 void 00619 merge(forward_list& __list, _Comp __comp) 00620 { merge(std::move(__list), __comp); } 00621 00622 using _Base::sort; 00623 using _Base::reverse; 00624 00625 _Base& 00626 _M_base() noexcept { return *this; } 00627 00628 const _Base& 00629 _M_base() const noexcept { return *this; } 00630 00631 private: 00632 void 00633 _M_invalidate_all() 00634 { 00635 this->_M_invalidate_if([this](_Base_const_iterator __it) 00636 { 00637 return __it != this->_M_base().cbefore_begin() 00638 && __it != this->_M_base().cend(); 00639 }); 00640 } 00641 typedef __gnu_debug::_Safe_iterator_base _Safe_iterator_base; 00642 static void 00643 _M_swap_aux(forward_list& __lhs, 00644 _Safe_iterator_base*& __lhs_iterators, 00645 forward_list& __rhs, 00646 _Safe_iterator_base*& __rhs_iterators); 00647 void _M_swap(forward_list& __list); 00648 }; 00649 00650 template<typename _Tp, typename _Alloc> 00651 void 00652 forward_list<_Tp, _Alloc>:: 00653 _M_swap_aux(forward_list<_Tp, _Alloc>& __lhs, 00654 __gnu_debug::_Safe_iterator_base*& __lhs_iterators, 00655 forward_list<_Tp, _Alloc>& __rhs, 00656 __gnu_debug::_Safe_iterator_base*& __rhs_iterators) 00657 { 00658 using __gnu_debug::_Safe_iterator_base; 00659 _Safe_iterator_base* __bbegin_its = 0; 00660 _Safe_iterator_base* __last_bbegin = 0; 00661 for (_Safe_iterator_base* __iter = __lhs_iterators; __iter;) 00662 { 00663 // Even iterator are casted to const_iterator, not a problem. 00664 const_iterator* __victim = static_cast<const_iterator*>(__iter); 00665 __iter = __iter->_M_next; 00666 if (__victim->base() == __rhs._M_base().cbefore_begin()) 00667 { 00668 __victim->_M_unlink(); 00669 if (__lhs_iterators == __victim) 00670 __lhs_iterators = __victim->_M_next; 00671 if (__bbegin_its) 00672 { 00673 __victim->_M_next = __bbegin_its; 00674 __bbegin_its->_M_prior = __victim; 00675 } 00676 else 00677 __last_bbegin = __victim; 00678 __bbegin_its = __victim; 00679 } 00680 else 00681 __victim->_M_sequence = &__lhs; 00682 } 00683 00684 if (__bbegin_its) 00685 { 00686 if (__rhs_iterators) 00687 { 00688 __rhs_iterators->_M_prior = __last_bbegin; 00689 __last_bbegin->_M_next = __rhs_iterators; 00690 } 00691 __rhs_iterators = __bbegin_its; 00692 } 00693 } 00694 00695 /* Special forward_list _M_swap version that do not swap the 00696 * before-begin ownership.*/ 00697 template<typename _Tp, typename _Alloc> 00698 void 00699 forward_list<_Tp, _Alloc>:: 00700 _M_swap(forward_list<_Tp, _Alloc>& __list) 00701 { 00702 __gnu_cxx::__scoped_lock sentry(this->_M_get_mutex()); 00703 std::swap(this->_M_iterators, __list._M_iterators); 00704 std::swap(this->_M_const_iterators, __list._M_const_iterators); 00705 // Useless, always 1 on forward_list 00706 //std::swap(this->_M_version, __list._M_version); 00707 _Safe_iterator_base* __this_its = this->_M_iterators; 00708 _M_swap_aux(__list, __list._M_iterators, *this, this->_M_iterators); 00709 _Safe_iterator_base* __this_const_its = this->_M_const_iterators; 00710 _M_swap_aux(__list, __list._M_const_iterators, *this, 00711 this->_M_const_iterators); 00712 _M_swap_aux(*this, __this_its, __list, __list._M_iterators); 00713 _M_swap_aux(*this, __this_const_its, __list, __list._M_const_iterators); 00714 } 00715 00716 template<typename _Tp, typename _Alloc> 00717 bool 00718 operator==(const forward_list<_Tp, _Alloc>& __lx, 00719 const forward_list<_Tp, _Alloc>& __ly) 00720 { return __lx._M_base() == __ly._M_base(); } 00721 00722 template<typename _Tp, typename _Alloc> 00723 inline bool 00724 operator<(const forward_list<_Tp, _Alloc>& __lx, 00725 const forward_list<_Tp, _Alloc>& __ly) 00726 { return __lx._M_base() < __ly._M_base(); } 00727 00728 template<typename _Tp, typename _Alloc> 00729 inline bool 00730 operator!=(const forward_list<_Tp, _Alloc>& __lx, 00731 const forward_list<_Tp, _Alloc>& __ly) 00732 { return !(__lx == __ly); } 00733 00734 /// Based on operator< 00735 template<typename _Tp, typename _Alloc> 00736 inline bool 00737 operator>(const forward_list<_Tp, _Alloc>& __lx, 00738 const forward_list<_Tp, _Alloc>& __ly) 00739 { return (__ly < __lx); } 00740 00741 /// Based on operator< 00742 template<typename _Tp, typename _Alloc> 00743 inline bool 00744 operator>=(const forward_list<_Tp, _Alloc>& __lx, 00745 const forward_list<_Tp, _Alloc>& __ly) 00746 { return !(__lx < __ly); } 00747 00748 /// Based on operator< 00749 template<typename _Tp, typename _Alloc> 00750 inline bool 00751 operator<=(const forward_list<_Tp, _Alloc>& __lx, 00752 const forward_list<_Tp, _Alloc>& __ly) 00753 { return !(__ly < __lx); } 00754 00755 /// See std::forward_list::swap(). 00756 template<typename _Tp, typename _Alloc> 00757 inline void 00758 swap(forward_list<_Tp, _Alloc>& __lx, 00759 forward_list<_Tp, _Alloc>& __ly) 00760 { __lx.swap(__ly); } 00761 00762 } // namespace __debug 00763 } // namespace std 00764 00765 namespace __gnu_debug 00766 { 00767 template<class _Tp, class _Alloc> 00768 struct _BeforeBeginHelper<std::__debug::forward_list<_Tp, _Alloc> > 00769 { 00770 typedef std::__debug::forward_list<_Tp, _Alloc> _Sequence; 00771 typedef typename _Sequence::const_iterator _It; 00772 typedef typename _It::iterator_type _BaseIt; 00773 00774 static bool 00775 _S_Is(_BaseIt __it, const _Sequence* __seq) 00776 { return __it == __seq->_M_base().cbefore_begin(); } 00777 00778 static bool 00779 _S_Is_Beginnest(_BaseIt __it, const _Sequence* __seq) 00780 { return _S_Is(__it, __seq); } 00781 }; 00782 } 00783 00784 #endif