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