]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/src/c++98/list.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / src / c++98 / list.cc
CommitLineData
e135a038
BK
1// std::list utilities implementation -*- C++ -*-
2
a945c346 3// Copyright (C) 2003-2024 Free Software Foundation, Inc.
e135a038
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
e135a038
BK
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
748086b7
JJ
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.
e135a038 19
748086b7
JJ
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/>.
e135a038
BK
24
25/*
26 *
27 * Copyright (c) 1994
28 * Hewlett-Packard Company
29 *
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
37 *
38 *
39 * Copyright (c) 1996,1997
40 * Silicon Graphics Computer Systems, Inc.
41 *
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
49 */
50
51#include <list>
52
12ffa228
BK
53namespace std _GLIBCXX_VISIBILITY(default)
54{
4a15d842
FD
55_GLIBCXX_BEGIN_NAMESPACE_VERSION
56
12ffa228 57 namespace __detail
e135a038 58 {
12ffa228 59 void
d3677132
PC
60 _List_node_base::swap(_List_node_base& __x,
61 _List_node_base& __y) _GLIBCXX_USE_NOEXCEPT
e135a038 62 {
12ffa228
BK
63 if ( __x._M_next != &__x )
64 {
65 if ( __y._M_next != &__y )
66 {
67 // Both __x and __y are not empty.
68 std::swap(__x._M_next,__y._M_next);
69 std::swap(__x._M_prev,__y._M_prev);
70 __x._M_next->_M_prev = __x._M_prev->_M_next = &__x;
71 __y._M_next->_M_prev = __y._M_prev->_M_next = &__y;
72 }
73 else
74 {
75 // __x is not empty, __y is empty.
76 __y._M_next = __x._M_next;
77 __y._M_prev = __x._M_prev;
78 __y._M_next->_M_prev = __y._M_prev->_M_next = &__y;
79 __x._M_next = __x._M_prev = &__x;
80 }
81 }
82 else if ( __y._M_next != &__y )
83 {
84 // __x is empty, __y is not empty.
85 __x._M_next = __y._M_next;
86 __x._M_prev = __y._M_prev;
87 __x._M_next->_M_prev = __x._M_prev->_M_next = &__x;
88 __y._M_next = __y._M_prev = &__y;
89 }
e135a038 90 }
e135a038 91
12ffa228 92 void
d3677132
PC
93 _List_node_base::
94 _M_transfer(_List_node_base * const __first,
95 _List_node_base * const __last) _GLIBCXX_USE_NOEXCEPT
e135a038 96 {
ff7793be
JW
97 __glibcxx_assert(__first != __last);
98
12ffa228
BK
99 if (this != __last)
100 {
101 // Remove [first, last) from its old position.
102 __last->_M_prev->_M_next = this;
103 __first->_M_prev->_M_next = __last;
104 this->_M_prev->_M_next = __first;
105
106 // Splice [first, last) into its new position.
107 _List_node_base* const __tmp = this->_M_prev;
108 this->_M_prev = __last->_M_prev;
109 __last->_M_prev = __first->_M_prev;
110 __first->_M_prev = __tmp;
111 }
e135a038 112 }
e135a038 113
12ffa228 114 void
d3677132 115 _List_node_base::_M_reverse() _GLIBCXX_USE_NOEXCEPT
e135a038 116 {
12ffa228
BK
117 _List_node_base* __tmp = this;
118 do
119 {
120 std::swap(__tmp->_M_next, __tmp->_M_prev);
bd1a56a0 121
12ffa228
BK
122 // Old next node is now prev.
123 __tmp = __tmp->_M_prev;
124 }
125 while (__tmp != this);
126 }
e135a038 127
12ffa228 128 void
d3677132
PC
129 _List_node_base::
130 _M_hook(_List_node_base* const __position) _GLIBCXX_USE_NOEXCEPT
12ffa228
BK
131 {
132 this->_M_next = __position;
133 this->_M_prev = __position->_M_prev;
134 __position->_M_prev->_M_next = this;
135 __position->_M_prev = this;
136 }
e135a038 137
12ffa228 138 void
d3677132 139 _List_node_base::_M_unhook() _GLIBCXX_USE_NOEXCEPT
12ffa228
BK
140 {
141 _List_node_base* const __next_node = this->_M_next;
142 _List_node_base* const __prev_node = this->_M_prev;
143 __prev_node->_M_next = __next_node;
144 __next_node->_M_prev = __prev_node;
145 }
12ffa228 146 } // namespace __detail
4a15d842
FD
147
148_GLIBCXX_END_NAMESPACE_VERSION
12ffa228 149} // namespace std