1 // Compatibility symbols for previous versions, list bits -*- C++ -*- 2 3 // Copyright (C) 2010-2018 Free Software Foundation, Inc. 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 3, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // Under Section 7 of GPL version 3, you are granted additional 17 // permissions described in the GCC Runtime Library Exception, version 18 // 3.1, as published by the Free Software Foundation. 19 20 // You should have received a copy of the GNU General Public License and 21 // a copy of the GCC Runtime Library Exception along with this program; 22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 // <http://www.gnu.org/licenses/>. 24 25 #include <bits/move.h> 26 27 #ifndef _GLIBCXX_BEGIN_NAMESPACE_COMPAT 28 # define _GLIBCXX_BEGIN_NAMESPACE_COMPAT 29 #endif 30 31 #ifndef _GLIBCXX_END_NAMESPACE_COMPAT 32 # define _GLIBCXX_END_NAMESPACE_COMPAT 33 #endif 34 35 namespace std _GLIBCXX_VISIBILITY(default) 36 { 37 _GLIBCXX_BEGIN_NAMESPACE_COMPAT 38 39 struct _List_node_base 40 { 41 _List_node_base* _M_next; 42 _List_node_base* _M_prev; 43 44 static void 45 swap(_List_node_base& __x, _List_node_base& __y) throw (); 46 47 void 48 transfer(_List_node_base * const __first, 49 _List_node_base * const __last) throw (); 50 51 void 52 reverse() throw (); 53 54 void 55 hook(_List_node_base * const __position) throw (); 56 57 void 58 unhook() throw (); 59 }; 60 61 void swap(_List_node_base & __x,_List_node_base & __y)62 _List_node_base::swap(_List_node_base& __x, _List_node_base& __y) throw() 63 { 64 if ( __x._M_next != &__x ) 65 { 66 if ( __y._M_next != &__y ) 67 { 68 // Both __x and __y are not empty. 69 std::swap(__x._M_next,__y._M_next); 70 std::swap(__x._M_prev,__y._M_prev); 71 __x._M_next->_M_prev = __x._M_prev->_M_next = &__x; 72 __y._M_next->_M_prev = __y._M_prev->_M_next = &__y; 73 } 74 else 75 { 76 // __x is not empty, __y is empty. 77 __y._M_next = __x._M_next; 78 __y._M_prev = __x._M_prev; 79 __y._M_next->_M_prev = __y._M_prev->_M_next = &__y; 80 __x._M_next = __x._M_prev = &__x; 81 } 82 } 83 else if ( __y._M_next != &__y ) 84 { 85 // __x is empty, __y is not empty. 86 __x._M_next = __y._M_next; 87 __x._M_prev = __y._M_prev; 88 __x._M_next->_M_prev = __x._M_prev->_M_next = &__x; 89 __y._M_next = __y._M_prev = &__y; 90 } 91 } 92 93 void transfer(_List_node_base * const __first,_List_node_base * const __last)94 _List_node_base::transfer(_List_node_base * const __first, 95 _List_node_base * const __last) throw () 96 { 97 if (this != __last) 98 { 99 // Remove [first, last) from its old position. 100 __last->_M_prev->_M_next = this; 101 __first->_M_prev->_M_next = __last; 102 this->_M_prev->_M_next = __first; 103 104 // Splice [first, last) into its new position. 105 _List_node_base* const __tmp = this->_M_prev; 106 this->_M_prev = __last->_M_prev; 107 __last->_M_prev = __first->_M_prev; 108 __first->_M_prev = __tmp; 109 } 110 } 111 112 void reverse()113 _List_node_base::reverse() throw () 114 { 115 _List_node_base* __tmp = this; 116 do 117 { 118 std::swap(__tmp->_M_next, __tmp->_M_prev); 119 120 // Old next node is now prev. 121 __tmp = __tmp->_M_prev; 122 } 123 while (__tmp != this); 124 } 125 126 void hook(_List_node_base * const __position)127 _List_node_base::hook(_List_node_base* const __position) throw () 128 { 129 this->_M_next = __position; 130 this->_M_prev = __position->_M_prev; 131 __position->_M_prev->_M_next = this; 132 __position->_M_prev = this; 133 } 134 135 void unhook()136 _List_node_base::unhook() throw () 137 { 138 _List_node_base* const __next_node = this->_M_next; 139 _List_node_base* const __prev_node = this->_M_prev; 140 __prev_node->_M_next = __next_node; 141 __next_node->_M_prev = __prev_node; 142 } 143 144 _GLIBCXX_END_NAMESPACE_COMPAT 145 146 } // namespace std 147