2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / include / bits / valarray_array.tcc
blob289001cf792cf1aa80d70483094ef0eaae906fad
1 // The template and inlines for the -*- C++ -*- internal _Array helper class.
3 // Copyright (C) 1997, 1998, 1999, 2003 Free Software Foundation, Inc.
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.
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,
19 // USA.
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
35 namespace std
37   template<typename _Tp>
38     void
39     __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m, 
40                     const _Tp& __t)
41     {
42       _Tp* __p = __a._M_data;
43       bool* __ok (__m._M_data);
44       for (size_t __i=0; __i < __n; ++__i, ++__ok, ++__p) 
45         {
46           while (!*__ok) 
47           {
48             ++__ok;
49             ++__p;
50           }
51           *__p = __t;
52         }
53     }
54   
55   template<typename _Tp>
56     void
57     __valarray_copy(_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b, 
58                     size_t __n)
59     {
60       _Tp* __p (__a._M_data);
61       bool* __ok (__m._M_data);
62       for (_Tp* __q = __b._M_data; __q < __b._M_data + __n; 
63            ++__q, ++__ok, ++__p) 
64         {
65           while (! *__ok) 
66             {
67               ++__ok;
68               ++__p;
69             }
70           *__q = *__p;
71         }
72     }
74   template<typename _Tp>
75     void
76     __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b, 
77                     _Array<bool> __m)
78     {
79       _Tp* __q (__b._M_data);
80       bool* __ok (__m._M_data);
81       for (_Tp* __p = __a._M_data; __p < __a._M_data+__n; 
82            ++__p, ++__ok, ++__q) 
83         {
84           while (! *__ok) 
85             {
86               ++__ok;
87               ++__q;
88             }
89           *__q = *__p;
90         }
91     }
93   template<typename _Tp, class _Dom>
94     void
95     __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
96     {
97       _Tp* __p (__a._M_data);
98       for (size_t __i = 0; __i < __n; ++__i, ++__p) 
99         *__p = __e[__i];
100     }
102   template<typename _Tp, class _Dom>
103     void
104     __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, 
105                      _Array<_Tp> __a, size_t __s)
106     {
107       _Tp* __p (__a._M_data);
108       for (size_t __i = 0; __i < __n; ++__i, __p += __s) 
109         *__p = __e[__i];
110     }
112   template<typename _Tp, class _Dom>
113     void
114     __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, 
115                     _Array<_Tp> __a, _Array<size_t> __i)
116     {
117       size_t* __j (__i._M_data);
118       for (size_t __k = 0; __k < __n; ++__k, ++__j) 
119         __a._M_data[*__j] = __e[__k];
120     }
122   template<typename _Tp, class _Dom>
123     void
124     __valarray_copy(const _Expr<_Dom, _Tp>& __e, size_t __n, 
125                     _Array<_Tp> __a, _Array<bool> __m)
126     {
127       bool* __ok (__m._M_data);
128       _Tp* __p (__a._M_data);
129       for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p) 
130         {
131           while (! *__ok) 
132             {
133               ++__ok;
134               ++__p;
135             }
136           *__p = __e[__i];
137         }
138     }
139   
141   template<typename _Tp, class _Dom>
142     void
143     __valarray_copy_construct(const _Expr<_Dom, _Tp>& __e, size_t __n,
144                               _Array<_Tp> __a)
145     {
146       _Tp* __p (__a._M_data);
147       for (size_t __i = 0; __i < __n; ++__i, ++__p) 
148         new (__p) _Tp(__e[__i]);
149     }
152   template<typename _Tp>
153     void
154     __valarray_copy_construct(_Array<_Tp> __a, _Array<bool> __m,
155                               _Array<_Tp> __b, size_t __n)
156     {
157       _Tp* __p (__a._M_data);
158       bool* __ok (__m._M_data);
159       for (_Tp* __q = __b._M_data; __q < __b._M_data+__n; ++__q, ++__ok, ++__p)
160         {
161           while (! *__ok) 
162             {
163               ++__ok;
164               ++__p;
165             }
166           new (__q) _Tp(*__p);
167         }
168     }
169 } // namespace std
171 #endif /* _VALARRAY_ARRAY_TCC */