1 // The template and inlines for the -*- C++ -*- valarray class.
3 // Copyright (C) 1997-1999 Cygnus Solutions
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)
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,
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
45 #define alloca __builtin_alloca
46 #else /* not GNU C. */
47 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
50 #if defined (MSDOS) && !defined (__TURBOC__)
52 #else /* not MSDOS, or __TURBOC__ */
56 #else /* not MSDOS, __TURBOC__, or _AIX */
60 #endif /* not MSDOS, or __TURBOC__ */
61 #endif /* not sparc. */
62 #endif /* not GNU C. */
63 #endif /* alloca not defined. */
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
111 #include <std/valarray_array.h>
112 #include <std/valarray_meta.h>
116 template<class _Tp
> class valarray
119 typedef _Tp value_type
;
121 // _lib.valarray.cons_ construct/destroy:
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
>&);
132 valarray(const _Expr
<_Dom
,_Tp
>& __e
);
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
>&);
189 valarray
<_Tp
>& operator*= (const _Expr
<_Dom
,_Tp
>&);
191 valarray
<_Tp
>& operator/= (const _Expr
<_Dom
,_Tp
>&);
193 valarray
<_Tp
>& operator%= (const _Expr
<_Dom
,_Tp
>&);
195 valarray
<_Tp
>& operator+= (const _Expr
<_Dom
,_Tp
>&);
197 valarray
<_Tp
>& operator-= (const _Expr
<_Dom
,_Tp
>&);
199 valarray
<_Tp
>& operator^= (const _Expr
<_Dom
,_Tp
>&);
201 valarray
<_Tp
>& operator|= (const _Expr
<_Dom
,_Tp
>&);
203 valarray
<_Tp
>& operator&= (const _Expr
<_Dom
,_Tp
>&);
205 valarray
<_Tp
>& operator<<=(const _Expr
<_Dom
,_Tp
>&);
207 valarray
<_Tp
>& operator>>=(const _Expr
<_Dom
,_Tp
>&);
210 // _lib.valarray.members_ member functions:
217 _Tp
product () const;
219 valarray
<_Tp
> shift (int) const;
220 valarray
<_Tp
> cshift(int) const;
221 _Expr
<_ValFunClos
<_ValArray
,_Tp
>,_Tp
> apply(_Tp
func(_Tp
)) const;
222 _Expr
<_RefFunClos
<_ValArray
,_Tp
>,_Tp
> apply(_Tp
func(const _Tp
&)) const;
223 void resize(size_t __size
, _Tp __c
= _Tp());
227 _Tp
* __restrict__ _M_data
;
229 friend class _Array
<_Tp
>;
233 template<typename _Tp
> struct _Unary_plus
: unary_function
<_Tp
,_Tp
> {
234 _Tp
operator() (const _Tp
& __t
) const { return __t
; }
237 template<typename _Tp
> struct _Bitwise_and
: binary_function
<_Tp
,_Tp
,_Tp
> {
238 _Tp
operator() (_Tp __x
, _Tp __y
) const { return __x
& __y
; }
241 template<typename _Tp
> struct _Bitwise_or
: binary_function
<_Tp
,_Tp
,_Tp
> {
242 _Tp
operator() (_Tp __x
, _Tp __y
) const { return __x
| __y
; }
245 template<typename _Tp
> struct _Bitwise_xor
: binary_function
<_Tp
,_Tp
,_Tp
> {
246 _Tp
operator() (_Tp __x
, _Tp __y
) const { return __x
^ __y
; }
249 template<typename _Tp
> struct _Bitwise_not
: unary_function
<_Tp
,_Tp
> {
250 _Tp
operator() (_Tp __t
) const { return ~__t
; }
253 template<typename _Tp
> struct _Shift_left
: unary_function
<_Tp
,_Tp
> {
254 _Tp
operator() (_Tp __x
, _Tp __y
) const { return __x
<< __y
; }
257 template<typename _Tp
> struct _Shift_right
: unary_function
<_Tp
,_Tp
> {
258 _Tp
operator() (_Tp __x
, _Tp __y
) const { return __x
>> __y
; }
262 template<typename _Tp
>
264 valarray
<_Tp
>::operator[] (size_t __i
) const
265 { return _M_data
[__i
]; }
267 template<typename _Tp
>
269 valarray
<_Tp
>::operator[] (size_t __i
)
270 { return _M_data
[__i
]; }
274 #include <std/slice.h>
275 #include <std/slice_array.h>
276 #include <std/gslice.h>
277 #include <std/gslice_array.h>
278 #include <std/mask_array.h>
279 #include <std/indirect_array.h>
283 template<typename _Tp
>
284 inline valarray
<_Tp
>::valarray () : _M_size (0), _M_data (0) {}
286 template<typename _Tp
>
287 inline valarray
<_Tp
>::valarray (size_t __n
)
288 : _M_size (__n
), _M_data (new _Tp
[__n
]) {}
290 template<typename _Tp
>
291 inline valarray
<_Tp
>::valarray (const _Tp
& __t
, size_t __n
)
292 : _M_size (__n
), _M_data (new _Tp
[__n
])
293 { __valarray_fill (_M_data
, _M_size
, __t
); }
295 template<typename _Tp
>
296 inline valarray
<_Tp
>::valarray (const _Tp
* __restrict__ __pT
, size_t __n
)
297 : _M_size (__n
), _M_data (new _Tp
[__n
])
298 { __valarray_copy (__pT
, __n
, _M_data
); }
300 template<typename _Tp
>
301 inline valarray
<_Tp
>::valarray (const valarray
<_Tp
>& __v
)
302 : _M_size (__v
._M_size
), _M_data (new _Tp
[__v
._M_size
])
303 { __valarray_copy (__v
._M_data
, _M_size
, _M_data
); }
305 template<typename _Tp
>
306 inline valarray
<_Tp
>::valarray (const slice_array
<_Tp
>& __sa
)
307 : _M_size (__sa
._M_sz
), _M_data (new _Tp
[__sa
._M_sz
])
308 { __valarray_copy (__sa
._M_array
, __sa
._M_sz
, __sa
._M_stride
,
309 _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()), _M_data (new _Tp
[_M_size
])
314 { __valarray_copy (__ga
._M_array
, _Array
<size_t>(__ga
._M_index
),
315 _Array
<_Tp
>(_M_data
), _M_size
); }
317 template<typename _Tp
>
318 inline valarray
<_Tp
>::valarray (const mask_array
<_Tp
>& __ma
)
319 : _M_size (__ma
._M_sz
), _M_data (new _Tp
[__ma
._M_sz
])
320 { __valarray_copy (__ma
._M_array
, __ma
._M_mask
,
321 _Array
<_Tp
>(_M_data
), _M_size
); }
323 template<typename _Tp
>
324 inline valarray
<_Tp
>::valarray (const indirect_array
<_Tp
>& __ia
)
325 : _M_size (__ia
._M_sz
), _M_data (new _Tp
[__ia
._M_sz
])
326 { __valarray_copy (__ia
._M_array
, __ia
._M_index
,
327 _Array
<_Tp
>(_M_data
), _M_size
); }
329 template<typename _Tp
> template<class _Dom
>
330 inline valarray
<_Tp
>::valarray (const _Expr
<_Dom
, _Tp
>& __e
)
331 : _M_size (__e
.size ()), _M_data (new _Tp
[_M_size
])
332 { __valarray_copy (__e
, _M_size
, _Array
<_Tp
>(_M_data
)); }
334 template<typename _Tp
>
335 inline valarray
<_Tp
>::~valarray () { delete[] _M_data
; }
337 template<typename _Tp
>
338 inline valarray
<_Tp
>&
339 valarray
<_Tp
>::operator= (const valarray
<_Tp
>& __v
)
341 __valarray_copy(__v
._M_data
, _M_size
, _M_data
);
345 template<typename _Tp
>
346 inline valarray
<_Tp
>&
347 valarray
<_Tp
>::operator= (const _Tp
& __t
)
349 __valarray_fill (_M_data
, _M_size
, __t
);
353 template<typename _Tp
>
354 inline valarray
<_Tp
>&
355 valarray
<_Tp
>::operator= (const slice_array
<_Tp
>& __sa
)
357 __valarray_copy (__sa
._M_array
, __sa
._M_sz
,
358 __sa
._M_stride
, _Array
<_Tp
>(_M_data
));
362 template<typename _Tp
>
363 inline valarray
<_Tp
>&
364 valarray
<_Tp
>::operator= (const gslice_array
<_Tp
>& __ga
)
366 __valarray_copy (__ga
._M_array
, _Array
<size_t>(__ga
._M_index
),
367 _Array
<_Tp
>(_M_data
), _M_size
);
371 template<typename _Tp
>
372 inline valarray
<_Tp
>&
373 valarray
<_Tp
>::operator= (const mask_array
<_Tp
>& __ma
)
375 __valarray_copy (__ma
._M_array
, __ma
._M_mask
,
376 _Array
<_Tp
>(_M_data
), _M_size
);
380 template<typename _Tp
>
381 inline valarray
<_Tp
>&
382 valarray
<_Tp
>::operator= (const indirect_array
<_Tp
>& __ia
)
384 __valarray_copy (__ia
._M_array
, __ia
._M_index
,
385 _Array
<_Tp
>(_M_data
), _M_size
);
389 template<typename _Tp
> template<class _Dom
>
390 inline valarray
<_Tp
>&
391 valarray
<_Tp
>::operator= (const _Expr
<_Dom
, _Tp
>& __e
)
393 __valarray_copy (__e
, _M_size
, _Array
<_Tp
>(_M_data
));
397 template<typename _Tp
>
398 inline _Expr
<_SClos
<_ValArray
,_Tp
>, _Tp
>
399 valarray
<_Tp
>::operator[] (slice __s
) const
401 typedef _SClos
<_ValArray
,_Tp
> _Closure
;
402 return _Expr
<_Closure
, _Tp
> (_Closure (_Array
<_Tp
>(_M_data
), __s
));
405 template<typename _Tp
>
406 inline slice_array
<_Tp
>
407 valarray
<_Tp
>::operator[] (slice __s
)
409 return slice_array
<_Tp
> (_Array
<_Tp
>(_M_data
), __s
);
412 template<typename _Tp
>
413 inline _Expr
<_GClos
<_ValArray
,_Tp
>, _Tp
>
414 valarray
<_Tp
>::operator[] (const gslice
& __gs
) const
416 typedef _GClos
<_ValArray
,_Tp
> _Closure
;
417 return _Expr
<_Closure
, _Tp
>
418 (_Closure (_Array
<_Tp
>(_M_data
), __gs
._M_index
->_M_index
));
421 template<typename _Tp
>
422 inline gslice_array
<_Tp
>
423 valarray
<_Tp
>::operator[] (const gslice
& __gs
)
425 return gslice_array
<_Tp
>
426 (_Array
<_Tp
>(_M_data
), __gs
._M_index
->_M_index
);
429 template<typename _Tp
>
431 valarray
<_Tp
>::operator[] (const valarray
<bool>& __m
) const
434 size_t __e (__m
.size ());
435 for (size_t __i
=0; __i
<__e
; ++__i
)
437 return valarray
<_Tp
> (mask_array
<_Tp
> (_Array
<_Tp
>(_M_data
), __s
,
438 _Array
<bool> (__m
)));
441 template<typename _Tp
>
442 inline mask_array
<_Tp
>
443 valarray
<_Tp
>::operator[] (const valarray
<bool>& __m
)
446 size_t __e (__m
.size ());
447 for (size_t __i
=0; __i
<__e
; ++__i
)
449 return mask_array
<_Tp
> (_Array
<_Tp
>(_M_data
), __s
, _Array
<bool> (__m
));
452 template<typename _Tp
>
453 inline _Expr
<_IClos
<_ValArray
,_Tp
>, _Tp
>
454 valarray
<_Tp
>::operator[] (const valarray
<size_t>& __i
) const
456 typedef _IClos
<_ValArray
,_Tp
> _Closure
;
457 return _Expr
<_Closure
, _Tp
> (_Closure (*this, __i
));
460 template<typename _Tp
>
461 inline indirect_array
<_Tp
>
462 valarray
<_Tp
>::operator[] (const valarray
<size_t>& __i
)
464 return indirect_array
<_Tp
> (_Array
<_Tp
>(_M_data
), __i
.size(),
465 _Array
<size_t> (__i
));
469 inline size_t valarray
<_Tp
>::size () const { return _M_size
; }
473 valarray
<_Tp
>::sum () const
475 return accumulate (_M_data
, _M_data
+ _M_size
, _Tp ());
478 template<typename _Tp
>
480 valarray
<_Tp
>::product () const
482 return accumulate (_M_data
, _M_data
+_M_size
, _Tp(1), multiplies
<_Tp
> ());
487 valarray
<_Tp
>::shift (int __n
) const
489 _Tp
* const __a
= static_cast<_Tp
*> (alloca (sizeof(_Tp
) * _M_size
));
490 if (! __n
) // __n == 0: no shift
491 __valarray_copy (_M_data
, _M_size
, __a
);
492 else if (__n
> 0) { // __n > 0: shift left
494 __valarray_fill(__a
, __n
, _Tp());
496 __valarray_copy (_M_data
+__n
, _M_size
-__n
, __a
);
497 __valarray_fill (__a
+_M_size
-__n
, __n
, _Tp());
500 else { // __n < 0: shift right
501 __valarray_copy (_M_data
, _M_size
+__n
, __a
-__n
);
502 __valarray_fill(__a
, -__n
, _Tp());
504 return valarray
<_Tp
> (__a
, _M_size
);
509 valarray
<_Tp
>::cshift (int __n
) const
511 _Tp
* const __a
= static_cast<_Tp
*> (alloca (sizeof(_Tp
) * _M_size
));
512 if (! __n
) // __n == 0: no cshift
513 __valarray_copy(_M_data
, _M_size
, __a
);
514 else if (__n
> 0) { // __n > 0: cshift left
515 __valarray_copy (_M_data
, __n
, __a
+ _M_size
-__n
);
516 __valarray_copy (_M_data
+ __n
, _M_size
-__n
, __a
);
518 else { // __n < 0: cshift right
519 __valarray_copy (_M_data
+ _M_size
+ __n
, -__n
, __a
);
520 __valarray_copy (_M_data
, _M_size
+ __n
, __a
- __n
);
522 return valarray
<_Tp
> (__a
, _M_size
);
527 valarray
<_Tp
>::resize (size_t __n
, _Tp __c
)
529 if (_M_size
!= __n
) {
532 _M_data
= new _Tp
[_M_size
];
534 __valarray_fill (_M_data
, _M_size
, __c
);
537 template<typename _Tp
>
539 valarray
<_Tp
>::min() const
541 return *min_element (_M_data
, _M_data
+_M_size
);
544 template<typename _Tp
>
546 valarray
<_Tp
>::max() const
548 return *max_element (_M_data
, _M_data
+_M_size
);
552 inline _Expr
<_ValFunClos
<_ValArray
,_Tp
>,_Tp
>
553 valarray
<_Tp
>::apply (_Tp
func (_Tp
)) const
555 typedef _ValFunClos
<_ValArray
,_Tp
> _Closure
;
556 return _Expr
<_Closure
,_Tp
> (_Closure (*this, func
));
560 inline _Expr
<_RefFunClos
<_ValArray
,_Tp
>,_Tp
>
561 valarray
<_Tp
>::apply (_Tp
func (const _Tp
&)) const
563 typedef _RefFunClos
<_ValArray
,_Tp
> _Closure
;
564 return _Expr
<_Closure
,_Tp
> (_Closure (*this, func
));
567 #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \
568 template<typename _Tp> \
569 inline _Expr<_UnClos<_Name,_ValArray,_Tp>, _Tp> \
570 valarray<_Tp>::operator##_Op() const \
572 typedef _UnClos<_Name,_ValArray,_Tp> _Closure; \
573 return _Expr<_Closure, _Tp> (_Closure (*this)); \
576 _DEFINE_VALARRAY_UNARY_OPERATOR(+, _Unary_plus
)
577 _DEFINE_VALARRAY_UNARY_OPERATOR(-, negate
)
578 _DEFINE_VALARRAY_UNARY_OPERATOR(~, _Bitwise_not
)
580 #undef _DEFINE_VALARRAY_UNARY_OPERATOR
582 template<typename _Tp
>
583 inline _Expr
<_UnClos
<logical_not
,_ValArray
,_Tp
>, bool>
584 valarray
<_Tp
>::operator!() const
586 typedef _UnClos
<logical_not
,_ValArray
,_Tp
> _Closure
;
587 return _Expr
<_Closure
, bool> (_Closure (*this));
590 #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
591 template<class _Tp> \
592 inline valarray<_Tp> & \
593 valarray<_Tp>::operator##_Op##= (const _Tp &__t) \
595 _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, __t); \
599 template<class _Tp> \
600 inline valarray<_Tp> & \
601 valarray<_Tp>::operator##_Op##= (const valarray<_Tp> &__v) \
603 _Array_augmented_##_Name (_Array<_Tp>(_M_data), _M_size, \
604 _Array<_Tp>(__v._M_data)); \
608 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, plus
)
609 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, minus
)
610 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, multiplies
)
611 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, divides
)
612 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, modulus
)
613 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, xor)
614 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, and)
615 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, or)
616 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, shift_left
)
617 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, shift_right
)
619 #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
622 #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
623 template<class _Tp> template<class _Dom> \
624 inline valarray<_Tp> & \
625 valarray<_Tp>::operator##_Op##= (const _Expr<_Dom,_Tp> &__e) \
627 _Array_augmented_##_Name (_Array<_Tp>(_M_data), __e, _M_size); \
631 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, plus
)
632 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, minus
)
633 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, multiplies
)
634 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, divides
)
635 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, modulus
)
636 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, xor)
637 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, and)
638 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, or)
639 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, shift_left
)
640 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, shift_right
)
642 #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
645 #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
646 template<typename _Tp> \
647 inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \
648 operator##_Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
650 typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
651 return _Expr<_Closure, _Tp> (_Closure (__v, __w)); \
654 template<typename _Tp> \
655 inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,_Tp> \
656 operator##_Op (const valarray<_Tp> &__v, const _Tp &__t) \
658 typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
659 return _Expr<_Closure, _Tp> (_Closure (__v, __t)); \
662 template<typename _Tp> \
663 inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,_Tp> \
664 operator##_Op (const _Tp &__t, const valarray<_Tp> &__v) \
666 typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
667 return _Expr<_Closure, _Tp> (_Closure (__t, __v)); \
670 _DEFINE_BINARY_OPERATOR(+, plus
)
671 _DEFINE_BINARY_OPERATOR(-, minus
)
672 _DEFINE_BINARY_OPERATOR(*, multiplies
)
673 _DEFINE_BINARY_OPERATOR(/, divides
)
674 _DEFINE_BINARY_OPERATOR(%, modulus
)
675 _DEFINE_BINARY_OPERATOR(^, _Bitwise_xor
)
676 _DEFINE_BINARY_OPERATOR(&, _Bitwise_and
)
677 _DEFINE_BINARY_OPERATOR(|, _Bitwise_or
)
678 _DEFINE_BINARY_OPERATOR(<<, _Shift_left
)
679 _DEFINE_BINARY_OPERATOR(>>, _Shift_right
)
681 #undef _DEFINE_BINARY_OPERATOR
683 #define _DEFINE_LOGICAL_OPERATOR(_Op, _Name) \
684 template<typename _Tp> \
685 inline _Expr<_BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp>,bool> \
686 operator##_Op (const valarray<_Tp> &__v, const valarray<_Tp> &__w) \
688 typedef _BinClos<_Name,_ValArray,_ValArray,_Tp,_Tp> _Closure; \
689 return _Expr<_Closure, bool> (_Closure (__v, __w)); \
692 template<class _Tp> \
693 inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,bool> \
694 operator##_Op (const valarray<_Tp> &__v, const _Tp &__t) \
696 typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \
697 return _Expr<_Closure, bool> (_Closure (__v, __t)); \
700 template<class _Tp> \
701 inline _Expr<_BinClos<_Name,_Constant,_ValArray,_Tp,_Tp>,bool> \
702 operator##_Op (const _Tp &__t, const valarray<_Tp> &__v) \
704 typedef _BinClos<_Name,_Constant,_ValArray,_Tp,_Tp> _Closure; \
705 return _Expr<_Closure, bool> (_Closure (__t, __v)); \
708 _DEFINE_LOGICAL_OPERATOR(&&, logical_and
)
709 _DEFINE_LOGICAL_OPERATOR(||, logical_or
)
710 _DEFINE_LOGICAL_OPERATOR(==, equal_to
)
711 _DEFINE_LOGICAL_OPERATOR(!=, not_equal_to
)
712 _DEFINE_LOGICAL_OPERATOR(<, less
)
713 _DEFINE_LOGICAL_OPERATOR(>, greater
)
714 _DEFINE_LOGICAL_OPERATOR(<=, less_equal
)
715 _DEFINE_LOGICAL_OPERATOR(>=, greater_equal
)
717 #undef _DEFINE_VALARRAY_OPERATOR
719 #undef _G_NO_VALARRAY_TEMPLATE_EXPORT
723 #endif // __STD_VALARRAY__