* arm.md (push_multi): Revert unintended change.
[official-gcc.git] / libstdc++ / std / std_valarray.h
blobd32412ce877af7034f70c5be82d5ac60d9d2282a
1 // The template and inlines for the -*- C++ -*- valarray class.
3 // Copyright (C) 1997-1999 Cygnus Solutions
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 __STD_VALARRAY__
33 #define __STD_VALARRAY__
34 #define _G_NO_VALARRAY_TEMPLATE_EXPORT 1
36 #include <cstddef>
37 #include <cmath>
38 #include <cstdlib>
39 #include <numeric>
40 #include <functional>
41 #include <algorithm>
43 #ifndef alloca
44 #ifdef __GNUC__
45 #define alloca __builtin_alloca
46 #else /* not GNU C. */
47 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
48 #include <alloca.h>
49 #else /* not sparc */
50 #if defined (MSDOS) && !defined (__TURBOC__)
51 #include <malloc.h>
52 #else /* not MSDOS, or __TURBOC__ */
53 #if defined(_AIX)
54 #include <malloc.h>
55 #pragma alloca
56 #else /* not MSDOS, __TURBOC__, or _AIX */
57 #ifdef __hpux
58 #endif /* __hpux */
59 #endif /* not _AIX */
60 #endif /* not MSDOS, or __TURBOC__ */
61 #endif /* not sparc. */
62 #endif /* not GNU C. */
63 #endif /* alloca not defined. */
65 extern "C" {
66 void* alloca(size_t);
69 extern "C++" {
71 template<class _Clos, typename _Tp> class _Expr;
73 template<typename _Tp1, typename _Tp2> class _ValArray;
75 template<template<class> class _Oper,
76 template<class, class> class _Meta, class _Dom> struct _UnClos;
78 template<template<class> class _Oper,
79 template<class, class> class _Meta1,
80 template<class, class> class _Meta2,
81 class _Dom1, class _Dom2> class _BinClos;
83 template<template<class, class> class _Meta, class _Dom> class _SClos;
85 template<template<class, class> class _Meta, class _Dom> class _GClos;
87 template<template<class, class> class _Meta, class _Dom> class _IClos;
89 template<template<class, class> class _Meta, class _Dom> class _ValFunClos;
91 template<template<class, class> class _Meta, class _Dom> class _RefFunClos;
93 template<class _Tp> struct _Unary_plus;
94 template<class _Tp> struct _Bitwise_and;
95 template<class _Tp> struct _Bitwise_or;
96 template<class _Tp> struct _Bitwise_xor;
97 template<class _Tp> struct _Bitwise_not;
98 template<class _Tp> struct _Shift_left;
99 template<class _Tp> struct _Shift_right;
101 template<class _Tp> class valarray; // An array of type _Tp
102 class slice; // BLAS-like slice out of an array
103 template<class _Tp> class slice_array;
104 class gslice; // generalized slice out of an array
105 template<class _Tp> class gslice_array;
106 template<class _Tp> class mask_array; // masked array
107 template<class _Tp> class indirect_array; // indirected array
109 } // extern "C++"
111 #include <std/valarray_array.h>
112 #include <std/valarray_meta.h>
114 extern "C++" {
116 template<class _Tp> class valarray
118 public:
119 typedef _Tp value_type;
121 // _lib.valarray.cons_ construct/destroy:
122 valarray();
123 explicit valarray(size_t);
124 valarray(const _Tp&, size_t);
125 valarray(const _Tp* __restrict__, size_t);
126 valarray(const valarray&);
127 valarray(const slice_array<_Tp>&);
128 valarray(const gslice_array<_Tp>&);
129 valarray(const mask_array<_Tp>&);
130 valarray(const indirect_array<_Tp>&);
131 template<class _Dom>
132 valarray(const _Expr<_Dom,_Tp>& __e);
133 ~valarray();
135 // _lib.valarray.assign_ assignment:
136 valarray<_Tp>& operator=(const valarray<_Tp>&);
137 valarray<_Tp>& operator=(const _Tp&);
138 valarray<_Tp>& operator=(const slice_array<_Tp>&);
139 valarray<_Tp>& operator=(const gslice_array<_Tp>&);
140 valarray<_Tp>& operator=(const mask_array<_Tp>&);
141 valarray<_Tp>& operator=(const indirect_array<_Tp>&);
143 template<class _Dom> valarray<_Tp>&
144 operator= (const _Expr<_Dom,_Tp>&);
146 // _lib.valarray.access_ element access:
147 _Tp operator[](size_t) const;
148 _Tp& operator[](size_t);
149 // _lib.valarray.sub_ subset operations:
150 _Expr<_SClos<_ValArray,_Tp>, _Tp> operator[](slice) const;
151 slice_array<_Tp> operator[](slice);
152 _Expr<_GClos<_ValArray,_Tp>, _Tp> operator[](const gslice&) const;
153 gslice_array<_Tp> operator[](const gslice&);
154 valarray<_Tp> operator[](const valarray<bool>&) const;
155 mask_array<_Tp> operator[](const valarray<bool>&);
156 _Expr<_IClos<_ValArray, _Tp>, _Tp>
157 operator[](const valarray<size_t>&) const;
158 indirect_array<_Tp> operator[](const valarray<size_t>&);
160 // _lib.valarray.unary_ unary operators:
161 _Expr<_UnClos<_Unary_plus,_ValArray,_Tp>,_Tp> operator+ () const;
162 _Expr<_UnClos<negate,_ValArray,_Tp>,_Tp> operator- () const;
163 _Expr<_UnClos<_Bitwise_not,_ValArray,_Tp>,_Tp> operator~ () const;
164 _Expr<_UnClos<logical_not,_ValArray,_Tp>,bool> operator! () const;
166 // _lib.valarray.cassign_ computed assignment:
167 valarray<_Tp>& operator*= (const _Tp&);
168 valarray<_Tp>& operator/= (const _Tp&);
169 valarray<_Tp>& operator%= (const _Tp&);
170 valarray<_Tp>& operator+= (const _Tp&);
171 valarray<_Tp>& operator-= (const _Tp&);
172 valarray<_Tp>& operator^= (const _Tp&);
173 valarray<_Tp>& operator&= (const _Tp&);
174 valarray<_Tp>& operator|= (const _Tp&);
175 valarray<_Tp>& operator<<=(const _Tp&);
176 valarray<_Tp>& operator>>=(const _Tp&);
177 valarray<_Tp>& operator*= (const valarray<_Tp>&);
178 valarray<_Tp>& operator/= (const valarray<_Tp>&);
179 valarray<_Tp>& operator%= (const valarray<_Tp>&);
180 valarray<_Tp>& operator+= (const valarray<_Tp>&);
181 valarray<_Tp>& operator-= (const valarray<_Tp>&);
182 valarray<_Tp>& operator^= (const valarray<_Tp>&);
183 valarray<_Tp>& operator|= (const valarray<_Tp>&);
184 valarray<_Tp>& operator&= (const valarray<_Tp>&);
185 valarray<_Tp>& operator<<=(const valarray<_Tp>&);
186 valarray<_Tp>& operator>>=(const valarray<_Tp>&);
188 template<class _Dom>
189 valarray<_Tp>& operator*= (const _Expr<_Dom,_Tp>&);
190 template<class _Dom>
191 valarray<_Tp>& operator/= (const _Expr<_Dom,_Tp>&);
192 template<class _Dom>
193 valarray<_Tp>& operator%= (const _Expr<_Dom,_Tp>&);
194 template<class _Dom>
195 valarray<_Tp>& operator+= (const _Expr<_Dom,_Tp>&);
196 template<class _Dom>
197 valarray<_Tp>& operator-= (const _Expr<_Dom,_Tp>&);
198 template<class _Dom>
199 valarray<_Tp>& operator^= (const _Expr<_Dom,_Tp>&);
200 template<class _Dom>
201 valarray<_Tp>& operator|= (const _Expr<_Dom,_Tp>&);
202 template<class _Dom>
203 valarray<_Tp>& operator&= (const _Expr<_Dom,_Tp>&);
204 template<class _Dom>
205 valarray<_Tp>& operator<<=(const _Expr<_Dom,_Tp>&);
206 template<class _Dom>
207 valarray<_Tp>& operator>>=(const _Expr<_Dom,_Tp>&);
210 // _lib.valarray.members_ member functions:
211 size_t size() const;
212 _Tp sum() const;
213 _Tp min() const;
214 _Tp max() const;
216 valarray<_Tp> shift (int) const;
217 valarray<_Tp> cshift(int) const;
218 _Expr<_ValFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(_Tp)) const;
219 _Expr<_RefFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(const _Tp&)) const;
220 void resize(size_t __size, _Tp __c = _Tp());
222 private:
223 size_t _M_size;
224 _Tp* __restrict__ _M_data;
226 friend class _Array<_Tp>;
230 template<typename _Tp> struct _Unary_plus : unary_function<_Tp,_Tp> {
231 _Tp operator() (const _Tp& __t) const { return __t; }
234 template<typename _Tp> struct _Bitwise_and : binary_function<_Tp,_Tp,_Tp> {
235 _Tp operator() (_Tp __x, _Tp __y) const { return __x & __y; }
238 template<typename _Tp> struct _Bitwise_or : binary_function<_Tp,_Tp,_Tp> {
239 _Tp operator() (_Tp __x, _Tp __y) const { return __x | __y; }
242 template<typename _Tp> struct _Bitwise_xor : binary_function<_Tp,_Tp,_Tp> {
243 _Tp operator() (_Tp __x, _Tp __y) const { return __x ^ __y; }
246 template<typename _Tp> struct _Bitwise_not : unary_function<_Tp,_Tp> {
247 _Tp operator() (_Tp __t) const { return ~__t; }
250 template<typename _Tp> struct _Shift_left : unary_function<_Tp,_Tp> {
251 _Tp operator() (_Tp __x, _Tp __y) const { return __x << __y; }
254 template<typename _Tp> struct _Shift_right : unary_function<_Tp,_Tp> {
255 _Tp operator() (_Tp __x, _Tp __y) const { return __x >> __y; }
259 template<typename _Tp>
260 inline _Tp
261 valarray<_Tp>::operator[] (size_t __i) const
262 { return _M_data[__i]; }
264 template<typename _Tp>
265 inline _Tp&
266 valarray<_Tp>::operator[] (size_t __i)
267 { return _M_data[__i]; }
269 } // extern "C++"
271 #include <std/slice.h>
272 #include <std/slice_array.h>
273 #include <std/gslice.h>
274 #include <std/gslice_array.h>
275 #include <std/mask_array.h>
276 #include <std/indirect_array.h>
278 extern "C++" {
280 template<typename _Tp>
281 inline valarray<_Tp>::valarray () : _M_size (0), _M_data (0) {}
283 template<typename _Tp>
284 inline valarray<_Tp>::valarray (size_t __n)
285 : _M_size (__n), _M_data(__valarray_get_storage<_Tp>(__n))
286 { __valarray_default_construct(_M_data, _M_data + __n); }
288 template<typename _Tp>
289 inline valarray<_Tp>::valarray (const _Tp& __t, size_t __n)
290 : _M_size (__n), _M_data(__valarray_get_storage<_Tp>(__n))
291 { __valarray_fill_construct(_M_data, _M_data + __n, __t); }
293 template<typename _Tp>
294 inline valarray<_Tp>::valarray (const _Tp* __restrict__ __pT, size_t __n)
295 : _M_size (__n), _M_data(__valarray_get_storage<_Tp>(__n))
296 { __valarray_copy_construct(__pT, __pT + __n, _M_data); }
298 template<typename _Tp>
299 inline valarray<_Tp>::valarray (const valarray<_Tp>& __v)
300 : _M_size (__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size))
301 { __valarray_copy_construct (__v._M_data, __v._M_data + _M_size, _M_data); }
303 template<typename _Tp>
304 inline valarray<_Tp>::valarray (const slice_array<_Tp>& __sa)
305 : _M_size (__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz))
307 __valarray_copy_construct
308 (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
311 template<typename _Tp>
312 inline valarray<_Tp>::valarray (const gslice_array<_Tp>& __ga)
313 : _M_size (__ga._M_index.size()),
314 _M_data(__valarray_get_storage<_Tp>(_M_size))
316 __valarray_copy_construct
317 (__ga._M_array, _Array<size_t>(__ga._M_index),
318 _Array<_Tp>(_M_data), _M_size);
321 template<typename _Tp>
322 inline valarray<_Tp>::valarray (const mask_array<_Tp>& __ma)
323 : _M_size (__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz))
325 __valarray_copy_construct
326 (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);
329 template<typename _Tp>
330 inline valarray<_Tp>::valarray (const indirect_array<_Tp>& __ia)
331 : _M_size (__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_size))
333 __valarray_copy_construct
334 (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
337 template<typename _Tp> template<class _Dom>
338 inline valarray<_Tp>::valarray (const _Expr<_Dom, _Tp>& __e)
339 : _M_size (__e.size ()), _M_data (__valarray_get_storage<_Tp>(_M_size))
340 { __valarray_copy_construct (__e, _M_size, _Array<_Tp>(_M_data)); }
342 template<typename _Tp>
343 inline valarray<_Tp>::~valarray ()
345 __valarray_destroy_elements(_M_data, _M_data + _M_size);
346 __valarray_release_storage(_M_data);
349 template<typename _Tp>
350 inline valarray<_Tp>&
351 valarray<_Tp>::operator= (const valarray<_Tp>& __v)
353 __valarray_copy(__v._M_data, _M_size, _M_data);
354 return *this;
357 template<typename _Tp>
358 inline valarray<_Tp>&
359 valarray<_Tp>::operator= (const _Tp& __t)
361 __valarray_fill (_M_data, _M_size, __t);
362 return *this;
365 template<typename _Tp>
366 inline valarray<_Tp>&
367 valarray<_Tp>::operator= (const slice_array<_Tp>& __sa)
369 __valarray_copy (__sa._M_array, __sa._M_sz,
370 __sa._M_stride, _Array<_Tp>(_M_data));
371 return *this;
374 template<typename _Tp>
375 inline valarray<_Tp>&
376 valarray<_Tp>::operator= (const gslice_array<_Tp>& __ga)
378 __valarray_copy (__ga._M_array, _Array<size_t>(__ga._M_index),
379 _Array<_Tp>(_M_data), _M_size);
380 return *this;
383 template<typename _Tp>
384 inline valarray<_Tp>&
385 valarray<_Tp>::operator= (const mask_array<_Tp>& __ma)
387 __valarray_copy (__ma._M_array, __ma._M_mask,
388 _Array<_Tp>(_M_data), _M_size);
389 return *this;
392 template<typename _Tp>
393 inline valarray<_Tp>&
394 valarray<_Tp>::operator= (const indirect_array<_Tp>& __ia)
396 __valarray_copy (__ia._M_array, __ia._M_index,
397 _Array<_Tp>(_M_data), _M_size);
398 return *this;
401 template<typename _Tp> template<class _Dom>
402 inline valarray<_Tp>&
403 valarray<_Tp>::operator= (const _Expr<_Dom, _Tp>& __e)
405 __valarray_copy (__e, _M_size, _Array<_Tp>(_M_data));
406 return *this;
409 template<typename _Tp>
410 inline _Expr<_SClos<_ValArray,_Tp>, _Tp>
411 valarray<_Tp>::operator[] (slice __s) const
413 typedef _SClos<_ValArray,_Tp> _Closure;
414 return _Expr<_Closure, _Tp> (_Closure (_Array<_Tp>(_M_data), __s));
417 template<typename _Tp>
418 inline slice_array<_Tp>
419 valarray<_Tp>::operator[] (slice __s)
421 return slice_array<_Tp> (_Array<_Tp>(_M_data), __s);
424 template<typename _Tp>
425 inline _Expr<_GClos<_ValArray,_Tp>, _Tp>
426 valarray<_Tp>::operator[] (const gslice& __gs) const
428 typedef _GClos<_ValArray,_Tp> _Closure;
429 return _Expr<_Closure, _Tp>
430 (_Closure (_Array<_Tp>(_M_data), __gs._M_index->_M_index));
433 template<typename _Tp>
434 inline gslice_array<_Tp>
435 valarray<_Tp>::operator[] (const gslice& __gs)
437 return gslice_array<_Tp>
438 (_Array<_Tp>(_M_data), __gs._M_index->_M_index);
441 template<typename _Tp>
442 inline valarray<_Tp>
443 valarray<_Tp>::operator[] (const valarray<bool>& __m) const
445 size_t __s (0);
446 size_t __e (__m.size ());
447 for (size_t __i=0; __i<__e; ++__i)
448 if (__m[__i]) ++__s;
449 return valarray<_Tp> (mask_array<_Tp> (_Array<_Tp>(_M_data), __s,
450 _Array<bool> (__m)));
453 template<typename _Tp>
454 inline mask_array<_Tp>
455 valarray<_Tp>::operator[] (const valarray<bool>& __m)
457 size_t __s (0);
458 size_t __e (__m.size ());
459 for (size_t __i=0; __i<__e; ++__i)
460 if (__m[__i]) ++__s;
461 return mask_array<_Tp> (_Array<_Tp>(_M_data), __s, _Array<bool> (__m));
464 template<typename _Tp>
465 inline _Expr<_IClos<_ValArray,_Tp>, _Tp>
466 valarray<_Tp>::operator[] (const valarray<size_t>& __i) const
468 typedef _IClos<_ValArray,_Tp> _Closure;
469 return _Expr<_Closure, _Tp> (_Closure (*this, __i));
472 template<typename _Tp>
473 inline indirect_array<_Tp>
474 valarray<_Tp>::operator[] (const valarray<size_t>& __i)
476 return indirect_array<_Tp> (_Array<_Tp>(_M_data), __i.size(),
477 _Array<size_t> (__i));
480 template<class _Tp>
481 inline size_t valarray<_Tp>::size () const { return _M_size; }
483 template<class _Tp>
484 inline _Tp
485 valarray<_Tp>::sum () const
487 return __valarray_sum(_M_data, _M_data + _M_size);
490 template <class _Tp>
491 inline valarray<_Tp>
492 valarray<_Tp>::shift (int __n) const
494 _Tp* const __a = static_cast<_Tp*> (alloca (sizeof(_Tp) * _M_size));
495 if (! __n) // __n == 0: no shift
496 __valarray_copy_construct (_M_data, _M_size, __a);
497 else if (__n > 0) { // __n > 0: shift left
498 if (__n > _M_size)
499 __valarray_default_construct(__a, __a + __n);
500 else {
501 __valarray_copy_construct (_M_data+__n, _M_size-__n, __a);
502 __valarray_default_construct (__a+_M_size-__n, __a + _M_size);
505 else { // __n < 0: shift right
506 __valarray_copy_construct (_M_data, _M_data+_M_size+__n, __a-__n);
507 __valarray_default_construct(__a, __a-__n);
509 return valarray<_Tp> (__a, _M_size);
512 template <class _Tp>
513 inline valarray<_Tp>
514 valarray<_Tp>::cshift (int __n) const
516 _Tp* const __a = static_cast<_Tp*> (alloca (sizeof(_Tp) * _M_size));
517 if (__n == 0) // __n == 0: no cshift
518 __valarray_copy_construct(_M_data, _M_data + _M_size, __a);
519 else if (__n > 0) { // __n > 0: cshift left
520 __valarray_copy_construct (_M_data, _M_data + __n, __a + _M_size-__n);
521 __valarray_copy_construct (_M_data + __n, _M_data + _M_size, __a);
523 else { // __n < 0: cshift right
524 __valarray_copy_construct
525 (_M_data + _M_size + __n, _M_data + _M_size, __a);
526 __valarray_copy_construct
527 (_M_data, _M_data + _M_size + __n, __a - __n);
529 return valarray<_Tp> (__a, _M_size);
532 template <class _Tp>
533 inline void
534 valarray<_Tp>::resize (size_t __n, _Tp __c)
536 // this is so to make valarray<valarray<T> > work
537 // even though it is not required by the standard.
538 __valarray_destroy_elements(_M_data, _M_data + _M_size);
539 if (_M_size != __n) {
540 __valarray_release_storage(_M_data);
541 _M_size = __n;
542 _M_data = __valarray_get_storage<_Tp>(__n);
544 __valarray_fill_construct (_M_data, _M_data + _M_size, __c);
547 template<typename _Tp>
548 inline _Tp
549 valarray<_Tp>::min() const
551 return *min_element (_M_data, _M_data+_M_size);
554 template<typename _Tp>
555 inline _Tp
556 valarray<_Tp>::max() const
558 return *max_element (_M_data, _M_data+_M_size);
561 template<class _Tp>
562 inline _Expr<_ValFunClos<_ValArray,_Tp>,_Tp>
563 valarray<_Tp>::apply (_Tp func (_Tp)) const
565 typedef _ValFunClos<_ValArray,_Tp> _Closure;
566 return _Expr<_Closure,_Tp> (_Closure (*this, func));
569 template<class _Tp>
570 inline _Expr<_RefFunClos<_ValArray,_Tp>,_Tp>
571 valarray<_Tp>::apply (_Tp func (const _Tp &)) const
573 typedef _RefFunClos<_ValArray,_Tp> _Closure;
574 return _Expr<_Closure,_Tp> (_Closure (*this, func));
577 #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \
578 template<typename _Tp> \
579 inline _Expr<_UnClos<_Name,_ValArray,_Tp>, _Tp> \
580 valarray<_Tp>::operator _Op() const \
582 typedef _UnClos<_Name,_ValArray,_Tp> _Closure; \
583 return _Expr<_Closure, _Tp> (_Closure (*this)); \
586 _DEFINE_VALARRAY_UNARY_OPERATOR(+, _Unary_plus)
587 _DEFINE_VALARRAY_UNARY_OPERATOR(-, negate)
588 _DEFINE_VALARRAY_UNARY_OPERATOR(~, _Bitwise_not)
590 #undef _DEFINE_VALARRAY_UNARY_OPERATOR
592 template<typename _Tp>
593 inline _Expr<_UnClos<logical_not,_ValArray,_Tp>, bool>
594 valarray<_Tp>::operator!() const
596 typedef _UnClos<logical_not,_ValArray,_Tp> _Closure;
597 return _Expr<_Closure, bool> (_Closure (*this));
600 #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
601 template<class _Tp> \
602 inline valarray<_Tp> & \
603 valarray<_Tp>::operator _Op##= (const _Tp &__t) \
605 _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, __t); \
606 return *this; \
609 template<class _Tp> \
610 inline valarray<_Tp> & \
611 valarray<_Tp>::operator _Op##= (const valarray<_Tp> &__v) \
613 _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, \
614 _Array<_Tp>(__v._M_data)); \
615 return *this; \
618 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, plus)
619 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, minus)
620 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, multiplies)
621 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, divides)
622 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, modulus)
623 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, xor)
624 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, and)
625 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, or)
626 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, shift_left)
627 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, shift_right)
629 #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
632 #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
633 template<class _Tp> template<class _Dom> \
634 inline valarray<_Tp> & \
635 valarray<_Tp>::operator _Op##= (const _Expr<_Dom,_Tp> &__e) \
637 _Array_augmented_##_Name (_Array<_Tp>(_M_data), __e, _M_size); \
638 return *this; \
641 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, plus)
642 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, minus)
643 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, multiplies)
644 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, divides)
645 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, modulus)
646 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, xor)
647 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, and)
648 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, or)
649 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, shift_left)
650 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, shift_right)
652 #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
655 #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
656 template<typename _Tp> \
657 inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \
658 operator _Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
660 typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
661 return _Expr<_Closure, _Tp> (_Closure (__v, __w)); \
664 template<typename _Tp> \
665 inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,_Tp> \
666 operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \
668 typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
669 return _Expr<_Closure, _Tp> (_Closure (__v, __t)); \
672 template<typename _Tp> \
673 inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,_Tp> \
674 operator _Op (const _Tp &__t, const valarray<_Tp> &__v) \
676 typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
677 return _Expr<_Closure, _Tp> (_Closure (__t, __v)); \
680 _DEFINE_BINARY_OPERATOR(+, plus)
681 _DEFINE_BINARY_OPERATOR(-, minus)
682 _DEFINE_BINARY_OPERATOR(*, multiplies)
683 _DEFINE_BINARY_OPERATOR(/, divides)
684 _DEFINE_BINARY_OPERATOR(%, modulus)
685 _DEFINE_BINARY_OPERATOR(^, _Bitwise_xor)
686 _DEFINE_BINARY_OPERATOR(&, _Bitwise_and)
687 _DEFINE_BINARY_OPERATOR(|, _Bitwise_or)
688 _DEFINE_BINARY_OPERATOR(<<, _Shift_left)
689 _DEFINE_BINARY_OPERATOR(>>, _Shift_right)
691 #undef _DEFINE_BINARY_OPERATOR
693 #define _DEFINE_LOGICAL_OPERATOR(_Op, _Name) \
694 template<typename _Tp> \
695 inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>,bool> \
696 operator _Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
698 typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
699 return _Expr<_Closure, bool> (_Closure (__v, __w)); \
702 template<class _Tp> \
703 inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,bool> \
704 operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \
706 typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
707 return _Expr<_Closure, bool> (_Closure (__v, __t)); \
710 template<class _Tp> \
711 inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,bool> \
712 operator _Op (const _Tp &__t, const valarray<_Tp> &__v) \
714 typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
715 return _Expr<_Closure, bool> (_Closure (__t, __v)); \
718 _DEFINE_LOGICAL_OPERATOR(&&, logical_and)
719 _DEFINE_LOGICAL_OPERATOR(||, logical_or)
720 _DEFINE_LOGICAL_OPERATOR(==, equal_to)
721 _DEFINE_LOGICAL_OPERATOR(!=, not_equal_to)
722 _DEFINE_LOGICAL_OPERATOR(<, less)
723 _DEFINE_LOGICAL_OPERATOR(>, greater)
724 _DEFINE_LOGICAL_OPERATOR(<=, less_equal)
725 _DEFINE_LOGICAL_OPERATOR(>=, greater_equal)
727 #undef _DEFINE_VALARRAY_OPERATOR
729 #undef _G_NO_VALARRAY_TEMPLATE_EXPORT
731 } // extern "C++"
733 #endif // __STD_VALARRAY__
735 // Local Variables:
736 // mode:c++
737 // End: