OSDN Git Service

* sh.h (PREDICATE_CODES): Remove register_operand entry.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / valarray_array.h
1 // The template and inlines for the -*- C++ -*- internal _Array helper class.
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2003
4 //  Free Software Foundation, Inc.
5 //
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 2, or (at your option)
10 // any later version.
11
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.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
32
33 /** @file valarray_array.h
34  *  This is an internal header file, included by other library headers.
35  *  You should not attempt to use it directly.
36  */
37
38 #ifndef _VALARRAY_ARRAY_H
39 #define _VALARRAY_ARRAY_H 1
40
41 #pragma GCC system_header
42
43 #include <bits/c++config.h>
44 #include <bits/cpp_type_traits.h>
45 #include <cstdlib>
46 #include <cstring>
47 #include <new>
48
49 namespace std
50 {
51   //
52   // Helper functions on raw pointers
53   //
54
55   // We get memory by the old fashion way
56   inline void*
57   __valarray_get_memory(size_t __n)
58   { return operator new(__n); }
59
60   template<typename _Tp>
61      inline _Tp*__restrict__
62      __valarray_get_storage(size_t __n)
63      {
64        return static_cast<_Tp*__restrict__>
65          (std::__valarray_get_memory(__n * sizeof(_Tp)));
66      }
67
68   // Return memory to the system
69   inline void
70   __valarray_release_memory(void* __p)
71   { operator delete(__p); }
72
73   // Turn a raw-memory into an array of _Tp filled with _Tp()
74   // This is required in 'valarray<T> v(n);'
75   template<typename _Tp, bool>
76      struct _Array_default_ctor
77      {
78        // Please note that this isn't exception safe.  But
79        // valarrays aren't required to be exception safe.
80        inline static void
81        _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
82        {
83          while (__b != __e)
84            new(__b++) _Tp();
85        }
86      };
87
88   template<typename _Tp>
89      struct _Array_default_ctor<_Tp, true>
90      {
91        // For fundamental types, it suffices to say 'memset()'
92        inline static void
93        _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
94        { std::memset(__b, 0, (__e - __b) * sizeof(_Tp)); }
95      };
96
97   template<typename _Tp>
98      inline void
99      __valarray_default_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
100      {
101        _Array_default_ctor<_Tp, __is_fundamental<_Tp>::_M_type>::
102          _S_do_it(__b, __e);
103      }
104
105   // Turn a raw-memory into an array of _Tp filled with __t
106   // This is the required in valarray<T> v(n, t).  Also
107   // used in valarray<>::resize().
108   template<typename _Tp, bool>
109      struct _Array_init_ctor
110      {
111        // Please note that this isn't exception safe.  But
112        // valarrays aren't required to be exception safe.
113        inline static void
114        _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t)
115        {
116          while (__b != __e)
117            new(__b++) _Tp(__t);
118        }
119      };
120
121   template<typename _Tp>
122      struct _Array_init_ctor<_Tp, true>
123      {
124        inline static void
125        _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e,  const _Tp __t)
126        {
127          while (__b != __e)
128            *__b++ = __t;
129        }
130      };
131
132   template<typename _Tp>
133      inline void
134      __valarray_fill_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e,
135                                const _Tp __t)
136      {
137        _Array_init_ctor<_Tp, __is_fundamental<_Tp>::_M_type>::
138          _S_do_it(__b, __e, __t);
139      }
140
141   //
142   // copy-construct raw array [__o, *) from plain array [__b, __e)
143   // We can't just say 'memcpy()'
144   //
145   template<typename _Tp, bool>
146      struct _Array_copy_ctor
147      {
148        // Please note that this isn't exception safe.  But
149        // valarrays aren't required to be exception safe.
150        inline static void
151        _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e,
152                 _Tp* __restrict__ __o)
153        {
154          while (__b != __e)
155            new(__o++) _Tp(*__b++);
156        }
157      };
158
159   template<typename _Tp>
160      struct _Array_copy_ctor<_Tp, true>
161      {
162        inline static void
163        _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e,
164                 _Tp* __restrict__ __o)
165        { std::memcpy(__o, __b, (__e - __b)*sizeof(_Tp)); }
166      };
167
168   template<typename _Tp>
169      inline void
170      __valarray_copy_construct(const _Tp* __restrict__ __b,
171                                const _Tp* __restrict__ __e,
172                                _Tp* __restrict__ __o)
173      {
174        _Array_copy_ctor<_Tp, __is_fundamental<_Tp>::_M_type>::
175          _S_do_it(__b, __e, __o);
176      }
177
178   // copy-construct raw array [__o, *) from strided array __a[<__n : __s>]
179   template<typename _Tp>
180      inline void
181      __valarray_copy_construct (const _Tp* __restrict__ __a, size_t __n,
182                                 size_t __s, _Tp* __restrict__ __o)
183      {
184        if (__is_fundamental<_Tp>::_M_type)
185          while (__n--)
186            {
187              *__o++ = *__a;
188              __a += __s;
189            }
190        else
191          while (__n--)
192            {
193              new(__o++) _Tp(*__a);
194              __a += __s;
195            }
196      }
197
198   // copy-construct raw array [__o, *) from indexed array __a[__i[<__n>]]
199   template<typename _Tp>
200      inline void
201      __valarray_copy_construct (const _Tp* __restrict__ __a,
202                                 const size_t* __restrict__ __i,
203                                 _Tp* __restrict__ __o, size_t __n)
204      {
205        if (__is_fundamental<_Tp>::_M_type)
206          while (__n--)
207            *__o++ = __a[*__i++];
208        else
209          while (__n--)
210            new (__o++) _Tp(__a[*__i++]);
211      }
212
213   // Do the necessary cleanup when we're done with arrays.
214   template<typename _Tp>
215      inline void
216      __valarray_destroy_elements(_Tp* __restrict__ __b, _Tp* __restrict__ __e)
217      {
218        if (!__is_fundamental<_Tp>::_M_type)
219          while (__b != __e)
220            {
221              __b->~_Tp();
222              ++__b;
223            }
224      }
225
226   // Fill a plain array __a[<__n>] with __t
227   template<typename _Tp>
228      inline void
229      __valarray_fill(_Tp* __restrict__ __a, size_t __n, const _Tp& __t)
230      {
231        while (__n--)
232          *__a++ = __t;
233      }
234
235   // fill strided array __a[<__n-1 : __s>] with __t
236   template<typename _Tp>
237      inline void
238      __valarray_fill(_Tp* __restrict__ __a, size_t __n,
239                      size_t __s, const _Tp& __t)
240      {
241        for (size_t __i = 0; __i < __n; ++__i, __a += __s)
242          *__a = __t;
243      }
244
245   // fill indir   ect array __a[__i[<__n>]] with __i
246   template<typename _Tp>
247      inline void
248      __valarray_fill(_Tp* __restrict__ __a, const size_t* __restrict__ __i,
249                      size_t __n, const _Tp& __t)
250      {
251        for (size_t __j = 0; __j < __n; ++__j, ++__i)
252          __a[*__i] = __t;
253      }
254
255   // copy plain array __a[<__n>] in __b[<__n>]
256   // For non-fundamental types, it is wrong to say 'memcpy()'
257   template<typename _Tp, bool>
258      struct _Array_copier
259      {
260        inline static void
261        _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b)
262        {
263          while(__n--)
264            *__b++ = *__a++;
265        }
266      };
267
268   template<typename _Tp>
269      struct _Array_copier<_Tp, true>
270      {
271        inline static void
272        _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b)
273        { std::memcpy (__b, __a, __n * sizeof (_Tp)); }
274      };
275
276   // Copy a plain array __a[<__n>] into a play array __b[<>]
277   template<typename _Tp>
278      inline void
279      __valarray_copy(const _Tp* __restrict__ __a, size_t __n,
280                      _Tp* __restrict__ __b)
281      {
282        _Array_copier<_Tp, __is_fundamental<_Tp>::_M_type>::
283          _S_do_it(__a, __n, __b);
284      }
285
286   // Copy strided array __a[<__n : __s>] in plain __b[<__n>]
287   template<typename _Tp>
288      inline void
289      __valarray_copy(const _Tp* __restrict__ __a, size_t __n, size_t __s,
290                      _Tp* __restrict__ __b)
291      {
292        for (size_t __i = 0; __i < __n; ++__i, ++__b, __a += __s)
293          *__b = *__a;
294      }
295
296   // Copy a plain array  __a[<__n>] into a strided array __b[<__n : __s>]
297   template<typename _Tp>
298      inline void
299      __valarray_copy(const _Tp* __restrict__ __a, _Tp* __restrict__ __b,
300                      size_t __n, size_t __s)
301      {
302        for (size_t __i = 0; __i < __n; ++__i, ++__a, __b += __s)
303          *__b = *__a;
304      }
305
306   // Copy strided array __src[<__n : __s1>] into another
307   // strided array __dst[< : __s2>].  Their sizes must match.
308   template<typename _Tp>
309      inline void
310      __valarray_copy(const _Tp* __restrict__ __src, size_t __n, size_t __s1,
311                      _Tp* __restrict__ __dst, size_t __s2)
312      {
313        for (size_t __i = 0; __i < __n; ++__i)
314          __dst[__i * __s2] = __src[__i * __s1];
315      }
316
317
318   // Copy an indexed array __a[__i[<__n>]] in plain array __b[<__n>]
319   template<typename _Tp>
320      inline void
321      __valarray_copy (const _Tp* __restrict__ __a,
322                       const size_t* __restrict__ __i,
323                       _Tp* __restrict__ __b, size_t __n)
324      {
325        for (size_t __j = 0; __j < __n; ++__j, ++__b, ++__i)
326          *__b = __a[*__i];
327      }
328
329   // Copy a plain array __a[<__n>] in an indexed array __b[__i[<__n>]]
330   template<typename _Tp>
331      inline void
332      __valarray_copy (const _Tp* __restrict__ __a, size_t __n,
333                       _Tp* __restrict__ __b, const size_t* __restrict__ __i)
334      {
335        for (size_t __j = 0; __j < __n; ++__j, ++__a, ++__i)
336          __b[*__i] = *__a;
337      }
338
339   // Copy the __n first elements of an indexed array __src[<__i>] into
340   // another indexed array __dst[<__j>].
341   template<typename _Tp>
342      inline void
343      __valarray_copy(const _Tp* __restrict__ __src, size_t __n,
344                      const size_t* __restrict__ __i,
345                      _Tp* __restrict__ __dst, const size_t* __restrict__ __j)
346      {
347        for (size_t __k = 0; __k < __n; ++__k)
348          __dst[*__j++] = __src[*__i++];
349      }
350
351   //
352   // Compute the sum of elements in range [__f, __l)
353   // This is a naive algorithm.  It suffers from cancelling.
354   // In the future try to specialize
355   // for _Tp = float, double, long double using a more accurate
356   // algorithm.
357   //
358   template<typename _Tp>
359      inline _Tp
360      __valarray_sum(const _Tp* __restrict__ __f, const _Tp* __restrict__ __l)
361      {
362        _Tp __r = _Tp();
363        while (__f != __l)
364          __r += *__f++;
365        return __r;
366      }
367
368   // Compute the product of all elements in range [__f, __l)
369   template<typename _Tp>
370      inline _Tp
371      __valarray_product(const _Tp* __restrict__ __f,
372                         const _Tp* __restrict__ __l)
373      {
374        _Tp __r = _Tp(1);
375        while (__f != __l)
376          __r = __r * *__f++;
377        return __r;
378      }
379
380   // Compute the min/max of an array-expression
381   template<typename _Ta>
382      inline typename _Ta::value_type
383      __valarray_min(const _Ta& __a)
384      {
385        size_t __s = __a.size();
386        typedef typename _Ta::value_type _Value_type;
387        _Value_type __r = __s == 0 ? _Value_type() : __a[0];
388        for (size_t __i = 1; __i < __s; ++__i)
389          {
390            _Value_type __t = __a[__i];
391            if (__t < __r)
392              __r = __t;
393          }
394        return __r;
395      }
396
397   template<typename _Ta>
398      inline typename _Ta::value_type
399      __valarray_max(const _Ta& __a)
400      {
401        size_t __s = __a.size();
402        typedef typename _Ta::value_type _Value_type;
403        _Value_type __r = __s == 0 ? _Value_type() : __a[0];
404        for (size_t __i = 1; __i < __s; ++__i)
405          {
406            _Value_type __t = __a[__i];
407            if (__t > __r)
408              __r = __t;
409          }
410        return __r;
411      }
412
413   //
414   // Helper class _Array, first layer of valarray abstraction.
415   // All operations on valarray should be forwarded to this class
416   // whenever possible. -- gdr
417   //
418
419   template<typename _Tp>
420      struct _Array
421      {
422        explicit _Array(size_t);
423        explicit _Array(_Tp* const __restrict__);
424        explicit _Array(const valarray<_Tp>&);
425        _Array(const _Tp* __restrict__, size_t);
426
427        _Tp* begin() const;
428
429        _Tp* const __restrict__ _M_data;
430      };
431
432   template<typename _Tp>
433      inline void
434      __valarray_fill (_Array<_Tp> __a, size_t __n, const _Tp& __t)
435      { std::__valarray_fill(__a._M_data, __n, __t); }
436
437   template<typename _Tp>
438      inline void
439      __valarray_fill(_Array<_Tp> __a, size_t __n, size_t __s, const _Tp& __t)
440      { std::__valarray_fill(__a._M_data, __n, __s, __t); }
441
442   template<typename _Tp>
443      inline void
444      __valarray_fill(_Array<_Tp> __a, _Array<size_t> __i,
445                      size_t __n, const _Tp& __t)
446      { std::__valarray_fill(__a._M_data, __i._M_data, __n, __t); }
447
448   // Copy a plain array __a[<__n>] into a play array __b[<>]
449   template<typename _Tp>
450      inline void
451      __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b)
452      { std::__valarray_copy(__a._M_data, __n, __b._M_data); }
453
454   // Copy strided array __a[<__n : __s>] in plain __b[<__n>]
455   template<typename _Tp>
456      inline void
457      __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s, _Array<_Tp> __b)
458      { std::__valarray_copy(__a._M_data, __n, __s, __b._M_data); }
459
460   // Copy a plain array  __a[<__n>] into a strided array __b[<__n : __s>]
461   template<typename _Tp>
462      inline void
463      __valarray_copy(_Array<_Tp> __a, _Array<_Tp> __b, size_t __n, size_t __s)
464      { __valarray_copy(__a._M_data, __b._M_data, __n, __s); }
465
466   // Copy strided array __src[<__n : __s1>] into another
467   // strided array __dst[< : __s2>].  Their sizes must match.
468   template<typename _Tp>
469      inline void
470      __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s1,
471                      _Array<_Tp> __b, size_t __s2)
472      { std::__valarray_copy(__a._M_data, __n, __s1, __b._M_data, __s2); }
473
474
475   // Copy an indexed array __a[__i[<__n>]] in plain array __b[<__n>]
476   template<typename _Tp>
477      inline void
478      __valarray_copy(_Array<_Tp> __a, _Array<size_t> __i,
479                      _Array<_Tp> __b, size_t __n)
480      { std::__valarray_copy(__a._M_data, __i._M_data, __b._M_data, __n); }
481
482   // Copy a plain array __a[<__n>] in an indexed array __b[__i[<__n>]]
483   template<typename _Tp>
484      inline void
485      __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b,
486                      _Array<size_t> __i)
487      { std::__valarray_copy(__a._M_data, __n, __b._M_data, __i._M_data); }
488
489   // Copy the __n first elements of an indexed array __src[<__i>] into
490   // another indexed array __dst[<__j>].
491   template<typename _Tp>
492      inline void
493      __valarray_copy(_Array<_Tp> __src, size_t __n, _Array<size_t> __i,
494                      _Array<_Tp> __dst, _Array<size_t> __j)
495      {
496        std::__valarray_copy(__src._M_data, __n, __i._M_data,
497                             __dst._M_data, __j._M_data);
498      }
499
500   template<typename _Tp>
501      inline
502      _Array<_Tp>::_Array(size_t __n)
503      : _M_data(__valarray_get_storage<_Tp>(__n))
504      { std::__valarray_default_construct(_M_data, _M_data + __n); }
505
506   template<typename _Tp>
507      inline
508      _Array<_Tp>::_Array(_Tp* const __restrict__ __p)
509      : _M_data (__p) {}
510
511   template<typename _Tp>
512      inline
513      _Array<_Tp>::_Array(const valarray<_Tp>& __v)
514      : _M_data (__v._M_data) {}
515
516   template<typename _Tp>
517      inline
518      _Array<_Tp>::_Array(const _Tp* __restrict__ __b, size_t __s)
519      : _M_data(__valarray_get_storage<_Tp>(__s))
520      { std::__valarray_copy_construct(__b, __s, _M_data); }
521
522   template<typename _Tp>
523      inline _Tp*
524      _Array<_Tp>::begin () const
525      { return _M_data; }
526
527 #define _DEFINE_ARRAY_FUNCTION(_Op, _Name)                              \
528   template<typename _Tp>                                                \
529     inline void                                                         \
530     _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n, const _Tp& __t) \
531     {                                                                   \
532       for (_Tp* __p = __a._M_data; __p < __a._M_data + __n; ++__p)      \
533         *__p _Op##= __t;                                                \
534     }                                                                   \
535                                                                         \
536   template<typename _Tp>                                                \
537     inline void                                                         \
538     _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b) \
539     {                                                                   \
540       _Tp* __p = __a._M_data;                                           \
541       for (_Tp* __q = __b._M_data; __q < __b._M_data + __n; ++__p, ++__q) \
542         *__p _Op##= *__q;                                               \
543     }                                                                   \
544                                                                         \
545   template<typename _Tp, class _Dom>                                    \
546     void                                                                \
547     _Array_augmented_##_Name(_Array<_Tp> __a,                           \
548                              const _Expr<_Dom, _Tp>& __e, size_t __n)   \
549     {                                                                   \
550       _Tp* __p(__a._M_data);                                            \
551       for (size_t __i = 0; __i < __n; ++__i, ++__p)                     \
552         *__p _Op##= __e[__i];                                           \
553     }                                                                   \
554                                                                         \
555   template<typename _Tp>                                                \
556     inline void                                                         \
557     _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n, size_t __s,   \
558                              _Array<_Tp> __b)                           \
559     {                                                                   \
560       _Tp* __q(__b._M_data);                                            \
561       for (_Tp* __p = __a._M_data; __p < __a._M_data + __s * __n;       \
562            __p += __s, ++__q)                                           \
563         *__p _Op##= *__q;                                               \
564     }                                                                   \
565                                                                         \
566   template<typename _Tp>                                                \
567     inline void                                                         \
568     _Array_augmented_##_Name(_Array<_Tp> __a, _Array<_Tp> __b,          \
569                              size_t __n, size_t __s)                    \
570     {                                                                   \
571       _Tp* __q(__b._M_data);                                            \
572       for (_Tp* __p = __a._M_data; __p < __a._M_data + __n;             \
573            ++__p, __q += __s)                                           \
574         *__p _Op##= *__q;                                               \
575     }                                                                   \
576                                                                         \
577   template<typename _Tp, class _Dom>                                    \
578     void                                                                \
579     _Array_augmented_##_Name(_Array<_Tp> __a, size_t __s,               \
580                              const _Expr<_Dom, _Tp>& __e, size_t __n)   \
581     {                                                                   \
582       _Tp* __p(__a._M_data);                                            \
583       for (size_t __i = 0; __i < __n; ++__i, __p += __s)                \
584         *__p _Op##= __e[__i];                                           \
585     }                                                                   \
586                                                                         \
587   template<typename _Tp>                                                \
588     inline void                                                         \
589     _Array_augmented_##_Name(_Array<_Tp> __a, _Array<size_t> __i,       \
590                              _Array<_Tp> __b, size_t __n)               \
591     {                                                                   \
592       _Tp* __q(__b._M_data);                                            \
593       for (size_t* __j = __i._M_data; __j < __i._M_data + __n;          \
594            ++__j, ++__q)                                                \
595         __a._M_data[*__j] _Op##= *__q;                                  \
596     }                                                                   \
597                                                                         \
598   template<typename _Tp>                                                \
599     inline void                                                         \
600     _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n,               \
601                              _Array<_Tp> __b, _Array<size_t> __i)       \
602     {                                                                   \
603       _Tp* __p(__a._M_data);                                            \
604       for (size_t* __j = __i._M_data; __j<__i._M_data + __n;            \
605            ++__j, ++__p)                                                \
606         *__p _Op##= __b._M_data[*__j];                                  \
607     }                                                                   \
608                                                                         \
609   template<typename _Tp, class _Dom>                                    \
610     void                                                                \
611     _Array_augmented_##_Name(_Array<_Tp> __a, _Array<size_t> __i,       \
612                              const _Expr<_Dom, _Tp>& __e, size_t __n)   \
613     {                                                                   \
614       size_t* __j(__i._M_data);                                         \
615       for (size_t __k = 0; __k<__n; ++__k, ++__j)                       \
616         __a._M_data[*__j] _Op##= __e[__k];                              \
617     }                                                                   \
618                                                                         \
619   template<typename _Tp>                                                \
620     void                                                                \
621     _Array_augmented_##_Name(_Array<_Tp> __a, _Array<bool> __m,         \
622                              _Array<_Tp> __b, size_t __n)               \
623     {                                                                   \
624       bool* __ok(__m._M_data);                                          \
625       _Tp* __p(__a._M_data);                                            \
626       for (_Tp* __q = __b._M_data; __q < __b._M_data + __n;             \
627            ++__q, ++__ok, ++__p)                                        \
628         {                                                               \
629           while (! *__ok)                                               \
630             {                                                           \
631               ++__ok;                                                   \
632               ++__p;                                                    \
633             }                                                           \
634           *__p _Op##= *__q;                                             \
635         }                                                               \
636     }                                                                   \
637                                                                         \
638   template<typename _Tp>                                                \
639     void                                                                \
640     _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n,               \
641                              _Array<_Tp> __b, _Array<bool> __m)         \
642     {                                                                   \
643       bool* __ok(__m._M_data);                                          \
644       _Tp* __q(__b._M_data);                                            \
645       for (_Tp* __p = __a._M_data; __p < __a._M_data + __n;             \
646            ++__p, ++__ok, ++__q)                                        \
647         {                                                               \
648           while (! *__ok)                                               \
649             {                                                           \
650               ++__ok;                                                   \
651               ++__q;                                                    \
652             }                                                           \
653           *__p _Op##= *__q;                                             \
654         }                                                               \
655     }                                                                   \
656                                                                         \
657   template<typename _Tp, class _Dom>                                    \
658     void                                                                \
659     _Array_augmented_##_Name(_Array<_Tp> __a, _Array<bool> __m,         \
660                              const _Expr<_Dom, _Tp>& __e, size_t __n)   \
661     {                                                                   \
662       bool* __ok(__m._M_data);                                          \
663       _Tp* __p(__a._M_data);                                            \
664       for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p)             \
665         {                                                               \
666           while (! *__ok)                                               \
667             {                                                           \
668               ++__ok;                                                   \
669               ++__p;                                                    \
670             }                                                           \
671           *__p _Op##= __e[__i];                                         \
672         }                                                               \
673     }
674
675    _DEFINE_ARRAY_FUNCTION(+, __plus)
676    _DEFINE_ARRAY_FUNCTION(-, __minus)
677    _DEFINE_ARRAY_FUNCTION(*, __multiplies)
678    _DEFINE_ARRAY_FUNCTION(/, __divides)
679    _DEFINE_ARRAY_FUNCTION(%, __modulus)
680    _DEFINE_ARRAY_FUNCTION(^, __bitwise_xor)
681    _DEFINE_ARRAY_FUNCTION(|, __bitwise_or)
682    _DEFINE_ARRAY_FUNCTION(&, __bitwise_and)
683    _DEFINE_ARRAY_FUNCTION(<<, __shift_left)
684    _DEFINE_ARRAY_FUNCTION(>>, __shift_right)
685
686 #undef _DEFINE_VALARRAY_FUNCTION
687 } // namespace std
688
689 #ifndef _GLIBCXX_EXPORT_TEMPLATE
690 # include <bits/valarray_array.tcc>
691 #endif
692
693 #endif /* _ARRAY_H */