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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
32 #ifndef _VALARRAY_ARRAY_TCC
33 #define _VALARRAY_ARRAY_TCC 1
37 template<typename _Tp>
39 __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m,
42 _Tp* __p = __a._M_data;
43 bool* __ok (__m._M_data);
44 for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p)
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.
61 template<typename _Tp>
63 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b,
66 _Tp* __p (__a._M_data);
67 bool* __ok (__m._M_data);
68 for (_Tp* __q = __b._M_data; __q < __b._M_data + __n;
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.
86 template<typename _Tp>
88 __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b,
91 _Tp* __q (__b._M_data);
92 bool* __ok (__m._M_data);
93 for (_Tp* __p = __a._M_data; __p < __a._M_data+__n;
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>
112 __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, size_t __n,
113 _Array<_Tp> __b, _Array<bool> __k)
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)
136 // Copy n consecutive elements of e into consecutive elements of a.
138 template<typename _Tp, class _Dom>
140 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
142 _Tp* __p (__a._M_data);
143 for (size_t __i = 0; __i < __n; ++__i, ++__p)
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].
149 template<typename _Tp, class _Dom>
151 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
152 _Array<_Tp> __a, size_t __s)
154 _Tp* __p (__a._M_data);
155 for (size_t __i = 0; __i < __n; ++__i, __p += __s)
159 // Copy n consecutive elements of e into elements of a indexed by
160 // contents of i. I.e., a[i[0]] = e[0].
161 template<typename _Tp, class _Dom>
163 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
164 _Array<_Tp> __a, _Array<size_t> __i)
166 size_t* __j (__i._M_data);
167 for (size_t __k = 0; __k < __n; ++__k, ++__j)
168 __a._M_data[*__j] = __e[__k];
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>
175 __valarray_copy(_Array<_Tp> __e, _Array<size_t> __f,
177 _Array<_Tp> __a, _Array<size_t> __i)
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];
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.
191 template<typename _Tp, class _Dom>
193 __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n,
194 _Array<_Tp> __a, _Array<bool> __m)
196 bool* __ok (__m._M_data);
197 _Tp* __p (__a._M_data);
198 for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p)
210 template<typename _Tp, class _Dom>
212 __valarray_copy_construct(const _Expr<_Dom, _Tp>& __e, size_t __n,
215 _Tp* __p (__a._M_data);
216 for (size_t __i = 0; __i < __n; ++__i, ++__p)
217 new (__p) _Tp(__e[__i]);
221 template<typename _Tp>
223 __valarray_copy_construct(_Array<_Tp> __a, _Array<bool> __m,
224 _Array<_Tp> __b, size_t __n)
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)
240 #endif /* _VALARRAY_ARRAY_TCC */