1 | // The template and inlines for the -*- C++ -*- internal _Array helper class.
|
---|
2 |
|
---|
3 | // Copyright (C) 1997-2021 Free Software Foundation, Inc.
|
---|
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 3, 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 | // 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/>.
|
---|
24 |
|
---|
25 | /** @file bits/valarray_array.tcc
|
---|
26 | * This is an internal header file, included by other library headers.
|
---|
27 | * Do not attempt to use it directly. @headername{valarray}
|
---|
28 | */
|
---|
29 |
|
---|
30 | // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
|
---|
31 |
|
---|
32 | #ifndef _VALARRAY_ARRAY_TCC
|
---|
33 | #define _VALARRAY_ARRAY_TCC 1
|
---|
34 |
|
---|
35 | namespace std _GLIBCXX_VISIBILITY(default)
|
---|
36 | {
|
---|
37 | _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
---|
38 |
|
---|
39 | template<typename _Tp>
|
---|
40 | void
|
---|
41 | __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m,
|
---|
42 | const _Tp& __t)
|
---|
43 | {
|
---|
44 | _Tp* __p = __a._M_data;
|
---|
45 | bool* __ok (__m._M_data);
|
---|
46 | for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p)
|
---|
47 | {
|
---|
48 | while (!*__ok)
|
---|
49 | {
|
---|
50 | ++__ok;
|
---|
51 | ++__p;
|
---|
52 | }
|
---|
53 | *__p = __t;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
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.
|
---|
63 | template<typename _Tp>
|
---|
64 | void
|
---|
65 | __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b,
|
---|
66 | size_t __n)
|
---|
67 | {
|
---|
68 | _Tp* __p (__a._M_data);
|
---|
69 | bool* __ok (__m._M_data);
|
---|
70 | for (_Tp* __q = __b._M_data; __q < __b._M_data + __n;
|
---|
71 | ++__q, ++__ok, ++__p)
|
---|
72 | {
|
---|
73 | while (! *__ok)
|
---|
74 | {
|
---|
75 | ++__ok;
|
---|
76 | ++__p;
|
---|
77 | }
|
---|
78 | *__q = *__p;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
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.
|
---|
88 | template<typename _Tp>
|
---|
89 | void
|
---|
90 | __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b,
|
---|
91 | _Array<bool> __m)
|
---|
92 | {
|
---|
93 | _Tp* __q (__b._M_data);
|
---|
94 | bool* __ok (__m._M_data);
|
---|
95 | for (_Tp* __p = __a._M_data; __p < __a._M_data+__n;
|
---|
96 | ++__p, ++__ok, ++__q)
|
---|
97 | {
|
---|
98 | while (! *__ok)
|
---|
99 | {
|
---|
100 | ++__ok;
|
---|
101 | ++__q;
|
---|
102 | }
|
---|
103 | *__q = *__p;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
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].
|
---|
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);
|
---|
145 | for (size_t __i = 0; __i < __n; ++__i, ++__p)
|
---|
146 | *__p = __e[__i];
|
---|
147 | }
|
---|
148 |
|
---|
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].
|
---|
151 | template<typename _Tp, class _Dom>
|
---|
152 | void
|
---|
153 | __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
|
---|
154 | _Array<_Tp> __a, size_t __s)
|
---|
155 | {
|
---|
156 | _Tp* __p (__a._M_data);
|
---|
157 | for (size_t __i = 0; __i < __n; ++__i, __p += __s)
|
---|
158 | *__p = __e[__i];
|
---|
159 | }
|
---|
160 |
|
---|
161 | // Copy n consecutive elements of e into elements of a indexed by
|
---|
162 | // contents of i. I.e., a[i[0]] = e[0].
|
---|
163 | template<typename _Tp, class _Dom>
|
---|
164 | void
|
---|
165 | __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
|
---|
166 | _Array<_Tp> __a, _Array<size_t> __i)
|
---|
167 | {
|
---|
168 | size_t* __j (__i._M_data);
|
---|
169 | for (size_t __k = 0; __k < __n; ++__k, ++__j)
|
---|
170 | __a._M_data[*__j] = __e[__k];
|
---|
171 | }
|
---|
172 |
|
---|
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.
|
---|
193 | template<typename _Tp, class _Dom>
|
---|
194 | void
|
---|
195 | __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
|
---|
196 | _Array<_Tp> __a, _Array<bool> __m)
|
---|
197 | {
|
---|
198 | bool* __ok (__m._M_data);
|
---|
199 | _Tp* __p (__a._M_data);
|
---|
200 | for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p)
|
---|
201 | {
|
---|
202 | while (! *__ok)
|
---|
203 | {
|
---|
204 | ++__ok;
|
---|
205 | ++__p;
|
---|
206 | }
|
---|
207 | *__p = __e[__i];
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
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);
|
---|
218 | for (size_t __i = 0; __i < __n; ++__i, ++__p)
|
---|
219 | new (__p) _Tp(__e[__i]);
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
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 | {
|
---|
232 | while (! *__ok)
|
---|
233 | {
|
---|
234 | ++__ok;
|
---|
235 | ++__p;
|
---|
236 | }
|
---|
237 | new (__q) _Tp(*__p);
|
---|
238 | }
|
---|
239 | }
|
---|
240 |
|
---|
241 | _GLIBCXX_END_NAMESPACE_VERSION
|
---|
242 | } // namespace
|
---|
243 |
|
---|
244 | #endif /* _VALARRAY_ARRAY_TCC */
|
---|