]>
Commit | Line | Data |
---|---|---|
725dc051 BK |
1 | // The template and inlines for the -*- C++ -*- internal _Array helper class. |
2 | ||
a5544970 | 3 | // Copyright (C) 1997-2019 Free Software Foundation, Inc. |
725dc051 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) |
725dc051 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. | |
19 | ||
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/>. | |
725dc051 | 24 | |
f910786b | 25 | /** @file bits/valarray_array.tcc |
0aa06b18 | 26 | * This is an internal header file, included by other library headers. |
f910786b | 27 | * Do not attempt to use it directly. @headername{valarray} |
0aa06b18 BK |
28 | */ |
29 | ||
725dc051 BK |
30 | // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> |
31 | ||
ed6814f7 | 32 | #ifndef _VALARRAY_ARRAY_TCC |
3d7c150e | 33 | #define _VALARRAY_ARRAY_TCC 1 |
725dc051 | 34 | |
12ffa228 BK |
35 | namespace std _GLIBCXX_VISIBILITY(default) |
36 | { | |
37 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
3cbc7af0 | 38 | |
5f697f7a BK |
39 | template<typename _Tp> |
40 | void | |
ed6814f7 | 41 | __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m, |
5f697f7a BK |
42 | const _Tp& __t) |
43 | { | |
44 | _Tp* __p = __a._M_data; | |
45 | bool* __ok (__m._M_data); | |
ed6814f7 | 46 | for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p) |
5f697f7a | 47 | { |
ed6814f7 | 48 | while (!*__ok) |
5f697f7a BK |
49 | { |
50 | ++__ok; | |
51 | ++__p; | |
52 | } | |
53 | *__p = __t; | |
54 | } | |
725dc051 | 55 | } |
ed6814f7 | 56 | |
e9264dac PC |
57 | // Copy n elements of a into consecutive elements of b. When m is |
58 | // false, the corresponding element of a is skipped. m must contain | |
59 | // at least n true elements. a must contain at least n elements and | |
60 | // enough elements to match up with m through the nth true element | |
61 | // of m. I.e. if n is 10, m has 15 elements with 5 false followed | |
62 | // by 10 true, a must have 15 elements. | |
5f697f7a BK |
63 | template<typename _Tp> |
64 | void | |
ed6814f7 | 65 | __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b, |
5f697f7a BK |
66 | size_t __n) |
67 | { | |
68 | _Tp* __p (__a._M_data); | |
69 | bool* __ok (__m._M_data); | |
ed6814f7 BI |
70 | for (_Tp* __q = __b._M_data; __q < __b._M_data + __n; |
71 | ++__q, ++__ok, ++__p) | |
5f697f7a | 72 | { |
ed6814f7 | 73 | while (! *__ok) |
5f697f7a BK |
74 | { |
75 | ++__ok; | |
76 | ++__p; | |
77 | } | |
78 | *__q = *__p; | |
79 | } | |
725dc051 | 80 | } |
725dc051 | 81 | |
e9264dac PC |
82 | // Copy n consecutive elements from a into elements of b. Elements |
83 | // of b are skipped if the corresponding element of m is false. m | |
84 | // must contain at least n true elements. b must have at least as | |
85 | // many elements as the index of the nth true element of m. I.e. if | |
86 | // m has 15 elements with 5 false followed by 10 true, b must have | |
87 | // at least 15 elements. | |
5f697f7a BK |
88 | template<typename _Tp> |
89 | void | |
ed6814f7 | 90 | __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b, |
5f697f7a BK |
91 | _Array<bool> __m) |
92 | { | |
93 | _Tp* __q (__b._M_data); | |
94 | bool* __ok (__m._M_data); | |
ed6814f7 BI |
95 | for (_Tp* __p = __a._M_data; __p < __a._M_data+__n; |
96 | ++__p, ++__ok, ++__q) | |
5f697f7a | 97 | { |
ed6814f7 | 98 | while (! *__ok) |
5f697f7a BK |
99 | { |
100 | ++__ok; | |
101 | ++__q; | |
102 | } | |
103 | *__q = *__p; | |
104 | } | |
725dc051 | 105 | } |
725dc051 | 106 | |
e9264dac PC |
107 | // Copy n elements from a into elements of b. Elements of a are |
108 | // skipped if the corresponding element of m is false. Elements of | |
109 | // b are skipped if the corresponding element of k is false. m and | |
110 | // k must contain at least n true elements. a and b must have at | |
111 | // least as many elements as the index of the nth true element of m. | |
112 | template<typename _Tp> | |
113 | void | |
114 | __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, size_t __n, | |
115 | _Array<_Tp> __b, _Array<bool> __k) | |
116 | { | |
117 | _Tp* __p (__a._M_data); | |
118 | _Tp* __q (__b._M_data); | |
119 | bool* __srcok (__m._M_data); | |
120 | bool* __dstok (__k._M_data); | |
121 | for (size_t __i = 0; __i < __n; | |
122 | ++__srcok, ++__p, ++__dstok, ++__q, ++__i) | |
123 | { | |
124 | while (! *__srcok) | |
125 | { | |
126 | ++__srcok; | |
127 | ++__p; | |
128 | } | |
129 | while (! *__dstok) | |
130 | { | |
131 | ++__dstok; | |
132 | ++__q; | |
133 | } | |
134 | *__q = *__p; | |
135 | } | |
136 | } | |
137 | ||
138 | // Copy n consecutive elements of e into consecutive elements of a. | |
139 | // I.e. a[i] = e[i]. | |
5f697f7a BK |
140 | template<typename _Tp, class _Dom> |
141 | void | |
142 | __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a) | |
143 | { | |
144 | _Tp* __p (__a._M_data); | |
ed6814f7 | 145 | for (size_t __i = 0; __i < __n; ++__i, ++__p) |
5f697f7a | 146 | *__p = __e[__i]; |
725dc051 | 147 | } |
725dc051 | 148 | |
e9264dac PC |
149 | // Copy n consecutive elements of e into elements of a using stride |
150 | // s. I.e., a[0] = e[0], a[s] = e[1], a[2*s] = e[2]. | |
5f697f7a BK |
151 | template<typename _Tp, class _Dom> |
152 | void | |
ed6814f7 | 153 | __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, |
5f697f7a BK |
154 | _Array<_Tp> __a, size_t __s) |
155 | { | |
156 | _Tp* __p (__a._M_data); | |
ed6814f7 | 157 | for (size_t __i = 0; __i < __n; ++__i, __p += __s) |
5f697f7a | 158 | *__p = __e[__i]; |
725dc051 | 159 | } |
725dc051 | 160 | |
e9264dac PC |
161 | // Copy n consecutive elements of e into elements of a indexed by |
162 | // contents of i. I.e., a[i[0]] = e[0]. | |
5f697f7a BK |
163 | template<typename _Tp, class _Dom> |
164 | void | |
ed6814f7 | 165 | __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, |
5f697f7a BK |
166 | _Array<_Tp> __a, _Array<size_t> __i) |
167 | { | |
168 | size_t* __j (__i._M_data); | |
ed6814f7 | 169 | for (size_t __k = 0; __k < __n; ++__k, ++__j) |
5f697f7a BK |
170 | __a._M_data[*__j] = __e[__k]; |
171 | } | |
725dc051 | 172 | |
e9264dac PC |
173 | // Copy n elements of e indexed by contents of f into elements of a |
174 | // indexed by contents of i. I.e., a[i[0]] = e[f[0]]. | |
175 | template<typename _Tp> | |
176 | void | |
177 | __valarray_copy(_Array<_Tp> __e, _Array<size_t> __f, | |
178 | size_t __n, | |
179 | _Array<_Tp> __a, _Array<size_t> __i) | |
180 | { | |
181 | size_t* __g (__f._M_data); | |
182 | size_t* __j (__i._M_data); | |
183 | for (size_t __k = 0; __k < __n; ++__k, ++__j, ++__g) | |
184 | __a._M_data[*__j] = __e._M_data[*__g]; | |
185 | } | |
186 | ||
187 | // Copy n consecutive elements of e into elements of a. Elements of | |
188 | // a are skipped if the corresponding element of m is false. m must | |
189 | // have at least n true elements and a must have at least as many | |
190 | // elements as the index of the nth true element of m. I.e. if m | |
191 | // has 5 false followed by 10 true elements and n == 10, a must have | |
192 | // at least 15 elements. | |
5f697f7a BK |
193 | template<typename _Tp, class _Dom> |
194 | void | |
ed6814f7 | 195 | __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, |
5f697f7a BK |
196 | _Array<_Tp> __a, _Array<bool> __m) |
197 | { | |
198 | bool* __ok (__m._M_data); | |
199 | _Tp* __p (__a._M_data); | |
ed6814f7 | 200 | for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p) |
5f697f7a | 201 | { |
ed6814f7 | 202 | while (! *__ok) |
5f697f7a BK |
203 | { |
204 | ++__ok; | |
205 | ++__p; | |
206 | } | |
207 | *__p = __e[__i]; | |
208 | } | |
209 | } | |
ed6814f7 | 210 | |
5f697f7a BK |
211 | |
212 | template<typename _Tp, class _Dom> | |
213 | void | |
214 | __valarray_copy_construct(const _Expr<_Dom, _Tp>& __e, size_t __n, | |
215 | _Array<_Tp> __a) | |
216 | { | |
217 | _Tp* __p (__a._M_data); | |
ed6814f7 | 218 | for (size_t __i = 0; __i < __n; ++__i, ++__p) |
5f697f7a BK |
219 | new (__p) _Tp(__e[__i]); |
220 | } | |
725dc051 BK |
221 | |
222 | ||
5f697f7a BK |
223 | template<typename _Tp> |
224 | void | |
225 | __valarray_copy_construct(_Array<_Tp> __a, _Array<bool> __m, | |
226 | _Array<_Tp> __b, size_t __n) | |
227 | { | |
228 | _Tp* __p (__a._M_data); | |
229 | bool* __ok (__m._M_data); | |
230 | for (_Tp* __q = __b._M_data; __q < __b._M_data+__n; ++__q, ++__ok, ++__p) | |
231 | { | |
ed6814f7 | 232 | while (! *__ok) |
5f697f7a BK |
233 | { |
234 | ++__ok; | |
235 | ++__p; | |
236 | } | |
237 | new (__q) _Tp(*__p); | |
238 | } | |
239 | } | |
3cbc7af0 | 240 | |
12ffa228 BK |
241 | _GLIBCXX_END_NAMESPACE_VERSION |
242 | } // namespace | |
725dc051 | 243 | |
3d7c150e | 244 | #endif /* _VALARRAY_ARRAY_TCC */ |