1 // std::list utilities implementation -*- C++ -*-
3 // Copyright (C) 2003, 2005 Free Software Foundation, Inc.
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 2, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
33 * Hewlett-Packard Company
35 * Permission to use, copy, modify, distribute and sell this software
36 * and its documentation for any purpose is hereby granted without fee,
37 * provided that the above copyright notice appear in all copies and
38 * that both that copyright notice and this permission notice appear
39 * in supporting documentation. Hewlett-Packard Company makes no
40 * representations about the suitability of this software for any
41 * purpose. It is provided "as is" without express or implied warranty.
44 * Copyright (c) 1996,1997
45 * Silicon Graphics Computer Systems, Inc.
47 * Permission to use, copy, modify, distribute and sell this software
48 * and its documentation for any purpose is hereby granted without fee,
49 * provided that the above copyright notice appear in all copies and
50 * that both that copyright notice and this permission notice appear
51 * in supporting documentation. Silicon Graphics makes no
52 * representations about the suitability of this software for any
53 * purpose. It is provided "as is" without express or implied warranty.
58 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std
, _GLIBCXX_STD_D
)
61 _List_node_base::swap(_List_node_base
& __x
, _List_node_base
& __y
)
63 if ( __x
._M_next
!= &__x
)
65 if ( __y
._M_next
!= &__y
)
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
;
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
;
82 else if ( __y
._M_next
!= &__y
)
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
;
93 _List_node_base::transfer(_List_node_base
* const __first
,
94 _List_node_base
* const __last
)
98 // Remove [first, last) from its old position.
99 __last
->_M_prev
->_M_next
= this;
100 __first
->_M_prev
->_M_next
= __last
;
101 this->_M_prev
->_M_next
= __first
;
103 // Splice [first, last) into its new position.
104 _List_node_base
* const __tmp
= this->_M_prev
;
105 this->_M_prev
= __last
->_M_prev
;
106 __last
->_M_prev
= __first
->_M_prev
;
107 __first
->_M_prev
= __tmp
;
112 _List_node_base::reverse()
114 _List_node_base
* __tmp
= this;
117 std::swap(__tmp
->_M_next
, __tmp
->_M_prev
);
119 // Old next node is now prev.
120 __tmp
= __tmp
->_M_prev
;
122 while (__tmp
!= this);
126 _List_node_base::hook(_List_node_base
* const __position
)
128 this->_M_next
= __position
;
129 this->_M_prev
= __position
->_M_prev
;
130 __position
->_M_prev
->_M_next
= this;
131 __position
->_M_prev
= this;
135 _List_node_base::unhook()
137 _List_node_base
* const __next_node
= this->_M_next
;
138 _List_node_base
* const __prev_node
= this->_M_prev
;
139 __prev_node
->_M_next
= __next_node
;
140 __next_node
->_M_prev
= __prev_node
;
143 _GLIBCXX_END_NESTED_NAMESPACE