]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/include/bits/stl_uninitialized.h
Remove trailing whitespace (see ChangeLog for longwinded description).
[gcc.git] / libstdc++-v3 / include / bits / stl_uninitialized.h
CommitLineData
42526146
PE
1// Raw memory manipulators -*- C++ -*-
2
15d72060 3// Copyright (C) 2001, 2004 Free Software Foundation, Inc.
42526146
PE
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 2, 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// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
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.
29
725dc051
BK
30/*
31 *
32 * Copyright (c) 1994
33 * Hewlett-Packard Company
34 *
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.
42 *
43 *
44 * Copyright (c) 1996,1997
45 * Silicon Graphics Computer Systems, Inc.
46 *
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.
54 */
55
729e3d3f
PE
56/** @file stl_uninitialized.h
57 * This is an internal header file, included by other library headers.
58 * You should not attempt to use it directly.
725dc051
BK
59 */
60
3d7c150e
BK
61#ifndef _STL_UNINITIALIZED_H
62#define _STL_UNINITIALIZED_H 1
725dc051 63
54c1bf78 64#include <cstring>
725dc051 65
d53d7f6e
PE
66namespace std
67{
02d92e3b 68 // uninitialized_copy
08addde6 69 template<typename _InputIterator, typename _ForwardIterator>
ed6814f7 70 inline _ForwardIterator
08addde6
PE
71 __uninitialized_copy_aux(_InputIterator __first, _InputIterator __last,
72 _ForwardIterator __result,
02d92e3b 73 __true_type)
9dd90ac6 74 { return std::copy(__first, __last, __result); }
02d92e3b 75
08addde6 76 template<typename _InputIterator, typename _ForwardIterator>
ed6814f7 77 inline _ForwardIterator
08addde6
PE
78 __uninitialized_copy_aux(_InputIterator __first, _InputIterator __last,
79 _ForwardIterator __result,
02d92e3b
SW
80 __false_type)
81 {
08addde6 82 _ForwardIterator __cur = __result;
ed6814f7 83 try
917a9fd4
SW
84 {
85 for ( ; __first != __last; ++__first, ++__cur)
86 std::_Construct(&*__cur, *__first);
87 return __cur;
88 }
322821b9
BK
89 catch(...)
90 {
9dd90ac6 91 std::_Destroy(__result, __cur);
ed6814f7 92 __throw_exception_again;
322821b9 93 }
02d92e3b
SW
94 }
95
82b61df5
PE
96 /**
97 * @brief Copies the range [first,last) into result.
98 * @param first An input iterator.
99 * @param last An input iterator.
100 * @param result An output iterator.
101 * @return result + (first - last)
102 *
103 * Like copy(), but does not require an initialized output range.
104 */
08addde6
PE
105 template<typename _InputIterator, typename _ForwardIterator>
106 inline _ForwardIterator
ed6814f7 107 uninitialized_copy(_InputIterator __first, _InputIterator __last,
917a9fd4 108 _ForwardIterator __result)
02d92e3b 109 {
08addde6 110 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
02d92e3b 111 typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
15d72060
PC
112 return std::__uninitialized_copy_aux(__first, __last, __result,
113 _Is_POD());
02d92e3b
SW
114 }
115
116 inline char*
117 uninitialized_copy(const char* __first, const char* __last, char* __result)
118 {
9dd90ac6 119 std::memmove(__result, __first, __last - __first);
02d92e3b 120 return __result + (__last - __first);
725dc051 121 }
725dc051 122
ed6814f7 123 inline wchar_t*
02d92e3b
SW
124 uninitialized_copy(const wchar_t* __first, const wchar_t* __last,
125 wchar_t* __result)
126 {
9dd90ac6 127 std::memmove(__result, __first, sizeof(wchar_t) * (__last - __first));
02d92e3b 128 return __result + (__last - __first);
725dc051 129 }
725dc051 130
02d92e3b
SW
131 // Valid if copy construction is equivalent to assignment, and if the
132 // destructor is trivial.
08addde6 133 template<typename _ForwardIterator, typename _Tp>
02d92e3b 134 inline void
ed6814f7
BI
135 __uninitialized_fill_aux(_ForwardIterator __first,
136 _ForwardIterator __last,
02d92e3b 137 const _Tp& __x, __true_type)
9dd90ac6 138 { std::fill(__first, __last, __x); }
02d92e3b 139
08addde6 140 template<typename _ForwardIterator, typename _Tp>
02d92e3b 141 void
ed6814f7 142 __uninitialized_fill_aux(_ForwardIterator __first, _ForwardIterator __last,
02d92e3b
SW
143 const _Tp& __x, __false_type)
144 {
08addde6 145 _ForwardIterator __cur = __first;
15d72060
PC
146 try
147 {
148 for ( ; __cur != __last; ++__cur)
149 std::_Construct(&*__cur, __x);
150 }
322821b9
BK
151 catch(...)
152 {
9dd90ac6 153 std::_Destroy(__first, __cur);
ed6814f7 154 __throw_exception_again;
322821b9 155 }
02d92e3b
SW
156 }
157
82b61df5
PE
158 /**
159 * @brief Copies the value x into the range [first,last).
160 * @param first An input iterator.
161 * @param last An input iterator.
162 * @param x The source value.
163 * @return Nothing.
164 *
165 * Like fill(), but does not require an initialized output range.
166 */
08addde6 167 template<typename _ForwardIterator, typename _Tp>
02d92e3b 168 inline void
ed6814f7 169 uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last,
917a9fd4 170 const _Tp& __x)
02d92e3b 171 {
08addde6 172 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
02d92e3b 173 typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
9dd90ac6 174 std::__uninitialized_fill_aux(__first, __last, __x, _Is_POD());
02d92e3b
SW
175 }
176
177 // Valid if copy construction is equivalent to assignment, and if the
178 // destructor is trivial.
08addde6
PE
179 template<typename _ForwardIterator, typename _Size, typename _Tp>
180 inline _ForwardIterator
181 __uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n,
02d92e3b 182 const _Tp& __x, __true_type)
917a9fd4 183 { return std::fill_n(__first, __n, __x); }
02d92e3b 184
08addde6
PE
185 template<typename _ForwardIterator, typename _Size, typename _Tp>
186 _ForwardIterator
187 __uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n,
02d92e3b
SW
188 const _Tp& __x, __false_type)
189 {
08addde6 190 _ForwardIterator __cur = __first;
ed6814f7 191 try
917a9fd4
SW
192 {
193 for ( ; __n > 0; --__n, ++__cur)
194 std::_Construct(&*__cur, __x);
195 return __cur;
196 }
322821b9 197 catch(...)
ed6814f7 198 {
9dd90ac6 199 std::_Destroy(__first, __cur);
ed6814f7 200 __throw_exception_again;
322821b9 201 }
02d92e3b
SW
202 }
203
82b61df5
PE
204 /**
205 * @brief Copies the value x into the range [first,first+n).
206 * @param first An input iterator.
207 * @param n The number of copies to make.
208 * @param x The source value.
209 * @return first+n
210 *
211 * Like fill_n(), but does not require an initialized output range.
212 */
08addde6 213 template<typename _ForwardIterator, typename _Size, typename _Tp>
ed6814f7 214 inline _ForwardIterator
08addde6 215 uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
02d92e3b 216 {
08addde6 217 typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
02d92e3b 218 typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
9dd90ac6 219 return std::__uninitialized_fill_n_aux(__first, __n, __x, _Is_POD());
02d92e3b
SW
220 }
221
ed6814f7 222 // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
02d92e3b
SW
223 // __uninitialized_fill_copy.
224
225 // __uninitialized_copy_copy
226 // Copies [first1, last1) into [result, result + (last1 - first1)), and
227 // copies [first2, last2) into
228 // [result, result + (last1 - first1) + (last2 - first2)).
229
ed6814f7 230 template<typename _InputIterator1, typename _InputIterator2,
917a9fd4 231 typename _ForwardIterator>
08addde6 232 inline _ForwardIterator
ed6814f7 233 __uninitialized_copy_copy(_InputIterator1 __first1,
917a9fd4 234 _InputIterator1 __last1,
ed6814f7 235 _InputIterator2 __first2,
917a9fd4 236 _InputIterator2 __last2,
08addde6 237 _ForwardIterator __result)
02d92e3b 238 {
15d72060
PC
239 _ForwardIterator __mid = std::uninitialized_copy(__first1, __last1,
240 __result);
241 try
242 {
243 return std::uninitialized_copy(__first2, __last2, __mid);
244 }
322821b9 245 catch(...)
ed6814f7 246 {
9dd90ac6 247 std::_Destroy(__result, __mid);
ed6814f7 248 __throw_exception_again;
322821b9 249 }
02d92e3b
SW
250 }
251
252 // __uninitialized_fill_copy
253 // Fills [result, mid) with x, and copies [first, last) into
254 // [mid, mid + (last - first)).
08addde6 255 template<typename _ForwardIterator, typename _Tp, typename _InputIterator>
ed6814f7 256 inline _ForwardIterator
08addde6 257 __uninitialized_fill_copy(_ForwardIterator __result, _ForwardIterator __mid,
15d72060
PC
258 const _Tp& __x, _InputIterator __first,
259 _InputIterator __last)
02d92e3b 260 {
9dd90ac6 261 std::uninitialized_fill(__result, __mid, __x);
15d72060
PC
262 try
263 {
264 return std::uninitialized_copy(__first, __last, __mid);
265 }
322821b9
BK
266 catch(...)
267 {
9dd90ac6 268 std::_Destroy(__result, __mid);
ed6814f7 269 __throw_exception_again;
322821b9 270 }
02d92e3b
SW
271 }
272
273 // __uninitialized_copy_fill
274 // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
275 // fills [first2 + (last1 - first1), last2) with x.
08addde6 276 template<typename _InputIterator, typename _ForwardIterator, typename _Tp>
02d92e3b 277 inline void
08addde6 278 __uninitialized_copy_fill(_InputIterator __first1, _InputIterator __last1,
15d72060
PC
279 _ForwardIterator __first2,
280 _ForwardIterator __last2, const _Tp& __x)
02d92e3b 281 {
ed6814f7 282 _ForwardIterator __mid2 = std::uninitialized_copy(__first1, __last1,
917a9fd4 283 __first2);
ed6814f7 284 try
917a9fd4
SW
285 {
286 std::uninitialized_fill(__mid2, __last2, __x);
287 }
322821b9
BK
288 catch(...)
289 {
9dd90ac6 290 std::_Destroy(__first2, __mid2);
ed6814f7 291 __throw_exception_again;
322821b9 292 }
02d92e3b 293 }
725dc051 294
d53d7f6e 295} // namespace std
725dc051 296
3d7c150e 297#endif /* _STL_UNINITIALIZED_H */
This page took 0.343103 seconds and 5 git commands to generate.