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