OSDN Git Service

* Makefile.in (install): Some of HEADERS come from the stl dir now.
[pf3gnuchains/gcc-fork.git] / libstdc++ / stl / stl_uninitialized.h
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.
38 template <class InputIterator, class ForwardIterator>
39 inline ForwardIterator 
40 __uninitialized_copy_aux(InputIterator first, InputIterator last,
41                          ForwardIterator result,
42                          __true_type) {
43   return copy(first, last, result);
44 }
45
46 template <class InputIterator, class ForwardIterator>
47 ForwardIterator 
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
61 template <class InputIterator, class ForwardIterator, class T>
62 inline 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
69 template <class InputIterator, class ForwardIterator>
70 inline ForwardIterator
71   uninitialized_copy(InputIterator first, InputIterator last,
72                      ForwardIterator result) {
73   return __uninitialized_copy(first, last, result, value_type(result));
74 }
75
76 inline 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
82 inline 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
88 template <class InputIterator, class Size, class ForwardIterator>
89 pair<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
102 template <class RandomAccessIterator, class Size, class ForwardIterator>
103 inline 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
111 template <class InputIterator, class Size, class ForwardIterator>
112 inline pair<InputIterator, ForwardIterator>
113 uninitialized_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.
121 template <class ForwardIterator, class T>
122 inline void
123 __uninitialized_fill_aux(ForwardIterator first, ForwardIterator last, 
124                          const T& x, __true_type)
125 {
126   fill(first, last, x);
127 }
128
129 template <class ForwardIterator, class T>
130 void
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
142 template <class ForwardIterator, class T, class T1>
143 inline 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
150 template <class ForwardIterator, class T>
151 inline 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.
158 template <class ForwardIterator, class Size, class T>
159 inline 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
165 template <class ForwardIterator, class Size, class T>
166 ForwardIterator
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
178 template <class ForwardIterator, class Size, class T, class T1>
179 inline 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
186 template <class ForwardIterator, class Size, class T>
187 inline 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
196 template <class InputIterator1, class InputIterator2, class ForwardIterator>
197 inline 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)).
210 template <class ForwardIterator, class T, class InputIterator>
211 inline 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.
224 template <class InputIterator, class ForwardIterator, class T>
225 inline 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: