2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / include / std / std_valarray.h
blob7dac89dadb01c144301e4bceb5dca97c85183675
1 // The template and inlines for the -*- C++ -*- valarray class.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
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.
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.
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.
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.
31 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
33 /** @file valarray
34 * This is a Standard C++ Library header. You should @c #include this header
35 * in your programs, rather than any of the "st[dl]_*.h" implementation files.
38 #ifndef _GLIBCXX_VALARRAY
39 #define _GLIBCXX_VALARRAY 1
41 #pragma GCC system_header
43 #include <bits/c++config.h>
44 #include <cstddef>
45 #include <cmath>
46 #include <cstdlib>
47 #include <numeric>
48 #include <algorithm>
49 #include <debug/debug.h>
51 namespace std
53 template<class _Clos, typename _Tp>
54 class _Expr;
56 template<typename _Tp1, typename _Tp2>
57 class _ValArray;
59 template<class _Oper, template<class, class> class _Meta, class _Dom>
60 struct _UnClos;
62 template<class _Oper,
63 template<class, class> class _Meta1,
64 template<class, class> class _Meta2,
65 class _Dom1, class _Dom2>
66 class _BinClos;
68 template<template<class, class> class _Meta, class _Dom>
69 class _SClos;
71 template<template<class, class> class _Meta, class _Dom>
72 class _GClos;
74 template<template<class, class> class _Meta, class _Dom>
75 class _IClos;
77 template<template<class, class> class _Meta, class _Dom>
78 class _ValFunClos;
80 template<template<class, class> class _Meta, class _Dom>
81 class _RefFunClos;
83 template<class _Tp> class valarray; // An array of type _Tp
84 class slice; // BLAS-like slice out of an array
85 template<class _Tp> class slice_array;
86 class gslice; // generalized slice out of an array
87 template<class _Tp> class gslice_array;
88 template<class _Tp> class mask_array; // masked array
89 template<class _Tp> class indirect_array; // indirected array
91 } // namespace std
93 #include <bits/valarray_array.h>
94 #include <bits/valarray_before.h>
96 namespace std
98 template<class _Tp>
99 class valarray
101 template<class _Op>
102 struct _UnaryOp
104 typedef typename __fun<_Op, _Tp>::result_type __rt;
105 typedef _Expr<_UnClos<_Op, _ValArray, _Tp>, __rt> _Rt;
107 public:
108 typedef _Tp value_type;
110 // _lib.valarray.cons_ construct/destroy:
111 valarray();
112 explicit valarray(size_t);
113 valarray(const _Tp&, size_t);
114 valarray(const _Tp* __restrict__, size_t);
115 valarray(const valarray&);
116 valarray(const slice_array<_Tp>&);
117 valarray(const gslice_array<_Tp>&);
118 valarray(const mask_array<_Tp>&);
119 valarray(const indirect_array<_Tp>&);
120 template<class _Dom>
121 valarray(const _Expr<_Dom,_Tp>& __e);
122 ~valarray();
124 // _lib.valarray.assign_ assignment:
125 valarray<_Tp>& operator=(const valarray<_Tp>&);
126 valarray<_Tp>& operator=(const _Tp&);
127 valarray<_Tp>& operator=(const slice_array<_Tp>&);
128 valarray<_Tp>& operator=(const gslice_array<_Tp>&);
129 valarray<_Tp>& operator=(const mask_array<_Tp>&);
130 valarray<_Tp>& operator=(const indirect_array<_Tp>&);
132 template<class _Dom> valarray<_Tp>&
133 operator= (const _Expr<_Dom,_Tp>&);
135 // _lib.valarray.access_ element access:
136 // XXX: LWG to be resolved.
137 const _Tp& operator[](size_t) const;
138 _Tp& operator[](size_t);
139 // _lib.valarray.sub_ subset operations:
140 _Expr<_SClos<_ValArray,_Tp>, _Tp> operator[](slice) const;
141 slice_array<_Tp> operator[](slice);
142 _Expr<_GClos<_ValArray,_Tp>, _Tp> operator[](const gslice&) const;
143 gslice_array<_Tp> operator[](const gslice&);
144 valarray<_Tp> operator[](const valarray<bool>&) const;
145 mask_array<_Tp> operator[](const valarray<bool>&);
146 _Expr<_IClos<_ValArray, _Tp>, _Tp>
147 operator[](const valarray<size_t>&) const;
148 indirect_array<_Tp> operator[](const valarray<size_t>&);
150 // _lib.valarray.unary_ unary operators:
151 typename _UnaryOp<__unary_plus>::_Rt operator+() const;
152 typename _UnaryOp<__negate>::_Rt operator-() const;
153 typename _UnaryOp<__bitwise_not>::_Rt operator~() const;
154 typename _UnaryOp<__logical_not>::_Rt operator!() const;
156 // _lib.valarray.cassign_ computed assignment:
157 valarray<_Tp>& operator*=(const _Tp&);
158 valarray<_Tp>& operator/=(const _Tp&);
159 valarray<_Tp>& operator%=(const _Tp&);
160 valarray<_Tp>& operator+=(const _Tp&);
161 valarray<_Tp>& operator-=(const _Tp&);
162 valarray<_Tp>& operator^=(const _Tp&);
163 valarray<_Tp>& operator&=(const _Tp&);
164 valarray<_Tp>& operator|=(const _Tp&);
165 valarray<_Tp>& operator<<=(const _Tp&);
166 valarray<_Tp>& operator>>=(const _Tp&);
167 valarray<_Tp>& operator*=(const valarray<_Tp>&);
168 valarray<_Tp>& operator/=(const valarray<_Tp>&);
169 valarray<_Tp>& operator%=(const valarray<_Tp>&);
170 valarray<_Tp>& operator+=(const valarray<_Tp>&);
171 valarray<_Tp>& operator-=(const valarray<_Tp>&);
172 valarray<_Tp>& operator^=(const valarray<_Tp>&);
173 valarray<_Tp>& operator|=(const valarray<_Tp>&);
174 valarray<_Tp>& operator&=(const valarray<_Tp>&);
175 valarray<_Tp>& operator<<=(const valarray<_Tp>&);
176 valarray<_Tp>& operator>>=(const valarray<_Tp>&);
178 template<class _Dom>
179 valarray<_Tp>& operator*=(const _Expr<_Dom,_Tp>&);
180 template<class _Dom>
181 valarray<_Tp>& operator/=(const _Expr<_Dom,_Tp>&);
182 template<class _Dom>
183 valarray<_Tp>& operator%=(const _Expr<_Dom,_Tp>&);
184 template<class _Dom>
185 valarray<_Tp>& operator+=(const _Expr<_Dom,_Tp>&);
186 template<class _Dom>
187 valarray<_Tp>& operator-=(const _Expr<_Dom,_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>&);
200 // _lib.valarray.members_ member functions:
201 size_t size() const;
202 _Tp sum() const;
203 _Tp min() const;
204 _Tp max() const;
206 // // FIXME: Extension
207 // _Tp product () const;
209 valarray<_Tp> shift (int) const;
210 valarray<_Tp> cshift(int) const;
211 _Expr<_ValFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(_Tp)) const;
212 _Expr<_RefFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(const _Tp&)) const;
213 void resize(size_t __size, _Tp __c = _Tp());
215 private:
216 size_t _M_size;
217 _Tp* __restrict__ _M_data;
219 friend class _Array<_Tp>;
222 template<typename _Tp>
223 inline const _Tp&
224 valarray<_Tp>::operator[](size_t __i) const
226 __glibcxx_requires_subscript(__i);
227 return _M_data[__i];
230 template<typename _Tp>
231 inline _Tp&
232 valarray<_Tp>::operator[](size_t __i)
234 __glibcxx_requires_subscript(__i);
235 return _M_data[__i];
238 } // std::
240 #include <bits/valarray_after.h>
242 #include <bits/slice_array.h>
243 #include <bits/gslice.h>
244 #include <bits/gslice_array.h>
245 #include <bits/mask_array.h>
246 #include <bits/indirect_array.h>
248 namespace std
250 template<typename _Tp>
251 inline
252 valarray<_Tp>::valarray() : _M_size(0), _M_data(0) {}
254 template<typename _Tp>
255 inline
256 valarray<_Tp>::valarray(size_t __n)
257 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
258 { std::__valarray_default_construct(_M_data, _M_data + __n); }
260 template<typename _Tp>
261 inline
262 valarray<_Tp>::valarray(const _Tp& __t, size_t __n)
263 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
264 { std::__valarray_fill_construct(_M_data, _M_data + __n, __t); }
266 template<typename _Tp>
267 inline
268 valarray<_Tp>::valarray(const _Tp* __restrict__ __p, size_t __n)
269 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
271 _GLIBCXX_DEBUG_ASSERT(__p != 0 || __n == 0);
272 std::__valarray_copy_construct(__p, __p + __n, _M_data);
275 template<typename _Tp>
276 inline
277 valarray<_Tp>::valarray(const valarray<_Tp>& __v)
278 : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size))
279 { std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size, _M_data); }
281 template<typename _Tp>
282 inline
283 valarray<_Tp>::valarray(const slice_array<_Tp>& __sa)
284 : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz))
286 std::__valarray_copy
287 (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
290 template<typename _Tp>
291 inline
292 valarray<_Tp>::valarray(const gslice_array<_Tp>& __ga)
293 : _M_size(__ga._M_index.size()),
294 _M_data(__valarray_get_storage<_Tp>(_M_size))
296 std::__valarray_copy
297 (__ga._M_array, _Array<size_t>(__ga._M_index),
298 _Array<_Tp>(_M_data), _M_size);
301 template<typename _Tp>
302 inline
303 valarray<_Tp>::valarray(const mask_array<_Tp>& __ma)
304 : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz))
306 std::__valarray_copy
307 (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);
310 template<typename _Tp>
311 inline
312 valarray<_Tp>::valarray(const indirect_array<_Tp>& __ia)
313 : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz))
315 std::__valarray_copy
316 (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
319 template<typename _Tp> template<class _Dom>
320 inline
321 valarray<_Tp>::valarray(const _Expr<_Dom, _Tp>& __e)
322 : _M_size(__e.size()), _M_data(__valarray_get_storage<_Tp>(_M_size))
323 { std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data)); }
325 template<typename _Tp>
326 inline
327 valarray<_Tp>::~valarray()
329 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
330 std::__valarray_release_memory(_M_data);
333 template<typename _Tp>
334 inline valarray<_Tp>&
335 valarray<_Tp>::operator=(const valarray<_Tp>& __v)
337 _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size);
338 std::__valarray_copy(__v._M_data, _M_size, _M_data);
339 return *this;
342 template<typename _Tp>
343 inline valarray<_Tp>&
344 valarray<_Tp>::operator=(const _Tp& __t)
346 std::__valarray_fill(_M_data, _M_size, __t);
347 return *this;
350 template<typename _Tp>
351 inline valarray<_Tp>&
352 valarray<_Tp>::operator=(const slice_array<_Tp>& __sa)
354 _GLIBCXX_DEBUG_ASSERT(_M_size == __sa._M_sz);
355 std::__valarray_copy(__sa._M_array, __sa._M_sz,
356 __sa._M_stride, _Array<_Tp>(_M_data));
357 return *this;
360 template<typename _Tp>
361 inline valarray<_Tp>&
362 valarray<_Tp>::operator=(const gslice_array<_Tp>& __ga)
364 _GLIBCXX_DEBUG_ASSERT(_M_size == __ga._M_index.size());
365 std::__valarray_copy(__ga._M_array, _Array<size_t>(__ga._M_index),
366 _Array<_Tp>(_M_data), _M_size);
367 return *this;
370 template<typename _Tp>
371 inline valarray<_Tp>&
372 valarray<_Tp>::operator=(const mask_array<_Tp>& __ma)
374 _GLIBCXX_DEBUG_ASSERT(_M_size == __ma._M_sz);
375 std::__valarray_copy(__ma._M_array, __ma._M_mask,
376 _Array<_Tp>(_M_data), _M_size);
377 return *this;
380 template<typename _Tp>
381 inline valarray<_Tp>&
382 valarray<_Tp>::operator=(const indirect_array<_Tp>& __ia)
384 _GLIBCXX_DEBUG_ASSERT(_M_size == __ia._M_sz);
385 std::__valarray_copy(__ia._M_array, __ia._M_index,
386 _Array<_Tp>(_M_data), _M_size);
387 return *this;
390 template<typename _Tp> template<class _Dom>
391 inline valarray<_Tp>&
392 valarray<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e)
394 _GLIBCXX_DEBUG_ASSERT(_M_size == __e.size());
395 std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data));
396 return *this;
399 template<typename _Tp>
400 inline _Expr<_SClos<_ValArray,_Tp>, _Tp>
401 valarray<_Tp>::operator[](slice __s) const
403 typedef _SClos<_ValArray,_Tp> _Closure;
404 return _Expr<_Closure, _Tp>(_Closure (_Array<_Tp>(_M_data), __s));
407 template<typename _Tp>
408 inline slice_array<_Tp>
409 valarray<_Tp>::operator[](slice __s)
411 return slice_array<_Tp>(_Array<_Tp>(_M_data), __s);
414 template<typename _Tp>
415 inline _Expr<_GClos<_ValArray,_Tp>, _Tp>
416 valarray<_Tp>::operator[](const gslice& __gs) const
418 typedef _GClos<_ValArray,_Tp> _Closure;
419 return _Expr<_Closure, _Tp>
420 (_Closure(_Array<_Tp>(_M_data), __gs._M_index->_M_index));
423 template<typename _Tp>
424 inline gslice_array<_Tp>
425 valarray<_Tp>::operator[](const gslice& __gs)
427 return gslice_array<_Tp>
428 (_Array<_Tp>(_M_data), __gs._M_index->_M_index);
431 template<typename _Tp>
432 inline valarray<_Tp>
433 valarray<_Tp>::operator[](const valarray<bool>& __m) const
435 size_t __s = 0;
436 size_t __e = __m.size();
437 for (size_t __i=0; __i<__e; ++__i)
438 if (__m[__i]) ++__s;
439 return valarray<_Tp>(mask_array<_Tp>(_Array<_Tp>(_M_data), __s,
440 _Array<bool> (__m)));
443 template<typename _Tp>
444 inline mask_array<_Tp>
445 valarray<_Tp>::operator[](const valarray<bool>& __m)
447 size_t __s = 0;
448 size_t __e = __m.size();
449 for (size_t __i=0; __i<__e; ++__i)
450 if (__m[__i]) ++__s;
451 return mask_array<_Tp>(_Array<_Tp>(_M_data), __s, _Array<bool>(__m));
454 template<typename _Tp>
455 inline _Expr<_IClos<_ValArray,_Tp>, _Tp>
456 valarray<_Tp>::operator[](const valarray<size_t>& __i) const
458 typedef _IClos<_ValArray,_Tp> _Closure;
459 return _Expr<_Closure, _Tp>(_Closure(*this, __i));
462 template<typename _Tp>
463 inline indirect_array<_Tp>
464 valarray<_Tp>::operator[](const valarray<size_t>& __i)
466 return indirect_array<_Tp>(_Array<_Tp>(_M_data), __i.size(),
467 _Array<size_t>(__i));
470 template<class _Tp>
471 inline size_t
472 valarray<_Tp>::size() const
473 { return _M_size; }
475 template<class _Tp>
476 inline _Tp
477 valarray<_Tp>::sum() const
479 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
480 return std::__valarray_sum(_M_data, _M_data + _M_size);
483 // template<typename _Tp>
484 // inline _Tp
485 // valarray<_Tp>::product () const
486 // {
487 // return __valarray_product(_M_data, _M_data + _M_size);
488 // }
490 template <class _Tp>
491 inline valarray<_Tp>
492 valarray<_Tp>::shift(int __n) const
494 _Tp* const __a = static_cast<_Tp*>
495 (__builtin_alloca(sizeof(_Tp) * _M_size));
496 if (__n == 0) // no shift
497 std::__valarray_copy_construct(_M_data, _M_data + _M_size, __a);
498 else if (__n > 0) // __n > 0: shift left
500 if (size_t(__n) > _M_size)
501 std::__valarray_default_construct(__a, __a + __n);
502 else
504 std::__valarray_copy_construct(_M_data+__n, _M_data + _M_size, __a);
505 std::__valarray_default_construct(__a+_M_size-__n, __a + _M_size);
508 else // __n < 0: shift right
510 std::__valarray_copy_construct (_M_data, _M_data+_M_size+__n, __a-__n);
511 std::__valarray_default_construct(__a, __a - __n);
513 return valarray<_Tp> (__a, _M_size);
516 template <class _Tp>
517 inline valarray<_Tp>
518 valarray<_Tp>::cshift (int __n) const
520 _Tp* const __a = static_cast<_Tp*>
521 (__builtin_alloca (sizeof(_Tp) * _M_size));
522 if (__n == 0) // no cshift
523 std::__valarray_copy_construct(_M_data, _M_data + _M_size, __a);
524 else if (__n > 0) // cshift left
526 std::__valarray_copy_construct(_M_data, _M_data+__n, __a+_M_size-__n);
527 std::__valarray_copy_construct(_M_data+__n, _M_data + _M_size, __a);
529 else // cshift right
531 std::__valarray_copy_construct
532 (_M_data + _M_size+__n, _M_data + _M_size, __a);
533 std::__valarray_copy_construct
534 (_M_data, _M_data + _M_size+__n, __a - __n);
536 return valarray<_Tp>(__a, _M_size);
539 template <class _Tp>
540 inline void
541 valarray<_Tp>::resize (size_t __n, _Tp __c)
543 // This complication is so to make valarray<valarray<T> > work
544 // even though it is not required by the standard. Nobody should
545 // be saying valarray<valarray<T> > anyway. See the specs.
546 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
547 if (_M_size != __n)
549 std::__valarray_release_memory(_M_data);
550 _M_size = __n;
551 _M_data = __valarray_get_storage<_Tp>(__n);
553 std::__valarray_fill_construct(_M_data, _M_data + __n, __c);
556 template<typename _Tp>
557 inline _Tp
558 valarray<_Tp>::min() const
560 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
561 return *std::min_element (_M_data, _M_data+_M_size);
564 template<typename _Tp>
565 inline _Tp
566 valarray<_Tp>::max() const
568 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
569 return *std::max_element (_M_data, _M_data+_M_size);
572 template<class _Tp>
573 inline _Expr<_ValFunClos<_ValArray,_Tp>,_Tp>
574 valarray<_Tp>::apply(_Tp func(_Tp)) const
576 typedef _ValFunClos<_ValArray,_Tp> _Closure;
577 return _Expr<_Closure,_Tp>(_Closure(*this, func));
580 template<class _Tp>
581 inline _Expr<_RefFunClos<_ValArray,_Tp>,_Tp>
582 valarray<_Tp>::apply(_Tp func(const _Tp &)) const
584 typedef _RefFunClos<_ValArray,_Tp> _Closure;
585 return _Expr<_Closure,_Tp>(_Closure(*this, func));
588 #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \
589 template<typename _Tp> \
590 inline typename valarray<_Tp>::template _UnaryOp<_Name>::_Rt \
591 valarray<_Tp>::operator _Op() const \
593 typedef _UnClos<_Name,_ValArray,_Tp> _Closure; \
594 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
595 return _Expr<_Closure, _Rt>(_Closure(*this)); \
598 _DEFINE_VALARRAY_UNARY_OPERATOR(+, __unary_plus)
599 _DEFINE_VALARRAY_UNARY_OPERATOR(-, __negate)
600 _DEFINE_VALARRAY_UNARY_OPERATOR(~, __bitwise_not)
601 _DEFINE_VALARRAY_UNARY_OPERATOR (!, __logical_not)
603 #undef _DEFINE_VALARRAY_UNARY_OPERATOR
605 #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
606 template<class _Tp> \
607 inline valarray<_Tp>& \
608 valarray<_Tp>::operator _Op##=(const _Tp &__t) \
610 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, __t); \
611 return *this; \
614 template<class _Tp> \
615 inline valarray<_Tp>& \
616 valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v) \
618 _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size); \
619 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, \
620 _Array<_Tp>(__v._M_data)); \
621 return *this; \
624 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, __plus)
625 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, __minus)
626 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, __multiplies)
627 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, __divides)
628 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, __modulus)
629 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
630 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
631 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
632 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, __shift_left)
633 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, __shift_right)
635 #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
637 #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
638 template<class _Tp> template<class _Dom> \
639 inline valarray<_Tp>& \
640 valarray<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) \
642 _Array_augmented_##_Name(_Array<_Tp>(_M_data), __e, _M_size); \
643 return *this; \
646 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, __plus)
647 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, __minus)
648 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, __multiplies)
649 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, __divides)
650 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, __modulus)
651 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
652 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
653 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
654 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left)
655 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right)
657 #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
660 #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
661 template<typename _Tp> \
662 inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, \
663 typename __fun<_Name, _Tp>::result_type> \
664 operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
666 _GLIBCXX_DEBUG_ASSERT(__v.size() == __w.size()); \
667 typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
668 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
669 return _Expr<_Closure, _Rt>(_Closure(__v, __w)); \
672 template<typename _Tp> \
673 inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>, \
674 typename __fun<_Name, _Tp>::result_type> \
675 operator _Op(const valarray<_Tp>& __v, const _Tp& __t) \
677 typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
678 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
679 return _Expr<_Closure, _Rt>(_Closure(__v, __t)); \
682 template<typename _Tp> \
683 inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>, \
684 typename __fun<_Name, _Tp>::result_type> \
685 operator _Op(const _Tp& __t, const valarray<_Tp>& __v) \
687 typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
688 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
689 return _Expr<_Closure, _Tp>(_Closure(__t, __v)); \
692 _DEFINE_BINARY_OPERATOR(+, __plus)
693 _DEFINE_BINARY_OPERATOR(-, __minus)
694 _DEFINE_BINARY_OPERATOR(*, __multiplies)
695 _DEFINE_BINARY_OPERATOR(/, __divides)
696 _DEFINE_BINARY_OPERATOR(%, __modulus)
697 _DEFINE_BINARY_OPERATOR(^, __bitwise_xor)
698 _DEFINE_BINARY_OPERATOR(&, __bitwise_and)
699 _DEFINE_BINARY_OPERATOR(|, __bitwise_or)
700 _DEFINE_BINARY_OPERATOR(<<, __shift_left)
701 _DEFINE_BINARY_OPERATOR(>>, __shift_right)
702 _DEFINE_BINARY_OPERATOR(&&, __logical_and)
703 _DEFINE_BINARY_OPERATOR(||, __logical_or)
704 _DEFINE_BINARY_OPERATOR(==, __equal_to)
705 _DEFINE_BINARY_OPERATOR(!=, __not_equal_to)
706 _DEFINE_BINARY_OPERATOR(<, __less)
707 _DEFINE_BINARY_OPERATOR(>, __greater)
708 _DEFINE_BINARY_OPERATOR(<=, __less_equal)
709 _DEFINE_BINARY_OPERATOR(>=, __greater_equal)
711 } // namespace std
713 #endif /* _GLIBCXX_VALARRAY */