1 // The template and inlines for the -*- C++ -*- internal _Array helper class.
3 // Copyright (C) 1997, 1998, 1999, 2003 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 2, 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 // 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
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
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.
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.
35 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
37 #ifndef _VALARRAY_ARRAY_TCC
38 #define _VALARRAY_ARRAY_TCC 1
42 template<typename _Tp>
44 __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m,
47 _Tp* __p = __a._M_data;
48 bool* __ok (__m._M_data);
49 for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p)
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.
66 template<typename _Tp>
68 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b,
71 _Tp* __p (__a._M_data);
72 bool* __ok (__m._M_data);
73 for (_Tp* __q = __b._M_data; __q < __b._M_data + __n;
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.
91 template<typename _Tp>
93 __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b,
96 _Tp* __q (__b._M_data);
97 bool* __ok (__m._M_data);
98 for (_Tp* __p = __a._M_data; __p < __a._M_data+__n;
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>
117 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, size_t __n,
118 _Array<_Tp> __b, _Array<bool> __k)
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)
141 // Copy n consecutive elements of e into consecutive elements of a.
143 template<typename _Tp, class _Dom>
145 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
147 _Tp* __p (__a._M_data);
148 for (size_t __i = 0; __i < __n; ++__i, ++__p)
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].
154 template<typename _Tp, class _Dom>
156 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
157 _Array<_Tp> __a, size_t __s)
159 _Tp* __p (__a._M_data);
160 for (size_t __i = 0; __i < __n; ++__i, __p += __s)
164 // Copy n consecutive elements of e into elements of a indexed by
165 // contents of i. I.e., a[i[0]] = e[0].
166 template<typename _Tp, class _Dom>
168 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
169 _Array<_Tp> __a, _Array<size_t> __i)
171 size_t* __j (__i._M_data);
172 for (size_t __k = 0; __k < __n; ++__k, ++__j)
173 __a._M_data[*__j] = __e[__k];
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>
180 __valarray_copy(_Array<_Tp> __e, _Array<size_t> __f,
182 _Array<_Tp> __a, _Array<size_t> __i)
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];
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.
196 template<typename _Tp, class _Dom>
198 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
199 _Array<_Tp> __a, _Array<bool> __m)
201 bool* __ok (__m._M_data);
202 _Tp* __p (__a._M_data);
203 for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p)
215 template<typename _Tp, class _Dom>
217 __valarray_copy_construct(const _Expr<_Dom, _Tp>& __e, size_t __n,
220 _Tp* __p (__a._M_data);
221 for (size_t __i = 0; __i < __n; ++__i, ++__p)
222 new (__p) _Tp(__e[__i]);
226 template<typename _Tp>
228 __valarray_copy_construct(_Array<_Tp> __a, _Array<bool> __m,
229 _Array<_Tp> __b, size_t __n)
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)
245 #endif /* _VALARRAY_ARRAY_TCC */