1 // The template and inlines for the -*- C++ -*- internal _Array helper class.
3 // Copyright (C) 1997, 1998, 1999, 2003, 2005, 2009, 2010
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 /** @file bits/valarray_array.tcc
27 * This is an internal header file, included by other library headers.
28 * Do not attempt to use it directly. @headername{valarray}
31 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
33 #ifndef _VALARRAY_ARRAY_TCC
34 #define _VALARRAY_ARRAY_TCC 1
36 namespace std _GLIBCXX_VISIBILITY(default)
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 template<typename _Tp>
42 __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m,
45 _Tp* __p = __a._M_data;
46 bool* __ok (__m._M_data);
47 for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p)
58 // Copy n elements of a into consecutive elements of b. When m is
59 // false, the corresponding element of a is skipped. m must contain
60 // at least n true elements. a must contain at least n elements and
61 // enough elements to match up with m through the nth true element
62 // of m. I.e. if n is 10, m has 15 elements with 5 false followed
63 // by 10 true, a must have 15 elements.
64 template<typename _Tp>
66 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b,
69 _Tp* __p (__a._M_data);
70 bool* __ok (__m._M_data);
71 for (_Tp* __q = __b._M_data; __q < __b._M_data + __n;
83 // Copy n consecutive elements from a into elements of b. Elements
84 // of b are skipped if the corresponding element of m is false. m
85 // must contain at least n true elements. b must have at least as
86 // many elements as the index of the nth true element of m. I.e. if
87 // m has 15 elements with 5 false followed by 10 true, b must have
88 // at least 15 elements.
89 template<typename _Tp>
91 __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b,
94 _Tp* __q (__b._M_data);
95 bool* __ok (__m._M_data);
96 for (_Tp* __p = __a._M_data; __p < __a._M_data+__n;
108 // Copy n elements from a into elements of b. Elements of a are
109 // skipped if the corresponding element of m is false. Elements of
110 // b are skipped if the corresponding element of k is false. m and
111 // k must contain at least n true elements. a and b must have at
112 // least as many elements as the index of the nth true element of m.
113 template<typename _Tp>
115 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, size_t __n,
116 _Array<_Tp> __b, _Array<bool> __k)
118 _Tp* __p (__a._M_data);
119 _Tp* __q (__b._M_data);
120 bool* __srcok (__m._M_data);
121 bool* __dstok (__k._M_data);
122 for (size_t __i = 0; __i < __n;
123 ++__srcok, ++__p, ++__dstok, ++__q, ++__i)
139 // Copy n consecutive elements of e into consecutive elements of a.
141 template<typename _Tp, class _Dom>
143 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
145 _Tp* __p (__a._M_data);
146 for (size_t __i = 0; __i < __n; ++__i, ++__p)
150 // Copy n consecutive elements of e into elements of a using stride
151 // s. I.e., a[0] = e[0], a[s] = e[1], a[2*s] = e[2].
152 template<typename _Tp, class _Dom>
154 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
155 _Array<_Tp> __a, size_t __s)
157 _Tp* __p (__a._M_data);
158 for (size_t __i = 0; __i < __n; ++__i, __p += __s)
162 // Copy n consecutive elements of e into elements of a indexed by
163 // contents of i. I.e., a[i[0]] = e[0].
164 template<typename _Tp, class _Dom>
166 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
167 _Array<_Tp> __a, _Array<size_t> __i)
169 size_t* __j (__i._M_data);
170 for (size_t __k = 0; __k < __n; ++__k, ++__j)
171 __a._M_data[*__j] = __e[__k];
174 // Copy n elements of e indexed by contents of f into elements of a
175 // indexed by contents of i. I.e., a[i[0]] = e[f[0]].
176 template<typename _Tp>
178 __valarray_copy(_Array<_Tp> __e, _Array<size_t> __f,
180 _Array<_Tp> __a, _Array<size_t> __i)
182 size_t* __g (__f._M_data);
183 size_t* __j (__i._M_data);
184 for (size_t __k = 0; __k < __n; ++__k, ++__j, ++__g)
185 __a._M_data[*__j] = __e._M_data[*__g];
188 // Copy n consecutive elements of e into elements of a. Elements of
189 // a are skipped if the corresponding element of m is false. m must
190 // have at least n true elements and a must have at least as many
191 // elements as the index of the nth true element of m. I.e. if m
192 // has 5 false followed by 10 true elements and n == 10, a must have
193 // at least 15 elements.
194 template<typename _Tp, class _Dom>
196 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
197 _Array<_Tp> __a, _Array<bool> __m)
199 bool* __ok (__m._M_data);
200 _Tp* __p (__a._M_data);
201 for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p)
213 template<typename _Tp, class _Dom>
215 __valarray_copy_construct(const _Expr<_Dom, _Tp>& __e, size_t __n,
218 _Tp* __p (__a._M_data);
219 for (size_t __i = 0; __i < __n; ++__i, ++__p)
220 new (__p) _Tp(__e[__i]);
224 template<typename _Tp>
226 __valarray_copy_construct(_Array<_Tp> __a, _Array<bool> __m,
227 _Array<_Tp> __b, size_t __n)
229 _Tp* __p (__a._M_data);
230 bool* __ok (__m._M_data);
231 for (_Tp* __q = __b._M_data; __q < __b._M_data+__n; ++__q, ++__ok, ++__p)
242 _GLIBCXX_END_NAMESPACE_VERSION
245 #endif /* _VALARRAY_ARRAY_TCC */