source: trunk/src/emx/include/Attic/cpp/stl_unin.h@ 18

Last change on this file since 18 was 18, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 8.4 KB
Line 
1/*
2 *
3 * Copyright (c) 1994
4 * Hewlett-Packard Company
5 *
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Hewlett-Packard Company makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 *
15 * Copyright (c) 1996,1997
16 * Silicon Graphics Computer Systems, Inc.
17 *
18 * Permission to use, copy, modify, distribute and sell this software
19 * and its documentation for any purpose is hereby granted without fee,
20 * provided that the above copyright notice appear in all copies and
21 * that both that copyright notice and this permission notice appear
22 * in supporting documentation. Silicon Graphics makes no
23 * representations about the suitability of this software for any
24 * purpose. It is provided "as is" without express or implied warranty.
25 */
26
27/* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
29 */
30
31#ifndef __SGI_STL_INTERNAL_UNINITIALIZED_H
32#define __SGI_STL_INTERNAL_UNINITIALIZED_H
33
34__STL_BEGIN_NAMESPACE
35
36// Valid if copy construction is equivalent to assignment, and if the
37// destructor is trivial.
38template <class InputIterator, class ForwardIterator>
39inline ForwardIterator
40__uninitialized_copy_aux(InputIterator first, InputIterator last,
41 ForwardIterator result,
42 __true_type) {
43 return copy(first, last, result);
44}
45
46template <class InputIterator, class ForwardIterator>
47ForwardIterator
48__uninitialized_copy_aux(InputIterator first, InputIterator last,
49 ForwardIterator result,
50 __false_type) {
51 ForwardIterator cur = result;
52 __STL_TRY {
53 for ( ; first != last; ++first, ++cur)
54 construct(&*cur, *first);
55 return cur;
56 }
57 __STL_UNWIND(destroy(result, cur));
58}
59
60
61template <class InputIterator, class ForwardIterator, class T>
62inline ForwardIterator
63__uninitialized_copy(InputIterator first, InputIterator last,
64 ForwardIterator result, T*) {
65 typedef typename __type_traits<T>::is_POD_type is_POD;
66 return __uninitialized_copy_aux(first, last, result, is_POD());
67}
68
69template <class InputIterator, class ForwardIterator>
70inline ForwardIterator
71 uninitialized_copy(InputIterator first, InputIterator last,
72 ForwardIterator result) {
73 return __uninitialized_copy(first, last, result, value_type(result));
74}
75
76inline char* uninitialized_copy(const char* first, const char* last,
77 char* result) {
78 memmove(result, first, last - first);
79 return result + (last - first);
80}
81
82inline wchar_t* uninitialized_copy(const wchar_t* first, const wchar_t* last,
83 wchar_t* result) {
84 memmove(result, first, sizeof(wchar_t) * (last - first));
85 return result + (last - first);
86}
87
88template <class InputIterator, class Size, class ForwardIterator>
89pair<InputIterator, ForwardIterator>
90__uninitialized_copy_n(InputIterator first, Size count,
91 ForwardIterator result,
92 input_iterator_tag) {
93 ForwardIterator cur = result;
94 __STL_TRY {
95 for ( ; count > 0 ; --count, ++first, ++cur)
96 construct(&*cur, *first);
97 return pair<InputIterator, ForwardIterator>(first, cur);
98 }
99 __STL_UNWIND(destroy(result, cur));
100}
101
102template <class RandomAccessIterator, class Size, class ForwardIterator>
103inline pair<RandomAccessIterator, ForwardIterator>
104__uninitialized_copy_n(RandomAccessIterator first, Size count,
105 ForwardIterator result,
106 random_access_iterator_tag) {
107 RandomAccessIterator last = first + count;
108 return make_pair(last, uninitialized_copy(first, last, result));
109}
110
111template <class InputIterator, class Size, class ForwardIterator>
112inline pair<InputIterator, ForwardIterator>
113uninitialized_copy_n(InputIterator first, Size count,
114 ForwardIterator result) {
115 return __uninitialized_copy_n(first, count, result,
116 iterator_category(first));
117}
118
119// Valid if copy construction is equivalent to assignment, and if the
120// destructor is trivial.
121template <class ForwardIterator, class T>
122inline void
123__uninitialized_fill_aux(ForwardIterator first, ForwardIterator last,
124 const T& x, __true_type)
125{
126 fill(first, last, x);
127}
128
129template <class ForwardIterator, class T>
130void
131__uninitialized_fill_aux(ForwardIterator first, ForwardIterator last,
132 const T& x, __false_type)
133{
134 ForwardIterator cur = first;
135 __STL_TRY {
136 for ( ; cur != last; ++cur)
137 construct(&*cur, x);
138 }
139 __STL_UNWIND(destroy(first, cur));
140}
141
142template <class ForwardIterator, class T, class T1>
143inline void __uninitialized_fill(ForwardIterator first, ForwardIterator last,
144 const T& x, T1*) {
145 typedef typename __type_traits<T1>::is_POD_type is_POD;
146 __uninitialized_fill_aux(first, last, x, is_POD());
147
148}
149
150template <class ForwardIterator, class T>
151inline void uninitialized_fill(ForwardIterator first, ForwardIterator last,
152 const T& x) {
153 __uninitialized_fill(first, last, x, value_type(first));
154}
155
156// Valid if copy construction is equivalent to assignment, and if the
157// destructor is trivial.
158template <class ForwardIterator, class Size, class T>
159inline ForwardIterator
160__uninitialized_fill_n_aux(ForwardIterator first, Size n,
161 const T& x, __true_type) {
162 return fill_n(first, n, x);
163}
164
165template <class ForwardIterator, class Size, class T>
166ForwardIterator
167__uninitialized_fill_n_aux(ForwardIterator first, Size n,
168 const T& x, __false_type) {
169 ForwardIterator cur = first;
170 __STL_TRY {
171 for ( ; n > 0; --n, ++cur)
172 construct(&*cur, x);
173 return cur;
174 }
175 __STL_UNWIND(destroy(first, cur));
176}
177
178template <class ForwardIterator, class Size, class T, class T1>
179inline ForwardIterator __uninitialized_fill_n(ForwardIterator first, Size n,
180 const T& x, T1*) {
181 typedef typename __type_traits<T1>::is_POD_type is_POD;
182 return __uninitialized_fill_n_aux(first, n, x, is_POD());
183
184}
185
186template <class ForwardIterator, class Size, class T>
187inline ForwardIterator uninitialized_fill_n(ForwardIterator first, Size n,
188 const T& x) {
189 return __uninitialized_fill_n(first, n, x, value_type(first));
190}
191
192// Copies [first1, last1) into [result, result + (last1 - first1)), and
193// copies [first2, last2) into
194// [result, result + (last1 - first1) + (last2 - first2)).
195
196template <class InputIterator1, class InputIterator2, class ForwardIterator>
197inline ForwardIterator
198__uninitialized_copy_copy(InputIterator1 first1, InputIterator1 last1,
199 InputIterator2 first2, InputIterator2 last2,
200 ForwardIterator result) {
201 ForwardIterator mid = uninitialized_copy(first1, last1, result);
202 __STL_TRY {
203 return uninitialized_copy(first2, last2, mid);
204 }
205 __STL_UNWIND(destroy(result, mid));
206}
207
208// Fills [result, mid) with x, and copies [first, last) into
209// [mid, mid + (last - first)).
210template <class ForwardIterator, class T, class InputIterator>
211inline ForwardIterator
212__uninitialized_fill_copy(ForwardIterator result, ForwardIterator mid,
213 const T& x,
214 InputIterator first, InputIterator last) {
215 uninitialized_fill(result, mid, x);
216 __STL_TRY {
217 return uninitialized_copy(first, last, mid);
218 }
219 __STL_UNWIND(destroy(result, mid));
220}
221
222// Copies [first1, last1) into [first2, first2 + (last1 - first1)), and
223// fills [first2 + (last1 - first1), last2) with x.
224template <class InputIterator, class ForwardIterator, class T>
225inline void
226__uninitialized_copy_fill(InputIterator first1, InputIterator last1,
227 ForwardIterator first2, ForwardIterator last2,
228 const T& x) {
229 ForwardIterator mid2 = uninitialized_copy(first1, last1, first2);
230 __STL_TRY {
231 uninitialized_fill(mid2, last2, x);
232 }
233 __STL_UNWIND(destroy(first2, mid2));
234}
235
236__STL_END_NAMESPACE
237
238#endif /* __SGI_STL_INTERNAL_UNINITIALIZED_H */
239
240// Local Variables:
241// mode:C++
242// End:
Note: See TracBrowser for help on using the repository browser.