]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/valarray_array.tcc
c++config: Add in revised namespace associations.
[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
3cbc7af0 3// Copyright (C) 1997, 1998, 1999, 2003, 2005 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
8// Free Software Foundation; either version 2, 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// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING. If not, write to the Free
83f51799 18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
725dc051
BK
19// USA.
20
21// As a special exception, you may use this file as part of a free software
22// library without restriction. Specifically, if other files instantiate
23// templates or use macros or inline functions from this file, or you compile
24// this file and link it with other files to produce an executable, this
25// file does not by itself cause the resulting executable to be covered by
26// the GNU General Public License. This exception does not however
27// invalidate any other reasons why the executable file might be covered by
28// the GNU General Public License.
29
0aa06b18
BK
30/** @file valarray_array.tcc
31 * This is an internal header file, included by other library headers.
32 * You should not attempt to use it directly.
33 */
34
725dc051
BK
35// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
36
ed6814f7 37#ifndef _VALARRAY_ARRAY_TCC
3d7c150e 38#define _VALARRAY_ARRAY_TCC 1
725dc051 39
3cbc7af0
BK
40_GLIBCXX_BEGIN_NAMESPACE(std)
41
5f697f7a
BK
42 template<typename _Tp>
43 void
ed6814f7 44 __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m,
5f697f7a
BK
45 const _Tp& __t)
46 {
47 _Tp* __p = __a._M_data;
48 bool* __ok (__m._M_data);
ed6814f7 49 for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p)
5f697f7a 50 {
ed6814f7 51 while (!*__ok)
5f697f7a
BK
52 {
53 ++__ok;
54 ++__p;
55 }
56 *__p = __t;
57 }
725dc051 58 }
ed6814f7 59
e9264dac
PC
60 // Copy n elements of a into consecutive elements of b. When m is
61 // false, the corresponding element of a is skipped. m must contain
62 // at least n true elements. a must contain at least n elements and
63 // enough elements to match up with m through the nth true element
64 // of m. I.e. if n is 10, m has 15 elements with 5 false followed
65 // by 10 true, a must have 15 elements.
5f697f7a
BK
66 template<typename _Tp>
67 void
ed6814f7 68 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b,
5f697f7a
BK
69 size_t __n)
70 {
71 _Tp* __p (__a._M_data);
72 bool* __ok (__m._M_data);
ed6814f7
BI
73 for (_Tp* __q = __b._M_data; __q < __b._M_data + __n;
74 ++__q, ++__ok, ++__p)
5f697f7a 75 {
ed6814f7 76 while (! *__ok)
5f697f7a
BK
77 {
78 ++__ok;
79 ++__p;
80 }
81 *__q = *__p;
82 }
725dc051 83 }
725dc051 84
e9264dac
PC
85 // Copy n consecutive elements from a into elements of b. Elements
86 // of b are skipped if the corresponding element of m is false. m
87 // must contain at least n true elements. b must have at least as
88 // many elements as the index of the nth true element of m. I.e. if
89 // m has 15 elements with 5 false followed by 10 true, b must have
90 // at least 15 elements.
5f697f7a
BK
91 template<typename _Tp>
92 void
ed6814f7 93 __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b,
5f697f7a
BK
94 _Array<bool> __m)
95 {
96 _Tp* __q (__b._M_data);
97 bool* __ok (__m._M_data);
ed6814f7
BI
98 for (_Tp* __p = __a._M_data; __p < __a._M_data+__n;
99 ++__p, ++__ok, ++__q)
5f697f7a 100 {
ed6814f7 101 while (! *__ok)
5f697f7a
BK
102 {
103 ++__ok;
104 ++__q;
105 }
106 *__q = *__p;
107 }
725dc051 108 }
725dc051 109
e9264dac
PC
110 // Copy n elements from a into elements of b. Elements of a are
111 // skipped if the corresponding element of m is false. Elements of
112 // b are skipped if the corresponding element of k is false. m and
113 // k must contain at least n true elements. a and b must have at
114 // least as many elements as the index of the nth true element of m.
115 template<typename _Tp>
116 void
117 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, size_t __n,
118 _Array<_Tp> __b, _Array<bool> __k)
119 {
120 _Tp* __p (__a._M_data);
121 _Tp* __q (__b._M_data);
122 bool* __srcok (__m._M_data);
123 bool* __dstok (__k._M_data);
124 for (size_t __i = 0; __i < __n;
125 ++__srcok, ++__p, ++__dstok, ++__q, ++__i)
126 {
127 while (! *__srcok)
128 {
129 ++__srcok;
130 ++__p;
131 }
132 while (! *__dstok)
133 {
134 ++__dstok;
135 ++__q;
136 }
137 *__q = *__p;
138 }
139 }
140
141 // Copy n consecutive elements of e into consecutive elements of a.
142 // I.e. a[i] = e[i].
5f697f7a
BK
143 template<typename _Tp, class _Dom>
144 void
145 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
146 {
147 _Tp* __p (__a._M_data);
ed6814f7 148 for (size_t __i = 0; __i < __n; ++__i, ++__p)
5f697f7a 149 *__p = __e[__i];
725dc051 150 }
725dc051 151
e9264dac
PC
152 // Copy n consecutive elements of e into elements of a using stride
153 // s. I.e., a[0] = e[0], a[s] = e[1], a[2*s] = e[2].
5f697f7a
BK
154 template<typename _Tp, class _Dom>
155 void
ed6814f7 156 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
5f697f7a
BK
157 _Array<_Tp> __a, size_t __s)
158 {
159 _Tp* __p (__a._M_data);
ed6814f7 160 for (size_t __i = 0; __i < __n; ++__i, __p += __s)
5f697f7a 161 *__p = __e[__i];
725dc051 162 }
725dc051 163
e9264dac
PC
164 // Copy n consecutive elements of e into elements of a indexed by
165 // contents of i. I.e., a[i[0]] = e[0].
5f697f7a
BK
166 template<typename _Tp, class _Dom>
167 void
ed6814f7 168 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
5f697f7a
BK
169 _Array<_Tp> __a, _Array<size_t> __i)
170 {
171 size_t* __j (__i._M_data);
ed6814f7 172 for (size_t __k = 0; __k < __n; ++__k, ++__j)
5f697f7a
BK
173 __a._M_data[*__j] = __e[__k];
174 }
725dc051 175
e9264dac
PC
176 // Copy n elements of e indexed by contents of f into elements of a
177 // indexed by contents of i. I.e., a[i[0]] = e[f[0]].
178 template<typename _Tp>
179 void
180 __valarray_copy(_Array<_Tp> __e, _Array<size_t> __f,
181 size_t __n,
182 _Array<_Tp> __a, _Array<size_t> __i)
183 {
184 size_t* __g (__f._M_data);
185 size_t* __j (__i._M_data);
186 for (size_t __k = 0; __k < __n; ++__k, ++__j, ++__g)
187 __a._M_data[*__j] = __e._M_data[*__g];
188 }
189
190 // Copy n consecutive elements of e into elements of a. Elements of
191 // a are skipped if the corresponding element of m is false. m must
192 // have at least n true elements and a must have at least as many
193 // elements as the index of the nth true element of m. I.e. if m
194 // has 5 false followed by 10 true elements and n == 10, a must have
195 // at least 15 elements.
5f697f7a
BK
196 template<typename _Tp, class _Dom>
197 void
ed6814f7 198 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
5f697f7a
BK
199 _Array<_Tp> __a, _Array<bool> __m)
200 {
201 bool* __ok (__m._M_data);
202 _Tp* __p (__a._M_data);
ed6814f7 203 for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p)
5f697f7a 204 {
ed6814f7 205 while (! *__ok)
5f697f7a
BK
206 {
207 ++__ok;
208 ++__p;
209 }
210 *__p = __e[__i];
211 }
212 }
ed6814f7 213
5f697f7a
BK
214
215 template<typename _Tp, class _Dom>
216 void
217 __valarray_copy_construct(const _Expr<_Dom, _Tp>& __e, size_t __n,
218 _Array<_Tp> __a)
219 {
220 _Tp* __p (__a._M_data);
ed6814f7 221 for (size_t __i = 0; __i < __n; ++__i, ++__p)
5f697f7a
BK
222 new (__p) _Tp(__e[__i]);
223 }
725dc051
BK
224
225
5f697f7a
BK
226 template<typename _Tp>
227 void
228 __valarray_copy_construct(_Array<_Tp> __a, _Array<bool> __m,
229 _Array<_Tp> __b, size_t __n)
230 {
231 _Tp* __p (__a._M_data);
232 bool* __ok (__m._M_data);
233 for (_Tp* __q = __b._M_data; __q < __b._M_data+__n; ++__q, ++__ok, ++__p)
234 {
ed6814f7 235 while (! *__ok)
5f697f7a
BK
236 {
237 ++__ok;
238 ++__p;
239 }
240 new (__q) _Tp(*__p);
241 }
242 }
3cbc7af0
BK
243
244_GLIBCXX_END_NAMESPACE
725dc051 245
3d7c150e 246#endif /* _VALARRAY_ARRAY_TCC */