1 // The template and inlines for the -*- C++ -*- internal _Array helper class.
3 // Copyright (C) 1997-2014 Free Software Foundation, Inc.
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)
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.
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.
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/>.
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}
30 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
32 #ifndef _VALARRAY_ARRAY_TCC
33 #define _VALARRAY_ARRAY_TCC 1
35 namespace std _GLIBCXX_VISIBILITY(default)
37 _GLIBCXX_BEGIN_NAMESPACE_VERSION
39 template<typename _Tp>
41 __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m,
44 _Tp* __p = __a._M_data;
45 bool* __ok (__m._M_data);
46 for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p)
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>
65 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b,
68 _Tp* __p (__a._M_data);
69 bool* __ok (__m._M_data);
70 for (_Tp* __q = __b._M_data; __q < __b._M_data + __n;
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>
90 __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b,
93 _Tp* __q (__b._M_data);
94 bool* __ok (__m._M_data);
95 for (_Tp* __p = __a._M_data; __p < __a._M_data+__n;
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>
114 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, size_t __n,
115 _Array<_Tp> __b, _Array<bool> __k)
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)
138 // Copy n consecutive elements of e into consecutive elements of a.
140 template<typename _Tp, class _Dom>
142 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
144 _Tp* __p (__a._M_data);
145 for (size_t __i = 0; __i < __n; ++__i, ++__p)
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>
153 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
154 _Array<_Tp> __a, size_t __s)
156 _Tp* __p (__a._M_data);
157 for (size_t __i = 0; __i < __n; ++__i, __p += __s)
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>
165 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
166 _Array<_Tp> __a, _Array<size_t> __i)
168 size_t* __j (__i._M_data);
169 for (size_t __k = 0; __k < __n; ++__k, ++__j)
170 __a._M_data[*__j] = __e[__k];
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>
177 __valarray_copy(_Array<_Tp> __e, _Array<size_t> __f,
179 _Array<_Tp> __a, _Array<size_t> __i)
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];
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>
195 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
196 _Array<_Tp> __a, _Array<bool> __m)
198 bool* __ok (__m._M_data);
199 _Tp* __p (__a._M_data);
200 for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p)
212 template<typename _Tp, class _Dom>
214 __valarray_copy_construct(const _Expr<_Dom, _Tp>& __e, size_t __n,
217 _Tp* __p (__a._M_data);
218 for (size_t __i = 0; __i < __n; ++__i, ++__p)
219 new (__p) _Tp(__e[__i]);
223 template<typename _Tp>
225 __valarray_copy_construct(_Array<_Tp> __a, _Array<bool> __m,
226 _Array<_Tp> __b, size_t __n)
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)
241 _GLIBCXX_END_NAMESPACE_VERSION
244 #endif /* _VALARRAY_ARRAY_TCC */