1 // The template and inlines for the -*- C++ -*- valarray class.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
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)
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,
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>
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.
39 #define _CPP_VALARRAY 1
41 #pragma GCC system_header
43 #include <bits/c++config.h>
53 template<class _Clos, typename _Tp> class _Expr;
55 template<typename _Tp1, typename _Tp2> class _ValArray;
57 template<template<class> class _Oper,
58 template<class, class> class _Meta, class _Dom> struct _UnClos;
60 template<template<class> class _Oper,
61 template<class, class> class _Meta1,
62 template<class, class> class _Meta2,
63 class _Dom1, class _Dom2> class _BinClos;
65 template<template<class, class> class _Meta, class _Dom> class _SClos;
67 template<template<class, class> class _Meta, class _Dom> class _GClos;
69 template<template<class, class> class _Meta, class _Dom> class _IClos;
71 template<template<class, class> class _Meta, class _Dom> class _ValFunClos;
73 template<template<class, class> class _Meta, class _Dom> class _RefFunClos;
75 template<class _Tp> struct _Unary_plus;
76 template<class _Tp> struct _Bitwise_and;
77 template<class _Tp> struct _Bitwise_or;
78 template<class _Tp> struct _Bitwise_xor;
79 template<class _Tp> struct _Bitwise_not;
80 template<class _Tp> struct _Shift_left;
81 template<class _Tp> struct _Shift_right;
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
93 #include <bits/valarray_array.h>
94 #include <bits/valarray_meta.h>
98 template<class _Tp> class valarray
101 typedef _Tp value_type;
103 // _lib.valarray.cons_ construct/destroy:
105 explicit valarray(size_t);
106 valarray(const _Tp&, size_t);
107 valarray(const _Tp* __restrict__, size_t);
108 valarray(const valarray&);
109 valarray(const slice_array<_Tp>&);
110 valarray(const gslice_array<_Tp>&);
111 valarray(const mask_array<_Tp>&);
112 valarray(const indirect_array<_Tp>&);
114 valarray(const _Expr<_Dom,_Tp>& __e);
117 // _lib.valarray.assign_ assignment:
118 valarray<_Tp>& operator=(const valarray<_Tp>&);
119 valarray<_Tp>& operator=(const _Tp&);
120 valarray<_Tp>& operator=(const slice_array<_Tp>&);
121 valarray<_Tp>& operator=(const gslice_array<_Tp>&);
122 valarray<_Tp>& operator=(const mask_array<_Tp>&);
123 valarray<_Tp>& operator=(const indirect_array<_Tp>&);
125 template<class _Dom> valarray<_Tp>&
126 operator= (const _Expr<_Dom,_Tp>&);
128 // _lib.valarray.access_ element access:
129 // XXX: LWG to be resolved.
130 const _Tp& operator[](size_t) const;
131 _Tp& operator[](size_t);
132 // _lib.valarray.sub_ subset operations:
133 _Expr<_SClos<_ValArray,_Tp>, _Tp> operator[](slice) const;
134 slice_array<_Tp> operator[](slice);
135 _Expr<_GClos<_ValArray,_Tp>, _Tp> operator[](const gslice&) const;
136 gslice_array<_Tp> operator[](const gslice&);
137 valarray<_Tp> operator[](const valarray<bool>&) const;
138 mask_array<_Tp> operator[](const valarray<bool>&);
139 _Expr<_IClos<_ValArray, _Tp>, _Tp>
140 operator[](const valarray<size_t>&) const;
141 indirect_array<_Tp> operator[](const valarray<size_t>&);
143 // _lib.valarray.unary_ unary operators:
144 _Expr<_UnClos<_Unary_plus,_ValArray,_Tp>,_Tp> operator+ () const;
145 _Expr<_UnClos<negate,_ValArray,_Tp>,_Tp> operator- () const;
146 _Expr<_UnClos<_Bitwise_not,_ValArray,_Tp>,_Tp> operator~ () const;
147 _Expr<_UnClos<logical_not,_ValArray,_Tp>,bool> operator! () const;
149 // _lib.valarray.cassign_ computed assignment:
150 valarray<_Tp>& operator*= (const _Tp&);
151 valarray<_Tp>& operator/= (const _Tp&);
152 valarray<_Tp>& operator%= (const _Tp&);
153 valarray<_Tp>& operator+= (const _Tp&);
154 valarray<_Tp>& operator-= (const _Tp&);
155 valarray<_Tp>& operator^= (const _Tp&);
156 valarray<_Tp>& operator&= (const _Tp&);
157 valarray<_Tp>& operator|= (const _Tp&);
158 valarray<_Tp>& operator<<=(const _Tp&);
159 valarray<_Tp>& operator>>=(const _Tp&);
160 valarray<_Tp>& operator*= (const valarray<_Tp>&);
161 valarray<_Tp>& operator/= (const valarray<_Tp>&);
162 valarray<_Tp>& operator%= (const valarray<_Tp>&);
163 valarray<_Tp>& operator+= (const valarray<_Tp>&);
164 valarray<_Tp>& operator-= (const valarray<_Tp>&);
165 valarray<_Tp>& operator^= (const valarray<_Tp>&);
166 valarray<_Tp>& operator|= (const valarray<_Tp>&);
167 valarray<_Tp>& operator&= (const valarray<_Tp>&);
168 valarray<_Tp>& operator<<=(const valarray<_Tp>&);
169 valarray<_Tp>& operator>>=(const valarray<_Tp>&);
172 valarray<_Tp>& operator*= (const _Expr<_Dom,_Tp>&);
174 valarray<_Tp>& operator/= (const _Expr<_Dom,_Tp>&);
176 valarray<_Tp>& operator%= (const _Expr<_Dom,_Tp>&);
178 valarray<_Tp>& operator+= (const _Expr<_Dom,_Tp>&);
180 valarray<_Tp>& operator-= (const _Expr<_Dom,_Tp>&);
182 valarray<_Tp>& operator^= (const _Expr<_Dom,_Tp>&);
184 valarray<_Tp>& operator|= (const _Expr<_Dom,_Tp>&);
186 valarray<_Tp>& operator&= (const _Expr<_Dom,_Tp>&);
188 valarray<_Tp>& operator<<=(const _Expr<_Dom,_Tp>&);
190 valarray<_Tp>& operator>>=(const _Expr<_Dom,_Tp>&);
193 // _lib.valarray.members_ member functions:
199 // // FIXME: Extension
200 // _Tp product () const;
202 valarray<_Tp> shift (int) const;
203 valarray<_Tp> cshift(int) const;
204 _Expr<_ValFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(_Tp)) const;
205 _Expr<_RefFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(const _Tp&)) const;
206 void resize(size_t __size, _Tp __c = _Tp());
210 _Tp* __restrict__ _M_data;
212 friend class _Array<_Tp>;
216 template<typename _Tp> struct _Unary_plus : unary_function<_Tp,_Tp> {
217 _Tp operator() (const _Tp& __t) const { return __t; }
220 template<typename _Tp> struct _Bitwise_and : binary_function<_Tp,_Tp,_Tp> {
221 _Tp operator() (_Tp __x, _Tp __y) const { return __x & __y; }
224 template<typename _Tp> struct _Bitwise_or : binary_function<_Tp,_Tp,_Tp> {
225 _Tp operator() (_Tp __x, _Tp __y) const { return __x | __y; }
228 template<typename _Tp> struct _Bitwise_xor : binary_function<_Tp,_Tp,_Tp> {
229 _Tp operator() (_Tp __x, _Tp __y) const { return __x ^ __y; }
232 template<typename _Tp> struct _Bitwise_not : unary_function<_Tp,_Tp> {
233 _Tp operator() (_Tp __t) const { return ~__t; }
236 template<typename _Tp> struct _Shift_left : unary_function<_Tp,_Tp> {
237 _Tp operator() (_Tp __x, _Tp __y) const { return __x << __y; }
240 template<typename _Tp> struct _Shift_right : unary_function<_Tp,_Tp> {
241 _Tp operator() (_Tp __x, _Tp __y) const { return __x >> __y; }
245 template<typename _Tp>
247 valarray<_Tp>::operator[] (size_t __i) const
248 { return _M_data[__i]; }
250 template<typename _Tp>
252 valarray<_Tp>::operator[] (size_t __i)
253 { return _M_data[__i]; }
257 #include <bits/slice_array.h>
258 #include <bits/gslice.h>
259 #include <bits/gslice_array.h>
260 #include <bits/mask_array.h>
261 #include <bits/indirect_array.h>
265 template<typename _Tp>
266 inline valarray<_Tp>::valarray () : _M_size (0), _M_data (0) {}
268 template<typename _Tp>
269 inline valarray<_Tp>::valarray (size_t __n)
270 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
271 { __valarray_default_construct(_M_data, _M_data + __n); }
273 template<typename _Tp>
274 inline valarray<_Tp>::valarray (const _Tp& __t, size_t __n)
275 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
276 { __valarray_fill_construct (_M_data, _M_data + __n, __t); }
278 template<typename _Tp>
279 inline valarray<_Tp>::valarray (const _Tp* __restrict__ __p, size_t __n)
280 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
281 { __valarray_copy_construct (__p, __p + __n, _M_data); }
283 template<typename _Tp>
284 inline valarray<_Tp>::valarray (const valarray<_Tp>& __v)
285 : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size))
286 { __valarray_copy_construct (__v._M_data, __v._M_data + _M_size, _M_data); }
288 template<typename _Tp>
289 inline valarray<_Tp>::valarray (const slice_array<_Tp>& __sa)
290 : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz))
293 (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
296 template<typename _Tp>
297 inline valarray<_Tp>::valarray (const gslice_array<_Tp>& __ga)
298 : _M_size(__ga._M_index.size()),
299 _M_data(__valarray_get_storage<_Tp>(_M_size))
302 (__ga._M_array, _Array<size_t>(__ga._M_index),
303 _Array<_Tp>(_M_data), _M_size);
306 template<typename _Tp>
307 inline valarray<_Tp>::valarray (const mask_array<_Tp>& __ma)
308 : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz))
311 (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);
314 template<typename _Tp>
315 inline valarray<_Tp>::valarray (const indirect_array<_Tp>& __ia)
316 : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz))
319 (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
322 template<typename _Tp> template<class _Dom>
323 inline valarray<_Tp>::valarray (const _Expr<_Dom, _Tp>& __e)
324 : _M_size(__e.size ()), _M_data(__valarray_get_storage<_Tp>(_M_size))
325 { __valarray_copy (__e, _M_size, _Array<_Tp>(_M_data)); }
327 template<typename _Tp>
328 inline valarray<_Tp>::~valarray ()
330 __valarray_destroy_elements(_M_data, _M_data + _M_size);
331 __valarray_release_memory(_M_data);
334 template<typename _Tp>
335 inline valarray<_Tp>&
336 valarray<_Tp>::operator= (const valarray<_Tp>& __v)
338 __valarray_copy(__v._M_data, _M_size, _M_data);
342 template<typename _Tp>
343 inline valarray<_Tp>&
344 valarray<_Tp>::operator= (const _Tp& __t)
346 __valarray_fill (_M_data, _M_size, __t);
350 template<typename _Tp>
351 inline valarray<_Tp>&
352 valarray<_Tp>::operator= (const slice_array<_Tp>& __sa)
354 __valarray_copy (__sa._M_array, __sa._M_sz,
355 __sa._M_stride, _Array<_Tp>(_M_data));
359 template<typename _Tp>
360 inline valarray<_Tp>&
361 valarray<_Tp>::operator= (const gslice_array<_Tp>& __ga)
363 __valarray_copy (__ga._M_array, _Array<size_t>(__ga._M_index),
364 _Array<_Tp>(_M_data), _M_size);
368 template<typename _Tp>
369 inline valarray<_Tp>&
370 valarray<_Tp>::operator= (const mask_array<_Tp>& __ma)
372 __valarray_copy (__ma._M_array, __ma._M_mask,
373 _Array<_Tp>(_M_data), _M_size);
377 template<typename _Tp>
378 inline valarray<_Tp>&
379 valarray<_Tp>::operator= (const indirect_array<_Tp>& __ia)
381 __valarray_copy (__ia._M_array, __ia._M_index,
382 _Array<_Tp>(_M_data), _M_size);
386 template<typename _Tp> template<class _Dom>
387 inline valarray<_Tp>&
388 valarray<_Tp>::operator= (const _Expr<_Dom, _Tp>& __e)
390 __valarray_copy (__e, _M_size, _Array<_Tp>(_M_data));
394 template<typename _Tp>
395 inline _Expr<_SClos<_ValArray,_Tp>, _Tp>
396 valarray<_Tp>::operator[] (slice __s) const
398 typedef _SClos<_ValArray,_Tp> _Closure;
399 return _Expr<_Closure, _Tp> (_Closure (_Array<_Tp>(_M_data), __s));
402 template<typename _Tp>
403 inline slice_array<_Tp>
404 valarray<_Tp>::operator[] (slice __s)
406 return slice_array<_Tp> (_Array<_Tp>(_M_data), __s);
409 template<typename _Tp>
410 inline _Expr<_GClos<_ValArray,_Tp>, _Tp>
411 valarray<_Tp>::operator[] (const gslice& __gs) const
413 typedef _GClos<_ValArray,_Tp> _Closure;
414 return _Expr<_Closure, _Tp>
415 (_Closure (_Array<_Tp>(_M_data), __gs._M_index->_M_index));
418 template<typename _Tp>
419 inline gslice_array<_Tp>
420 valarray<_Tp>::operator[] (const gslice& __gs)
422 return gslice_array<_Tp>
423 (_Array<_Tp>(_M_data), __gs._M_index->_M_index);
426 template<typename _Tp>
428 valarray<_Tp>::operator[] (const valarray<bool>& __m) const
431 size_t __e (__m.size ());
432 for (size_t __i=0; __i<__e; ++__i)
434 return valarray<_Tp> (mask_array<_Tp> (_Array<_Tp>(_M_data), __s,
435 _Array<bool> (__m)));
438 template<typename _Tp>
439 inline mask_array<_Tp>
440 valarray<_Tp>::operator[] (const valarray<bool>& __m)
443 size_t __e (__m.size ());
444 for (size_t __i=0; __i<__e; ++__i)
446 return mask_array<_Tp> (_Array<_Tp>(_M_data), __s, _Array<bool> (__m));
449 template<typename _Tp>
450 inline _Expr<_IClos<_ValArray,_Tp>, _Tp>
451 valarray<_Tp>::operator[] (const valarray<size_t>& __i) const
453 typedef _IClos<_ValArray,_Tp> _Closure;
454 return _Expr<_Closure, _Tp> (_Closure (*this, __i));
457 template<typename _Tp>
458 inline indirect_array<_Tp>
459 valarray<_Tp>::operator[] (const valarray<size_t>& __i)
461 return indirect_array<_Tp> (_Array<_Tp>(_M_data), __i.size(),
462 _Array<size_t> (__i));
466 inline size_t valarray<_Tp>::size () const { return _M_size; }
470 valarray<_Tp>::sum () const
472 return __valarray_sum(_M_data, _M_data + _M_size);
475 // template<typename _Tp>
477 // valarray<_Tp>::product () const
479 // return __valarray_product(_M_data, _M_data + _M_size);
484 valarray<_Tp>::shift(int __n) const
486 _Tp* const __a = static_cast<_Tp*>
487 (__builtin_alloca(sizeof(_Tp) * _M_size));
488 if (__n == 0) // no shift
489 __valarray_copy_construct(_M_data, _M_data + _M_size, __a);
490 else if (__n > 0) // __n > 0: shift left
492 if (size_t(__n) > _M_size)
493 __valarray_default_construct(__a, __a + __n);
496 __valarray_copy_construct(_M_data+__n, _M_data + _M_size, __a);
497 __valarray_default_construct(__a+_M_size-__n, __a + _M_size);
500 else // __n < 0: shift right
502 __valarray_copy_construct (_M_data, _M_data+_M_size+__n, __a-__n);
503 __valarray_default_construct(__a, __a - __n);
505 return valarray<_Tp> (__a, _M_size);
510 valarray<_Tp>::cshift (int __n) const
512 _Tp* const __a = static_cast<_Tp*>
513 (__builtin_alloca (sizeof(_Tp) * _M_size));
514 if (__n == 0) // no cshift
515 __valarray_copy_construct(_M_data, _M_data + _M_size, __a);
516 else if (__n > 0) // cshift left
518 __valarray_copy_construct(_M_data, _M_data+__n, __a+_M_size-__n);
519 __valarray_copy_construct(_M_data+__n, _M_data + _M_size, __a);
523 __valarray_copy_construct
524 (_M_data + _M_size+__n, _M_data + _M_size, __a);
525 __valarray_copy_construct
526 (_M_data, _M_data + _M_size+__n, __a - __n);
528 return valarray<_Tp>(__a, _M_size);
533 valarray<_Tp>::resize (size_t __n, _Tp __c)
535 // This complication is so to make valarray<valarray<T> > work
536 // even though it is not required by the standard. Nobody should
537 // be saying valarray<valarray<T> > anyway. See the specs.
538 __valarray_destroy_elements(_M_data, _M_data + _M_size);
541 __valarray_release_memory(_M_data);
543 _M_data = __valarray_get_storage<_Tp>(__n);
545 __valarray_fill_construct(_M_data, _M_data + __n, __c);
548 template<typename _Tp>
550 valarray<_Tp>::min() const
552 return *min_element (_M_data, _M_data+_M_size);
555 template<typename _Tp>
557 valarray<_Tp>::max() const
559 return *max_element (_M_data, _M_data+_M_size);
563 inline _Expr<_ValFunClos<_ValArray,_Tp>,_Tp>
564 valarray<_Tp>::apply (_Tp func (_Tp)) const
566 typedef _ValFunClos<_ValArray,_Tp> _Closure;
567 return _Expr<_Closure,_Tp> (_Closure (*this, func));
571 inline _Expr<_RefFunClos<_ValArray,_Tp>,_Tp>
572 valarray<_Tp>::apply (_Tp func (const _Tp &)) const
574 typedef _RefFunClos<_ValArray,_Tp> _Closure;
575 return _Expr<_Closure,_Tp> (_Closure (*this, func));
578 #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \
579 template<typename _Tp> \
580 inline _Expr<_UnClos<_Name,_ValArray,_Tp>, _Tp> \
581 valarray<_Tp>::operator _Op() const \
583 typedef _UnClos<_Name,_ValArray,_Tp> _Closure; \
584 return _Expr<_Closure, _Tp> (_Closure (*this)); \
587 _DEFINE_VALARRAY_UNARY_OPERATOR(+, _Unary_plus)
588 _DEFINE_VALARRAY_UNARY_OPERATOR(-, negate)
589 _DEFINE_VALARRAY_UNARY_OPERATOR(~, _Bitwise_not)
591 #undef _DEFINE_VALARRAY_UNARY_OPERATOR
593 template<typename _Tp>
594 inline _Expr<_UnClos<logical_not,_ValArray,_Tp>, bool>
595 valarray<_Tp>::operator!() const
597 typedef _UnClos<logical_not,_ValArray,_Tp> _Closure;
598 return _Expr<_Closure, bool> (_Closure (*this));
601 #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
602 template<class _Tp> \
603 inline valarray<_Tp> & \
604 valarray<_Tp>::operator _Op##= (const _Tp &__t) \
606 _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, __t); \
610 template<class _Tp> \
611 inline valarray<_Tp> & \
612 valarray<_Tp>::operator _Op##= (const valarray<_Tp> &__v) \
614 _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, \
615 _Array<_Tp>(__v._M_data)); \
619 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, plus)
620 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, minus)
621 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, multiplies)
622 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, divides)
623 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, modulus)
624 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, xor)
625 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, and)
626 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, or)
627 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, shift_left)
628 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, shift_right)
630 #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
639 #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
640 template<class _Tp> template<class _Dom> \
641 inline valarray<_Tp> & \
642 valarray<_Tp>::operator _Op##= (const _Expr<_Dom,_Tp> &__e) \
644 _Array_augmented_##_Name (_Array<_Tp>(_M_data), __e, _M_size); \
648 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, plus)
649 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, minus)
650 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, multiplies)
651 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, divides)
652 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, modulus)
653 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, xor)
654 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, and)
655 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, or)
656 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, shift_left)
657 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, shift_right)
659 #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
662 #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
663 template<typename _Tp> \
664 inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \
665 operator _Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
667 typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
668 return _Expr<_Closure, _Tp> (_Closure (__v, __w)); \
671 template<typename _Tp> \
672 inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,_Tp> \
673 operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \
675 typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
676 return _Expr<_Closure, _Tp> (_Closure (__v, __t)); \
679 template<typename _Tp> \
680 inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,_Tp> \
681 operator _Op (const _Tp &__t, const valarray<_Tp> &__v) \
683 typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
684 return _Expr<_Closure, _Tp> (_Closure (__t, __v)); \
687 _DEFINE_BINARY_OPERATOR(+, plus)
688 _DEFINE_BINARY_OPERATOR(-, minus)
689 _DEFINE_BINARY_OPERATOR(*, multiplies)
690 _DEFINE_BINARY_OPERATOR(/, divides)
691 _DEFINE_BINARY_OPERATOR(%, modulus)
692 _DEFINE_BINARY_OPERATOR(^, _Bitwise_xor)
693 _DEFINE_BINARY_OPERATOR(&, _Bitwise_and)
694 _DEFINE_BINARY_OPERATOR(|, _Bitwise_or)
695 _DEFINE_BINARY_OPERATOR(<<, _Shift_left)
696 _DEFINE_BINARY_OPERATOR(>>, _Shift_right)
698 #undef _DEFINE_BINARY_OPERATOR
700 #define _DEFINE_LOGICAL_OPERATOR(_Op, _Name) \
701 template<typename _Tp> \
702 inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>,bool> \
703 operator _Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
705 typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
706 return _Expr<_Closure, bool> (_Closure (__v, __w)); \
709 template<class _Tp> \
710 inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,bool> \
711 operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \
713 typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
714 return _Expr<_Closure, bool> (_Closure (__v, __t)); \
717 template<class _Tp> \
718 inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,bool> \
719 operator _Op (const _Tp &__t, const valarray<_Tp> &__v) \
721 typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
722 return _Expr<_Closure, bool> (_Closure (__t, __v)); \
725 _DEFINE_LOGICAL_OPERATOR(&&, logical_and)
726 _DEFINE_LOGICAL_OPERATOR(||, logical_or)
727 _DEFINE_LOGICAL_OPERATOR(==, equal_to)
728 _DEFINE_LOGICAL_OPERATOR(!=, not_equal_to)
729 _DEFINE_LOGICAL_OPERATOR(<, less)
730 _DEFINE_LOGICAL_OPERATOR(>, greater)
731 _DEFINE_LOGICAL_OPERATOR(<=, less_equal)
732 _DEFINE_LOGICAL_OPERATOR(>=, greater_equal)
734 #undef _DEFINE_LOGICAL_OPERATOR
738 #endif // _CPP_VALARRAY