2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
4 * Silicon Graphics Computer Systems, Inc.
9 * This material is provided "as is", with absolutely no warranty expressed
10 * or implied. Any use is at your own risk.
12 * Permission to use or copy this software for any purpose is hereby granted
13 * without fee, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
20 #ifndef _STLP_VALARRAY_H
21 #define _STLP_VALARRAY_H
23 #ifndef _STLP_CMATH_H_HEADER
24 #include <stl/_cmath.h>
26 #ifndef _STLP_INTERNAL_NEW_HEADER
29 #ifndef _STLP_INTERNAL_ALGO_H
30 #include <stl/_algo.h>
32 #ifndef _STLP_INTERNAL_NUMERIC_H
33 #include <stl/_numeric.h>
35 #ifndef _STLP_LIMITS_H
39 //To resolve the unidentified identifier __THROW_BAD_ALLOC
40 #include <stl/_alloc.h>
47 template <class _Tp> class valarray;
48 typedef valarray<bool> _Valarray_bool;
49 typedef valarray<size_t> _Valarray_size_t;
51 template <class _Tp> class slice_array;
52 template <class _Tp> class gslice_array;
53 template <class _Tp> class mask_array;
54 template <class _Tp> class indirect_array;
56 //----------------------------------------------------------------------
59 // Base class to handle memory allocation and deallocation. We can't just
60 // use vector<>, because vector<bool> would be unsuitable as an internal
61 // representation for valarray<bool>.
69 _Valarray_base() : _M_first(0), _M_size(0) {}
70 _Valarray_base(size_t __n) : _M_first(0), _M_size(0) { _M_allocate(__n); }
71 ~_Valarray_base() { _M_deallocate(); }
73 void _M_allocate(size_t __n) {
76 _M_first = ::new _Tp[__n];
78 _M_first = __STATIC_CAST(_Tp*, (malloc(__n * sizeof(_Tp))));
92 void _M_deallocate() {
104 class valarray : private _Valarray_base<_Tp>
109 typedef _Tp value_type;
111 // Basic constructors
112 valarray() : _Valarray_base<_Tp>() {}
113 valarray(size_t __n) : _Valarray_base<_Tp>(__n) {}
114 valarray(const value_type& __x, size_t __n) : _Valarray_base<_Tp>(__n)
115 { uninitialized_fill_n(this->_M_first, this->_M_size, __x); }
116 valarray(const value_type* __p, size_t __n) : _Valarray_base<_Tp>(__n)
117 { uninitialized_copy(__p, __p + __n, this->_M_first); }
118 valarray(const valarray<_Tp>& __x) : _Valarray_base<_Tp>(__x._M_size) {
119 uninitialized_copy(__x._M_first, __x._M_first + __x._M_size,
123 // Constructors from auxiliary array types
124 valarray(const slice_array<_Tp>&);
125 valarray(const gslice_array<_Tp>&);
126 valarray(const mask_array<_Tp>&);
127 valarray(const indirect_array<_Tp>&);
130 ~valarray() { _STLP_STD::_Destroy(this->_M_first, this->_M_first + this->_M_size); }
132 // Extension: constructor that doesn't initialize valarray elements to a
133 // specific value. This is faster for types such as int and double.
135 void _M_initialize(const __true_type&) {}
136 void _M_initialize(const __false_type&)
137 { uninitialized_fill_n(this->_M_first, this->_M_size, value_type()); }
141 valarray(size_t __n, _NoInit) : _Valarray_base<_Tp>(__n) {
142 typedef typename __type_traits<_Tp>::has_trivial_default_constructor _Is_Trivial;
143 _M_initialize(_Is_Trivial());
146 public: // Assignment
147 // Basic assignment. Note that 'x = y' is undefined if x.size() != y.size()
148 valarray<_Tp>& operator=(const valarray<_Tp>& __x) {
149 _STLP_ASSERT(__x.size() == this->size())
155 copy(__x._M_first, __x._M_first + __x._M_size, this->_M_first);
161 valarray<_Tp>& operator=(const value_type& __x) {
162 fill_n(this->_M_first, this->_M_size, __x);
166 // Assignment of auxiliary array types
167 valarray<_Tp>& operator=(const slice_array<_Tp>&);
168 valarray<_Tp>& operator=(const gslice_array<_Tp>&);
169 valarray<_Tp>& operator=(const mask_array<_Tp>&);
170 valarray<_Tp>& operator=(const indirect_array<_Tp>&);
172 public: // Element access
173 value_type operator[](size_t __n) const { return this->_M_first[__n]; }
174 value_type& operator[](size_t __n) { return this->_M_first[__n]; }
175 size_t size() const { return this->_M_size; }
177 public: // Subsetting operations with auxiliary type
178 valarray<_Tp> operator[](slice) const;
179 slice_array<_Tp> operator[](slice);
180 valarray<_Tp> operator[](gslice) const;
181 gslice_array<_Tp> operator[](const gslice&);
182 valarray<_Tp> operator[](const _Valarray_bool&) const;
183 mask_array<_Tp> operator[](const _Valarray_bool&);
184 valarray<_Tp> operator[](const _Valarray_size_t&) const;
185 indirect_array<_Tp> operator[](const _Valarray_size_t&);
187 public: // Unary operators.
188 valarray<_Tp> operator+() const { return *this; }
190 valarray<_Tp> operator-() const {
191 valarray<_Tp> __tmp(this->size(), _NoInit());
192 for (size_t __i = 0; __i < this->size(); ++__i)
193 __tmp[__i] = -(*this)[__i];
197 valarray<_Tp> operator~() const {
198 valarray<_Tp> __tmp(this->size(), _NoInit());
199 for (size_t __i = 0; __i < this->size(); ++__i)
200 __tmp[__i] = ~(*this)[__i];
204 _Valarray_bool operator!() const;
206 public: // Scalar computed assignment.
207 valarray<_Tp>& operator*= (const value_type& __x) {
208 for (size_t __i = 0; __i < this->size(); ++__i)
213 valarray<_Tp>& operator/= (const value_type& __x) {
214 for (size_t __i = 0; __i < this->size(); ++__i)
219 valarray<_Tp>& operator%= (const value_type& __x) {
220 for (size_t __i = 0; __i < this->size(); ++__i)
225 valarray<_Tp>& operator+= (const value_type& __x) {
226 for (size_t __i = 0; __i < this->size(); ++__i)
231 valarray<_Tp>& operator-= (const value_type& __x) {
232 for (size_t __i = 0; __i < this->size(); ++__i)
237 valarray<_Tp>& operator^= (const value_type& __x) {
238 for (size_t __i = 0; __i < this->size(); ++__i)
243 valarray<_Tp>& operator&= (const value_type& __x) {
244 for (size_t __i = 0; __i < this->size(); ++__i)
249 valarray<_Tp>& operator|= (const value_type& __x) {
250 for (size_t __i = 0; __i < this->size(); ++__i)
255 valarray<_Tp>& operator<<= (const value_type& __x) {
256 for (size_t __i = 0; __i < this->size(); ++__i)
257 (*this)[__i] <<= __x;
261 valarray<_Tp>& operator>>= (const value_type& __x) {
262 for (size_t __i = 0; __i < this->size(); ++__i)
263 (*this)[__i] >>= __x;
267 public: // Array computed assignment.
268 valarray<_Tp>& operator*= (const valarray<_Tp>& __x) {
269 for (size_t __i = 0; __i < this->size(); ++__i)
270 (*this)[__i] *= __x[__i];
274 valarray<_Tp>& operator/= (const valarray<_Tp>& __x) {
275 for (size_t __i = 0; __i < this->size(); ++__i)
276 (*this)[__i] /= __x[__i];
280 valarray<_Tp>& operator%= (const valarray<_Tp>& __x) {
281 for (size_t __i = 0; __i < this->size(); ++__i)
282 (*this)[__i] %= __x[__i];
286 valarray<_Tp>& operator+= (const valarray<_Tp>& __x) {
287 for (size_t __i = 0; __i < this->size(); ++__i)
288 (*this)[__i] += __x[__i];
292 valarray<_Tp>& operator-= (const valarray<_Tp>& __x) {
293 for (size_t __i = 0; __i < this->size(); ++__i)
294 (*this)[__i] -= __x[__i];
298 valarray<_Tp>& operator^= (const valarray<_Tp>& __x) {
299 for (size_t __i = 0; __i < this->size(); ++__i)
300 (*this)[__i] ^= __x[__i];
304 valarray<_Tp>& operator&= (const valarray<_Tp>& __x) {
305 for (size_t __i = 0; __i < this->size(); ++__i)
306 (*this)[__i] &= __x[__i];
310 valarray<_Tp>& operator|= (const valarray<_Tp>& __x) {
311 for (size_t __i = 0; __i < this->size(); ++__i)
312 (*this)[__i] |= __x[__i];
316 valarray<_Tp>& operator<<= (const valarray<_Tp>& __x) {
317 for (size_t __i = 0; __i < this->size(); ++__i)
318 (*this)[__i] <<= __x[__i];
322 valarray<_Tp>& operator>>= (const valarray<_Tp>& __x) {
323 for (size_t __i = 0; __i < this->size(); ++__i)
324 (*this)[__i] >>= __x[__i];
328 public: // Other member functions.
330 // The result is undefined for zero-length arrays
331 value_type sum() const {
332 return accumulate(this->_M_first + 1, this->_M_first + this->_M_size,
336 // The result is undefined for zero-length arrays
337 value_type (min) () const {
338 return *min_element(this->_M_first + 0, this->_M_first + this->_M_size);
341 value_type (max) () const {
342 return *max_element(this->_M_first + 0, this->_M_first + this->_M_size);
345 valarray<_Tp> shift(int __n) const;
346 valarray<_Tp> cshift(int __n) const;
348 valarray<_Tp> apply(value_type __f(value_type)) const {
349 valarray<_Tp> __tmp(this->size());
350 transform(this->_M_first + 0, this->_M_first + this->_M_size, __tmp._M_first,
354 valarray<_Tp> apply(value_type __f(const value_type&)) const {
355 valarray<_Tp> __tmp(this->size());
356 transform(this->_M_first + 0, this->_M_first + this->_M_size, __tmp._M_first,
361 void resize(size_t __n, value_type __x = value_type()) {
362 _STLP_STD::_Destroy(this->_M_first, this->_M_first + this->_M_size);
363 this->_Valarray_base<_Tp>::_M_deallocate();
364 this->_Valarray_base<_Tp>::_M_allocate(__n);
365 uninitialized_fill_n(this->_M_first, this->_M_size, __x);
369 //----------------------------------------------------------------------
370 // valarray non-member functions.
372 // Binary arithmetic operations between two arrays. Behavior is
373 // undefined if the two arrays do not have the same length.
376 inline valarray<_Tp> _STLP_CALL operator*(const valarray<_Tp>& __x,
377 const valarray<_Tp>& __y) {
378 typedef typename valarray<_Tp>::_NoInit _NoInit;
379 valarray<_Tp> __tmp(__x.size(), _NoInit());
380 for (size_t __i = 0; __i < __x.size(); ++__i)
381 __tmp[__i] = __x[__i] * __y[__i];
386 inline valarray<_Tp> _STLP_CALL operator/(const valarray<_Tp>& __x,
387 const valarray<_Tp>& __y) {
388 typedef typename valarray<_Tp>::_NoInit _NoInit;
389 valarray<_Tp> __tmp(__x.size(), _NoInit());
390 for (size_t __i = 0; __i < __x.size(); ++__i)
391 __tmp[__i] = __x[__i] / __y[__i];
396 inline valarray<_Tp> _STLP_CALL operator%(const valarray<_Tp>& __x,
397 const valarray<_Tp>& __y) {
398 typedef typename valarray<_Tp>::_NoInit _NoInit;
399 valarray<_Tp> __tmp(__x.size(), _NoInit());
400 for (size_t __i = 0; __i < __x.size(); ++__i)
401 __tmp[__i] = __x[__i] % __y[__i];
406 inline valarray<_Tp> _STLP_CALL operator+(const valarray<_Tp>& __x,
407 const valarray<_Tp>& __y) {
408 typedef typename valarray<_Tp>::_NoInit _NoInit;
409 valarray<_Tp> __tmp(__x.size(), _NoInit());
410 for (size_t __i = 0; __i < __x.size(); ++__i)
411 __tmp[__i] = __x[__i] + __y[__i];
416 inline valarray<_Tp> _STLP_CALL operator-(const valarray<_Tp>& __x,
417 const valarray<_Tp>& __y) {
418 typedef typename valarray<_Tp>::_NoInit _NoInit;
419 valarray<_Tp> __tmp(__x.size(), _NoInit());
420 for (size_t __i = 0; __i < __x.size(); ++__i)
421 __tmp[__i] = __x[__i] - __y[__i];
426 inline valarray<_Tp> _STLP_CALL operator^(const valarray<_Tp>& __x,
427 const valarray<_Tp>& __y) {
428 typedef typename valarray<_Tp>::_NoInit _NoInit;
429 valarray<_Tp> __tmp(__x.size(), _NoInit());
430 for (size_t __i = 0; __i < __x.size(); ++__i)
431 __tmp[__i] = __x[__i] ^ __y[__i];
436 inline valarray<_Tp> _STLP_CALL operator&(const valarray<_Tp>& __x,
437 const valarray<_Tp>& __y) {
438 typedef typename valarray<_Tp>::_NoInit _NoInit;
439 valarray<_Tp> __tmp(__x.size(), _NoInit());
440 for (size_t __i = 0; __i < __x.size(); ++__i)
441 __tmp[__i] = __x[__i] & __y[__i];
446 inline valarray<_Tp> _STLP_CALL operator|(const valarray<_Tp>& __x,
447 const valarray<_Tp>& __y) {
448 typedef typename valarray<_Tp>::_NoInit _NoInit;
449 valarray<_Tp> __tmp(__x.size(), _NoInit());
450 for (size_t __i = 0; __i < __x.size(); ++__i)
451 __tmp[__i] = __x[__i] | __y[__i];
456 inline valarray<_Tp> _STLP_CALL operator<<(const valarray<_Tp>& __x,
457 const valarray<_Tp>& __y) {
458 typedef typename valarray<_Tp>::_NoInit _NoInit;
459 valarray<_Tp> __tmp(__x.size(), _NoInit());
460 for (size_t __i = 0; __i < __x.size(); ++__i)
461 __tmp[__i] = __x[__i] << __y[__i];
466 inline valarray<_Tp> _STLP_CALL operator>>(const valarray<_Tp>& __x,
467 const valarray<_Tp>& __y) {
468 typedef typename valarray<_Tp>::_NoInit _NoInit;
469 valarray<_Tp> __tmp(__x.size(), _NoInit());
470 for (size_t __i = 0; __i < __x.size(); ++__i)
471 __tmp[__i] = __x[__i] >> __y[__i];
475 // Binary arithmetic operations between an array and a scalar.
478 inline valarray<_Tp> _STLP_CALL operator*(const valarray<_Tp>& __x, const _Tp& __c) {
479 typedef typename valarray<_Tp>::_NoInit _NoInit;
480 valarray<_Tp> __tmp(__x.size(), _NoInit());
481 for (size_t __i = 0; __i < __x.size(); ++__i)
482 __tmp[__i] = __x[__i] * __c;
487 inline valarray<_Tp> _STLP_CALL operator*(const _Tp& __c, const valarray<_Tp>& __x) {
488 typedef typename valarray<_Tp>::_NoInit _NoInit;
489 valarray<_Tp> __tmp(__x.size(), _NoInit());
490 for (size_t __i = 0; __i < __x.size(); ++__i)
491 __tmp[__i] = __c * __x[__i];
496 inline valarray<_Tp> _STLP_CALL operator/(const valarray<_Tp>& __x, const _Tp& __c) {
497 typedef typename valarray<_Tp>::_NoInit _NoInit;
498 valarray<_Tp> __tmp(__x.size(), _NoInit());
499 for (size_t __i = 0; __i < __x.size(); ++__i)
500 __tmp[__i] = __x[__i] / __c;
505 inline valarray<_Tp> _STLP_CALL operator/(const _Tp& __c, const valarray<_Tp>& __x) {
506 typedef typename valarray<_Tp>::_NoInit _NoInit;
507 valarray<_Tp> __tmp(__x.size(), _NoInit());
508 for (size_t __i = 0; __i < __x.size(); ++__i)
509 __tmp[__i] = __c / __x[__i];
514 inline valarray<_Tp> _STLP_CALL operator%(const valarray<_Tp>& __x, const _Tp& __c) {
515 typedef typename valarray<_Tp>::_NoInit _NoInit;
516 valarray<_Tp> __tmp(__x.size(), _NoInit());
517 for (size_t __i = 0; __i < __x.size(); ++__i)
518 __tmp[__i] = __x[__i] % __c;
523 inline valarray<_Tp> _STLP_CALL operator%(const _Tp& __c, const valarray<_Tp>& __x) {
524 typedef typename valarray<_Tp>::_NoInit _NoInit;
525 valarray<_Tp> __tmp(__x.size(), _NoInit());
526 for (size_t __i = 0; __i < __x.size(); ++__i)
527 __tmp[__i] = __c % __x[__i];
532 inline valarray<_Tp> _STLP_CALL operator+(const valarray<_Tp>& __x, const _Tp& __c) {
533 typedef typename valarray<_Tp>::_NoInit _NoInit;
534 valarray<_Tp> __tmp(__x.size(), _NoInit());
535 for (size_t __i = 0; __i < __x.size(); ++__i)
536 __tmp[__i] = __x[__i] + __c;
541 inline valarray<_Tp> _STLP_CALL operator+(const _Tp& __c, const valarray<_Tp>& __x) {
542 typedef typename valarray<_Tp>::_NoInit _NoInit;
543 valarray<_Tp> __tmp(__x.size(), _NoInit());
544 for (size_t __i = 0; __i < __x.size(); ++__i)
545 __tmp[__i] = __c + __x[__i];
550 inline valarray<_Tp> _STLP_CALL operator-(const valarray<_Tp>& __x, const _Tp& __c) {
551 typedef typename valarray<_Tp>::_NoInit _NoInit;
552 valarray<_Tp> __tmp(__x.size(), _NoInit());
553 for (size_t __i = 0; __i < __x.size(); ++__i)
554 __tmp[__i] = __x[__i] - __c;
559 inline valarray<_Tp> _STLP_CALL operator-(const _Tp& __c, const valarray<_Tp>& __x) {
560 typedef typename valarray<_Tp>::_NoInit _NoInit;
561 valarray<_Tp> __tmp(__x.size(), _NoInit());
562 for (size_t __i = 0; __i < __x.size(); ++__i)
563 __tmp[__i] = __c - __x[__i];
568 inline valarray<_Tp> _STLP_CALL operator^(const valarray<_Tp>& __x, const _Tp& __c) {
569 typedef typename valarray<_Tp>::_NoInit _NoInit;
570 valarray<_Tp> __tmp(__x.size(), _NoInit());
571 for (size_t __i = 0; __i < __x.size(); ++__i)
572 __tmp[__i] = __x[__i] ^ __c;
577 inline valarray<_Tp> _STLP_CALL operator^(const _Tp& __c, const valarray<_Tp>& __x) {
578 typedef typename valarray<_Tp>::_NoInit _NoInit;
579 valarray<_Tp> __tmp(__x.size(), _NoInit());
580 for (size_t __i = 0; __i < __x.size(); ++__i)
581 __tmp[__i] = __c ^ __x[__i];
586 inline valarray<_Tp> _STLP_CALL operator&(const valarray<_Tp>& __x, const _Tp& __c) {
587 typedef typename valarray<_Tp>::_NoInit _NoInit;
588 valarray<_Tp> __tmp(__x.size(), _NoInit());
589 for (size_t __i = 0; __i < __x.size(); ++__i)
590 __tmp[__i] = __x[__i] & __c;
595 inline valarray<_Tp> _STLP_CALL operator&(const _Tp& __c, const valarray<_Tp>& __x) {
596 typedef typename valarray<_Tp>::_NoInit _NoInit;
597 valarray<_Tp> __tmp(__x.size(), _NoInit());
598 for (size_t __i = 0; __i < __x.size(); ++__i)
599 __tmp[__i] = __c & __x[__i];
604 inline valarray<_Tp> _STLP_CALL operator|(const valarray<_Tp>& __x, const _Tp& __c) {
605 typedef typename valarray<_Tp>::_NoInit _NoInit;
606 valarray<_Tp> __tmp(__x.size(), _NoInit());
607 for (size_t __i = 0; __i < __x.size(); ++__i)
608 __tmp[__i] = __x[__i] | __c;
613 inline valarray<_Tp> _STLP_CALL operator|(const _Tp& __c, const valarray<_Tp>& __x) {
614 typedef typename valarray<_Tp>::_NoInit _NoInit;
615 valarray<_Tp> __tmp(__x.size(), _NoInit());
616 for (size_t __i = 0; __i < __x.size(); ++__i)
617 __tmp[__i] = __c | __x[__i];
622 inline valarray<_Tp> _STLP_CALL operator<<(const valarray<_Tp>& __x, const _Tp& __c) {
623 typedef typename valarray<_Tp>::_NoInit _NoInit;
624 valarray<_Tp> __tmp(__x.size(), _NoInit());
625 for (size_t __i = 0; __i < __x.size(); ++__i)
626 __tmp[__i] = __x[__i] << __c;
631 inline valarray<_Tp> _STLP_CALL operator<<(const _Tp& __c, const valarray<_Tp>& __x) {
632 typedef typename valarray<_Tp>::_NoInit _NoInit;
633 valarray<_Tp> __tmp(__x.size(), _NoInit());
634 for (size_t __i = 0; __i < __x.size(); ++__i)
635 __tmp[__i] = __c << __x[__i];
640 inline valarray<_Tp> _STLP_CALL operator>>(const valarray<_Tp>& __x, const _Tp& __c) {
641 typedef typename valarray<_Tp>::_NoInit _NoInit;
642 valarray<_Tp> __tmp(__x.size(), _NoInit());
643 for (size_t __i = 0; __i < __x.size(); ++__i)
644 __tmp[__i] = __x[__i] >> __c;
649 inline valarray<_Tp> _STLP_CALL operator>>(const _Tp& __c, const valarray<_Tp>& __x) {
650 typedef typename valarray<_Tp>::_NoInit _NoInit;
651 valarray<_Tp> __tmp(__x.size(), _NoInit());
652 for (size_t __i = 0; __i < __x.size(); ++__i)
653 __tmp[__i] = __c >> __x[__i];
657 // Binary logical operations between two arrays. Behavior is undefined
658 // if the two arrays have different lengths. Note that operator== does
659 // not do what you might at first expect.
662 inline _Valarray_bool _STLP_CALL operator==(const valarray<_Tp>& __x,
663 const valarray<_Tp>& __y)
665 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
666 for (size_t __i = 0; __i < __x.size(); ++__i)
667 __tmp[__i] = __x[__i] == __y[__i];
672 inline _Valarray_bool _STLP_CALL operator<(const valarray<_Tp>& __x,
673 const valarray<_Tp>& __y)
675 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
676 for (size_t __i = 0; __i < __x.size(); ++__i)
677 __tmp[__i] = __x[__i] < __y[__i];
681 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
684 inline _Valarray_bool _STLP_CALL operator!=(const valarray<_Tp>& __x,
685 const valarray<_Tp>& __y)
687 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
688 for (size_t __i = 0; __i < __x.size(); ++__i)
689 __tmp[__i] = __x[__i] != __y[__i];
694 inline _Valarray_bool _STLP_CALL operator>(const valarray<_Tp>& __x,
695 const valarray<_Tp>& __y)
697 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
698 for (size_t __i = 0; __i < __x.size(); ++__i)
699 __tmp[__i] = __x[__i] > __y[__i];
704 inline _Valarray_bool _STLP_CALL operator<=(const valarray<_Tp>& __x,
705 const valarray<_Tp>& __y)
707 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
708 for (size_t __i = 0; __i < __x.size(); ++__i)
709 __tmp[__i] = __x[__i] <= __y[__i];
714 inline _Valarray_bool _STLP_CALL operator>=(const valarray<_Tp>& __x,
715 const valarray<_Tp>& __y)
717 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
718 for (size_t __i = 0; __i < __x.size(); ++__i)
719 __tmp[__i] = __x[__i] >= __y[__i];
723 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
727 inline _Valarray_bool _STLP_CALL operator&&(const valarray<_Tp>& __x,
728 const valarray<_Tp>& __y)
730 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
731 for (size_t __i = 0; __i < __x.size(); ++__i)
732 __tmp[__i] = __x[__i] && __y[__i];
737 inline _Valarray_bool _STLP_CALL operator||(const valarray<_Tp>& __x,
738 const valarray<_Tp>& __y)
740 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
741 for (size_t __i = 0; __i < __x.size(); ++__i)
742 __tmp[__i] = __x[__i] || __y[__i];
746 // Logical operations between an array and a scalar.
749 inline _Valarray_bool _STLP_CALL operator==(const valarray<_Tp>& __x, const _Tp& __c)
751 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
752 for (size_t __i = 0; __i < __x.size(); ++__i)
753 __tmp[__i] = __x[__i] == __c;
758 inline _Valarray_bool _STLP_CALL operator==(const _Tp& __c, const valarray<_Tp>& __x)
760 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
761 for (size_t __i = 0; __i < __x.size(); ++__i)
762 __tmp[__i] = __c == __x[__i];
767 inline _Valarray_bool _STLP_CALL operator!=(const valarray<_Tp>& __x, const _Tp& __c)
769 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
770 for (size_t __i = 0; __i < __x.size(); ++__i)
771 __tmp[__i] = __x[__i] != __c;
776 inline _Valarray_bool _STLP_CALL operator!=(const _Tp& __c, const valarray<_Tp>& __x)
778 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
779 for (size_t __i = 0; __i < __x.size(); ++__i)
780 __tmp[__i] = __c != __x[__i];
785 inline _Valarray_bool _STLP_CALL operator<(const valarray<_Tp>& __x, const _Tp& __c)
787 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
788 for (size_t __i = 0; __i < __x.size(); ++__i)
789 __tmp[__i] = __x[__i] < __c;
794 inline _Valarray_bool _STLP_CALL operator<(const _Tp& __c, const valarray<_Tp>& __x)
796 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
797 for (size_t __i = 0; __i < __x.size(); ++__i)
798 __tmp[__i] = __c < __x[__i];
803 inline _Valarray_bool _STLP_CALL operator>(const valarray<_Tp>& __x, const _Tp& __c)
805 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
806 for (size_t __i = 0; __i < __x.size(); ++__i)
807 __tmp[__i] = __x[__i] > __c;
812 inline _Valarray_bool _STLP_CALL operator>(const _Tp& __c, const valarray<_Tp>& __x)
814 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
815 for (size_t __i = 0; __i < __x.size(); ++__i)
816 __tmp[__i] = __c > __x[__i];
821 inline _Valarray_bool _STLP_CALL operator<=(const valarray<_Tp>& __x, const _Tp& __c)
823 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
824 for (size_t __i = 0; __i < __x.size(); ++__i)
825 __tmp[__i] = __x[__i] <= __c;
830 inline _Valarray_bool _STLP_CALL operator<=(const _Tp& __c, const valarray<_Tp>& __x)
832 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
833 for (size_t __i = 0; __i < __x.size(); ++__i)
834 __tmp[__i] = __c <= __x[__i];
839 inline _Valarray_bool _STLP_CALL operator>=(const valarray<_Tp>& __x, const _Tp& __c)
841 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
842 for (size_t __i = 0; __i < __x.size(); ++__i)
843 __tmp[__i] = __x[__i] >= __c;
848 inline _Valarray_bool _STLP_CALL operator>=(const _Tp& __c, const valarray<_Tp>& __x)
850 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
851 for (size_t __i = 0; __i < __x.size(); ++__i)
852 __tmp[__i] = __c >= __x[__i];
857 inline _Valarray_bool _STLP_CALL operator&&(const valarray<_Tp>& __x, const _Tp& __c)
859 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
860 for (size_t __i = 0; __i < __x.size(); ++__i)
861 __tmp[__i] = __x[__i] && __c;
866 inline _Valarray_bool _STLP_CALL operator&&(const _Tp& __c, const valarray<_Tp>& __x)
868 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
869 for (size_t __i = 0; __i < __x.size(); ++__i)
870 __tmp[__i] = __c && __x[__i];
875 inline _Valarray_bool _STLP_CALL operator||(const valarray<_Tp>& __x, const _Tp& __c)
877 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
878 for (size_t __i = 0; __i < __x.size(); ++__i)
879 __tmp[__i] = __x[__i] || __c;
884 inline _Valarray_bool _STLP_CALL operator||(const _Tp& __c, const valarray<_Tp>& __x)
886 _Valarray_bool __tmp(__x.size(), _Valarray_bool::_NoInit());
887 for (size_t __i = 0; __i < __x.size(); ++__i)
888 __tmp[__i] = __c || __x[__i];
892 // valarray "transcendentals" (the list includes abs and sqrt, which,
893 // of course, are not transcendental).
896 inline valarray<_Tp> abs(const valarray<_Tp>& __x) {
897 typedef typename valarray<_Tp>::_NoInit _NoInit;
898 valarray<_Tp> __tmp(__x.size(), _NoInit());
899 for (size_t __i = 0; __i < __x.size(); ++__i)
900 __tmp[__i] = _STLP_DO_ABS(_Tp)(__x[__i]);
905 inline valarray<_Tp> acos(const valarray<_Tp>& __x) {
906 typedef typename valarray<_Tp>::_NoInit _NoInit;
907 valarray<_Tp> __tmp(__x.size(), _NoInit());
908 for (size_t __i = 0; __i < __x.size(); ++__i)
909 __tmp[__i] = _STLP_DO_ACOS(_Tp)(__x[__i]);
914 inline valarray<_Tp> asin(const valarray<_Tp>& __x) {
915 typedef typename valarray<_Tp>::_NoInit _NoInit;
916 valarray<_Tp> __tmp(__x.size(), _NoInit());
917 for (size_t __i = 0; __i < __x.size(); ++__i)
918 __tmp[__i] = _STLP_DO_ASIN(_Tp)(__x[__i]);
923 inline valarray<_Tp> atan(const valarray<_Tp>& __x) {
924 typedef typename valarray<_Tp>::_NoInit _NoInit;
925 valarray<_Tp> __tmp(__x.size(), _NoInit());
926 for (size_t __i = 0; __i < __x.size(); ++__i)
927 __tmp[__i] = _STLP_DO_ATAN(_Tp)(__x[__i]);
932 inline valarray<_Tp> atan2(const valarray<_Tp>& __x,
933 const valarray<_Tp>& __y) {
934 typedef typename valarray<_Tp>::_NoInit _NoInit;
935 valarray<_Tp> __tmp(__x.size(), _NoInit());
936 for (size_t __i = 0; __i < __x.size(); ++__i)
937 __tmp[__i] = _STLP_DO_ATAN2(_Tp)(__x[__i], __y[__i]);
942 inline valarray<_Tp> atan2(const valarray<_Tp>& __x, const _Tp& __c) {
943 typedef typename valarray<_Tp>::_NoInit _NoInit;
944 valarray<_Tp> __tmp(__x.size(), _NoInit());
945 for (size_t __i = 0; __i < __x.size(); ++__i)
946 __tmp[__i] = _STLP_DO_ATAN2(_Tp)(__x[__i], __c);
951 inline valarray<_Tp> atan2(const _Tp& __c, const valarray<_Tp>& __x) {
952 typedef typename valarray<_Tp>::_NoInit _NoInit;
953 valarray<_Tp> __tmp(__x.size(), _NoInit());
954 for (size_t __i = 0; __i < __x.size(); ++__i)
955 __tmp[__i] = _STLP_DO_ATAN2(_Tp)(__c, __x[__i]);
960 inline valarray<_Tp> cos(const valarray<_Tp>& __x) {
961 typedef typename valarray<_Tp>::_NoInit _NoInit;
962 valarray<_Tp> __tmp(__x.size(), _NoInit());
963 for (size_t __i = 0; __i < __x.size(); ++__i)
964 __tmp[__i] = _STLP_DO_COS(_Tp)(__x[__i]);
969 inline valarray<_Tp> cosh(const valarray<_Tp>& __x) {
970 typedef typename valarray<_Tp>::_NoInit _NoInit;
971 valarray<_Tp> __tmp(__x.size(), _NoInit());
972 for (size_t __i = 0; __i < __x.size(); ++__i)
973 __tmp[__i] = _STLP_DO_COSH(_Tp)(__x[__i]);
978 inline valarray<_Tp> exp(const valarray<_Tp>& __x) {
979 typedef typename valarray<_Tp>::_NoInit _NoInit;
980 valarray<_Tp> __tmp(__x.size(), _NoInit());
981 for (size_t __i = 0; __i < __x.size(); ++__i)
982 __tmp[__i] = _STLP_DO_EXP(_Tp)(__x[__i]);
987 inline valarray<_Tp> log(const valarray<_Tp>& __x) {
988 typedef typename valarray<_Tp>::_NoInit _NoInit;
989 valarray<_Tp> __tmp(__x.size(), _NoInit());
990 for (size_t __i = 0; __i < __x.size(); ++__i)
991 __tmp[__i] = _STLP_DO_LOG(_Tp)(__x[__i]);
996 inline valarray<_Tp> log10(const valarray<_Tp>& __x) {
997 typedef typename valarray<_Tp>::_NoInit _NoInit;
998 valarray<_Tp> __tmp(__x.size(), _NoInit());
999 for (size_t __i = 0; __i < __x.size(); ++__i)
1000 __tmp[__i] = _STLP_DO_LOG10(_Tp)(__x[__i]);
1004 template <class _Tp>
1005 inline valarray<_Tp> pow(const valarray<_Tp>& __x,
1006 const valarray<_Tp>& __y) {
1007 typedef typename valarray<_Tp>::_NoInit _NoInit;
1008 valarray<_Tp> __tmp(__x.size(), _NoInit());
1009 for (size_t __i = 0; __i < __x.size(); ++__i)
1010 __tmp[__i] = _STLP_DO_POW(_Tp)(__x[__i], __y[__i]);
1014 template <class _Tp>
1015 inline valarray<_Tp> pow(const valarray<_Tp>& __x, const _Tp& __c) {
1016 typedef typename valarray<_Tp>::_NoInit _NoInit;
1017 valarray<_Tp> __tmp(__x.size(), _NoInit());
1018 for (size_t __i = 0; __i < __x.size(); ++__i)
1019 __tmp[__i] = _STLP_DO_POW(_Tp)(__x[__i], __c);
1023 template <class _Tp>
1024 inline valarray<_Tp> pow(const _Tp& __c, const valarray<_Tp>& __x) {
1025 typedef typename valarray<_Tp>::_NoInit _NoInit;
1026 valarray<_Tp> __tmp(__x.size(), _NoInit());
1027 for (size_t __i = 0; __i < __x.size(); ++__i)
1028 __tmp[__i] = _STLP_DO_POW(_Tp)(__c, __x[__i]);
1032 template <class _Tp>
1033 inline valarray<_Tp> sin(const valarray<_Tp>& __x) {
1034 typedef typename valarray<_Tp>::_NoInit _NoInit;
1035 valarray<_Tp> __tmp(__x.size(), _NoInit());
1036 for (size_t __i = 0; __i < __x.size(); ++__i)
1037 __tmp[__i] = _STLP_DO_SIN(_Tp)(__x[__i]);
1041 template <class _Tp>
1042 inline valarray<_Tp> sinh(const valarray<_Tp>& __x) {
1043 typedef typename valarray<_Tp>::_NoInit _NoInit;
1044 valarray<_Tp> __tmp(__x.size(), _NoInit());
1045 for (size_t __i = 0; __i < __x.size(); ++__i)
1046 __tmp[__i] = _STLP_DO_SINH(_Tp)(__x[__i]);
1050 template <class _Tp>
1051 inline valarray<_Tp> sqrt(const valarray<_Tp>& __x) {
1052 typedef typename valarray<_Tp>::_NoInit _NoInit;
1053 valarray<_Tp> __tmp(__x.size(), _NoInit());
1054 for (size_t __i = 0; __i < __x.size(); ++__i)
1055 __tmp[__i] = _STLP_DO_SQRT(_Tp)(__x[__i]);
1059 template <class _Tp>
1060 inline valarray<_Tp> tan(const valarray<_Tp>& __x) {
1061 typedef typename valarray<_Tp>::_NoInit _NoInit;
1062 valarray<_Tp> __tmp(__x.size(), _NoInit());
1063 for (size_t __i = 0; __i < __x.size(); ++__i)
1064 __tmp[__i] = _STLP_DO_TAN(_Tp)(__x[__i]);
1068 template <class _Tp>
1069 inline valarray<_Tp> tanh(const valarray<_Tp>& __x) {
1070 typedef typename valarray<_Tp>::_NoInit _NoInit;
1071 valarray<_Tp> __tmp(__x.size(), _NoInit());
1072 for (size_t __i = 0; __i < __x.size(); ++__i)
1073 __tmp[__i] = _STLP_DO_TANH(_Tp)(__x[__i]);
1077 //----------------------------------------------------------------------
1078 // slice and slice_array
1082 slice() : _M_start(0), _M_length(0), _M_stride(0) {}
1083 slice(size_t __start, size_t __length, size_t __stride)
1084 : _M_start(__start), _M_length(__length), _M_stride(__stride)
1086 __TRIVIAL_DESTRUCTOR(slice)
1088 size_t start() const { return _M_start; }
1089 size_t size() const { return _M_length; }
1090 size_t stride() const { return _M_stride; }
1099 template <class _Tp>
1101 friend class valarray<_Tp>;
1103 typedef _Tp value_type;
1105 void operator=(const valarray<value_type>& __x) const {
1106 size_t __index = _M_slice.start();
1107 for (size_t __i = 0;
1108 __i < _M_slice.size();
1109 ++__i, __index += _M_slice.stride())
1110 #ifdef __SYMBIAN32__
1111 (*_M_array)[__index] = __x[__i];
1113 _M_array[__index] = __x[__i];
1117 void operator*=(const valarray<value_type>& __x) const {
1118 size_t __index = _M_slice.start();
1119 for (size_t __i = 0;
1120 __i < _M_slice.size();
1121 ++__i, __index += _M_slice.stride())
1122 #ifdef __SYMBIAN32__
1123 (*_M_array)[__index] *= __x[__i];
1125 _M_array[__index] *= __x[__i];
1129 void operator/=(const valarray<value_type>& __x) const {
1130 size_t __index = _M_slice.start();
1131 for (size_t __i = 0;
1132 __i < _M_slice.size();
1133 ++__i, __index += _M_slice.stride())
1134 #ifdef __SYMBIAN32__
1135 (*_M_array)[__index] /= __x[__i];
1137 _M_array[__index] /= __x[__i];
1141 void operator%=(const valarray<value_type>& __x) const {
1142 size_t __index = _M_slice.start();
1143 for (size_t __i = 0;
1144 __i < _M_slice.size();
1145 ++__i, __index += _M_slice.stride())
1146 #ifdef __SYMBIAN32__
1147 (*_M_array)[__index] %= __x[__i];
1149 _M_array[__index] %= __x[__i];
1153 void operator+=(const valarray<value_type>& __x) const {
1154 size_t __index = _M_slice.start();
1155 for (size_t __i = 0;
1156 __i < _M_slice.size();
1157 ++__i, __index += _M_slice.stride())
1158 #ifdef __SYMBIAN32__
1159 (*_M_array)[__index] += __x[__i];
1161 _M_array[__index] += __x[__i];
1165 void operator-=(const valarray<value_type>& __x) const {
1166 size_t __index = _M_slice.start();
1167 for (size_t __i = 0;
1168 __i < _M_slice.size();
1169 ++__i, __index += _M_slice.stride())
1170 #ifdef __SYMBIAN32__
1171 (*_M_array)[__index] -= __x[__i];
1173 _M_array[__index] -= __x[__i];
1177 void operator^=(const valarray<value_type>& __x) const {
1178 size_t __index = _M_slice.start();
1179 for (size_t __i = 0;
1180 __i < _M_slice.size();
1181 ++__i, __index += _M_slice.stride())
1182 #ifdef __SYMBIAN32__
1183 (*_M_array)[__index] ^= __x[__i];
1185 _M_array[__index] ^= __x[__i];
1189 void operator&=(const valarray<value_type>& __x) const {
1190 size_t __index = _M_slice.start();
1191 for (size_t __i = 0;
1192 __i < _M_slice.size();
1193 ++__i, __index += _M_slice.stride())
1194 #ifdef __SYMBIAN32__
1195 (*_M_array)[__index] &= __x[__i];
1197 _M_array[__index] &= __x[__i];
1201 void operator|=(const valarray<value_type>& __x) const {
1202 size_t __index = _M_slice.start();
1203 for (size_t __i = 0;
1204 __i < _M_slice.size();
1205 ++__i, __index += _M_slice.stride())
1206 #ifdef __SYMBIAN32__
1207 (*_M_array)[__index] |= __x[__i];
1209 _M_array[__index] |= __x[__i];
1213 void operator<<=(const valarray<value_type>& __x) const {
1214 size_t __index = _M_slice.start();
1215 for (size_t __i = 0;
1216 __i < _M_slice.size();
1217 ++__i, __index += _M_slice.stride())
1218 #ifdef __SYMBIAN32__
1219 (*_M_array)[__index] <<= __x[__i];
1221 _M_array[__index] <<= __x[__i];
1225 void operator>>=(const valarray<value_type>& __x) const {
1226 size_t __index = _M_slice.start();
1227 for (size_t __i = 0;
1228 __i < _M_slice.size();
1229 ++__i, __index += _M_slice.stride())
1230 #ifdef __SYMBIAN32__
1231 (*_M_array)[__index] >>= __x[__i];
1233 _M_array[__index] >>= __x[__i];
1237 void operator=(const value_type& __c) {
1238 size_t __index = _M_slice.start();
1239 for (size_t __i = 0;
1240 __i < _M_slice.size();
1241 ++__i, __index += _M_slice.stride())
1242 #ifdef __SYMBIAN32__
1243 (*_M_array)[__index] = __c;
1245 _M_array[__index] = __c;
1250 operator=(const slice_array<_Tp>& __a)
1252 size_t __index = _M_slice.start();
1253 for (size_t __i = __a._M_slice.start();
1254 __i < _M_slice.size();
1255 __i += __a._M_slice.stride(), __index += _M_slice.stride())
1256 _M_array[__index] = __a._M_array[__index][__i];
1260 slice_array(const slice_array<_Tp>& a)
1261 : _M_slice(a._M_slice), _M_array(a._M_array){}
1266 slice_array(const slice& __slice, valarray<_Tp>* __array)
1267 : _M_slice(__slice), _M_array(__array)
1271 valarray<_Tp>* _M_array;
1273 private: // Disable assignment and default constructor
1277 // valarray member functions dealing with slice and slice_array
1279 template <class _Tp>
1280 inline valarray<_Tp>::valarray(const slice_array<_Tp>& __x)
1281 : _Valarray_base<_Tp>(__x._M_slice.size())
1283 typedef typename __type_traits<_Tp>::has_trivial_default_constructor
1285 _M_initialize(_Is_Trivial());
1290 template <class _Tp>
1291 inline slice_array<_Tp> valarray<_Tp>::operator[](slice __slice) {
1292 return slice_array<_Tp>(__slice, this);
1295 //----------------------------------------------------------------------
1296 // gslice and gslice_array
1298 template <class _Size>
1299 struct _Gslice_Iter_tmpl;
1302 friend struct _Gslice_Iter_tmpl<size_t>;
1304 gslice() : _M_start(0), _M_lengths(0), _M_strides(0) {}
1305 gslice(size_t __start,
1306 const _Valarray_size_t& __lengths, const _Valarray_size_t& __strides)
1307 : _M_start(__start), _M_lengths(__lengths), _M_strides(__strides)
1309 __TRIVIAL_DESTRUCTOR(gslice)
1311 size_t start() const { return _M_start; }
1312 _Valarray_size_t size() const { return _M_lengths; }
1313 _Valarray_size_t stride() const { return _M_strides; }
1315 // Extension: check for an empty gslice.
1316 bool _M_empty() const { return _M_lengths.size() == 0; }
1318 // Extension: number of indices this gslice represents. (For a degenerate
1319 // gslice, they're not necessarily all distinct.)
1320 size_t _M_size() const {
1321 return !this->_M_empty()
1322 ? accumulate(_M_lengths._M_first + 1,
1323 _M_lengths._M_first + _M_lengths._M_size,
1325 multiplies<size_t>())
1334 _Valarray_size_t _M_lengths;
1335 _Valarray_size_t _M_strides;
1338 // This is not an STL iterator. It is constructed from a gslice, and it
1339 // steps through the gslice indices in sequence. See 23.3.6 of the C++
1340 // standard, paragraphs 2-3, for an explanation of the sequence. At
1341 // each step we get two things: the ordinal (i.e. number of steps taken),
1342 // and the one-dimensional index.
1344 template <class _Size>
1345 struct _Gslice_Iter_tmpl {
1346 _Gslice_Iter_tmpl(const gslice& __gslice)
1347 : _M_step(0), _M_1d_idx(__gslice.start()),
1348 _M_indices(size_t(0), __gslice._M_lengths.size()),
1352 bool _M_done() const { return _M_indices[0] == _M_gslice._M_lengths[0]; }
1359 valarray<_Size> _M_indices;
1360 const gslice& _M_gslice;
1363 typedef _Gslice_Iter_tmpl<size_t> _Gslice_Iter;
1365 template <class _Tp>
1366 class gslice_array {
1367 friend class valarray<_Tp>;
1369 typedef _Tp value_type;
1371 void operator= (const valarray<value_type>& __x) const {
1372 if (!_M_gslice._M_empty()) {
1373 _Gslice_Iter __i(_M_gslice);
1374 do _M_array[__i._M_1d_idx] = __x[__i._M_step]; while(__i._M_incr());
1378 void operator*= (const valarray<value_type>& __x) const {
1379 if (!_M_gslice._M_empty()) {
1380 _Gslice_Iter __i(_M_gslice);
1381 do _M_array[__i._M_1d_idx] *= __x[__i._M_step]; while(__i._M_incr());
1385 void operator/= (const valarray<value_type>& __x) const {
1386 if (!_M_gslice._M_empty()) {
1387 _Gslice_Iter __i(_M_gslice);
1388 do _M_array[__i._M_1d_idx] /= __x[__i._M_step]; while(__i._M_incr());
1392 void operator%= (const valarray<value_type>& __x) const {
1393 if (!_M_gslice._M_empty()) {
1394 _Gslice_Iter __i(_M_gslice);
1395 do _M_array[__i._M_1d_idx] %= __x[__i._M_step]; while(__i._M_incr());
1399 void operator+= (const valarray<value_type>& __x) const {
1400 if (!_M_gslice._M_empty()) {
1401 _Gslice_Iter __i(_M_gslice);
1402 do _M_array[__i._M_1d_idx] += __x[__i._M_step]; while(__i._M_incr());
1406 void operator-= (const valarray<value_type>& __x) const {
1407 if (!_M_gslice._M_empty()) {
1408 _Gslice_Iter __i(_M_gslice);
1409 do _M_array[__i._M_1d_idx] -= __x[__i._M_step]; while(__i._M_incr());
1413 void operator^= (const valarray<value_type>& __x) const {
1414 if (!_M_gslice._M_empty()) {
1415 _Gslice_Iter __i(_M_gslice);
1416 do _M_array[__i._M_1d_idx] ^= __x[__i._M_step]; while(__i._M_incr());
1420 void operator&= (const valarray<value_type>& __x) const {
1421 if (!_M_gslice._M_empty()) {
1422 _Gslice_Iter __i(_M_gslice);
1423 do _M_array[__i._M_1d_idx] &= __x[__i._M_step]; while(__i._M_incr());
1427 void operator|= (const valarray<value_type>& __x) const {
1428 if (!_M_gslice._M_empty()) {
1429 _Gslice_Iter __i(_M_gslice);
1430 do _M_array[__i._M_1d_idx] |= __x[__i._M_step]; while(__i._M_incr());
1434 void operator<<= (const valarray<value_type>& __x) const {
1435 if (!_M_gslice._M_empty()) {
1436 _Gslice_Iter __i(_M_gslice);
1437 do _M_array[__i._M_1d_idx] <<= __x[__i._M_step]; while(__i._M_incr());
1441 void operator>>= (const valarray<value_type>& __x) const {
1442 if (!_M_gslice._M_empty()) {
1443 _Gslice_Iter __i(_M_gslice);
1444 do _M_array[__i._M_1d_idx] >>= __x[__i._M_step]; while(__i._M_incr());
1448 void operator= (const value_type& __c) {
1449 if (!_M_gslice._M_empty()) {
1450 _Gslice_Iter __i(_M_gslice);
1451 do _M_array[__i._M_1d_idx] = __c; while(__i._M_incr());
1458 gslice_array(gslice __gslice, valarray<_Tp>& __array)
1459 : _M_gslice(__gslice), _M_array(__array)
1463 valarray<value_type>& _M_array;
1465 private: // Disable assignment
1466 void operator=(const gslice_array<_Tp>&);
1469 // valarray member functions dealing with gslice and gslice_array. Note
1470 // that it is illegal (behavior is undefined) to construct a gslice_array
1471 // from a degenerate gslice.
1473 template <class _Tp>
1474 inline valarray<_Tp>::valarray(const gslice_array<_Tp>& __x)
1475 : _Valarray_base<_Tp>(__x._M_gslice._M_size())
1477 typedef typename __type_traits<_Tp>::has_trivial_default_constructor
1479 _M_initialize(_Is_Trivial());
1483 template <class _Tp>
1484 inline gslice_array<_Tp> valarray<_Tp>::operator[](const gslice& __slice) {
1485 return gslice_array<_Tp>(__slice, *this);
1489 //----------------------------------------------------------------------
1492 template <class _Tp>
1494 friend class valarray<_Tp>;
1496 typedef _Tp value_type;
1498 void operator=(const valarray<value_type>& __x) const {
1500 #ifdef __SYMBIAN32__
1501 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1503 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1504 #endif // __SYMBIAN32__
1505 if (_M_mask[__i]) _M_array[__i] = __x[__idx++];
1508 void operator*=(const valarray<value_type>& __x) const {
1510 #ifdef __SYMBIAN32__
1511 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1513 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1514 #endif // __SYMBIAN32__
1515 if (_M_mask[__i]) _M_array[__i] *= __x[__idx++];
1518 void operator/=(const valarray<value_type>& __x) const {
1520 #ifdef __SYMBIAN32__
1521 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1523 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1524 #endif //__SYMBIAN32__
1525 if (_M_mask[__i]) _M_array[__i] /= __x[__idx++];
1528 void operator%=(const valarray<value_type>& __x) const {
1530 #ifdef __SYMBIAN32__
1531 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1533 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1535 if (_M_mask[__i]) _M_array[__i] %= __x[__idx++];
1538 void operator+=(const valarray<value_type>& __x) const {
1540 #ifdef __SYMBIAN32__
1541 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1543 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1545 if (_M_mask[__i]) _M_array[__i] += __x[__idx++];
1548 void operator-=(const valarray<value_type>& __x) const {
1550 #ifdef __SYMBIAN32__
1551 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1553 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1554 #endif //__SYMBIAN32__
1555 if (_M_mask[__i]) _M_array[__i] -= __x[__idx++];
1558 void operator^=(const valarray<value_type>& __x) const {
1560 #ifdef __SYMBIAN32__
1561 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1563 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1564 #endif // __SYMBIAN32__
1565 if (_M_mask[__i]) _M_array[__i] ^= __x[__idx++];
1568 void operator&=(const valarray<value_type>& __x) const {
1570 #ifdef __SYMBIAN32__
1571 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1573 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1574 #endif // __SYMBIAN32__
1575 if (_M_mask[__i]) _M_array[__i] &= __x[__idx++];
1578 void operator|=(const valarray<value_type>& __x) const {
1580 #ifdef __SYMBIAN32__
1581 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1583 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1584 #endif // __SYMBIAN32__
1585 if (_M_mask[__i]) _M_array[__i] |= __x[__idx++];
1588 void operator<<=(const valarray<value_type>& __x) const {
1590 #ifdef __SYMBIAN32__
1591 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1593 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1594 #endif // __SYMBIAN32__
1595 if (_M_mask[__i]) _M_array[__i] <<= __x[__idx++];
1598 void operator>>=(const valarray<value_type>& __x) const {
1600 #ifdef __SYMBIAN32__
1601 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1603 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1604 #endif // __SYMBIAN32__
1605 if (_M_mask[__i]) _M_array[__i] >>= __x[__idx++];
1608 void operator=(const value_type& __c) const {
1609 #ifdef __SYMBIAN32__
1610 for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
1612 for (size_t __i = 0; __i < _M_array.size(); ++__i)
1613 #endif // __SYMBIAN32__
1614 if (_M_mask[__i]) _M_array[__i] = __c;
1619 // Extension: number of true values in the mask
1620 size_t _M_num_true() const {
1621 size_t __result = 0;
1622 for (size_t __i = 0; __i < _M_mask.size(); ++__i)
1623 if (_M_mask[__i]) ++__result;
1628 mask_array(const _Valarray_bool& __mask, valarray<_Tp>& __array)
1629 : _M_mask(__mask), _M_array(__array)
1632 _Valarray_bool _M_mask;
1633 valarray<_Tp>& _M_array;
1635 private: // Disable assignment
1636 void operator=(const mask_array<_Tp>&);
1639 // valarray member functions dealing with mask_array
1641 template <class _Tp>
1642 inline valarray<_Tp>::valarray(const mask_array<_Tp>& __x)
1643 : _Valarray_base<_Tp>(__x._M_num_true())
1645 typedef typename __type_traits<_Tp>::has_trivial_default_constructor
1647 _M_initialize(_Is_Trivial());
1651 // Behavior is undefined if __x._M_num_true() != this->size()
1652 template <class _Tp>
1653 inline valarray<_Tp>& valarray<_Tp>::operator=(const mask_array<_Tp>& __x) {
1655 for (size_t __i = 0; __i < __x._M_array.size(); ++__i)
1656 if (__x._M_mask[__i])
1658 #ifdef __SYMBIAN32__
1659 if(__idx < this->_M_size)
1660 (*this)[__idx++] = __x._M_array[__i];
1664 (*this)[__idx++] = __x._M_array[__i];
1670 template <class _Tp>
1671 inline mask_array<_Tp> valarray<_Tp>::operator[](const _Valarray_bool& __mask)
1673 return mask_array<_Tp>(__mask, *this);
1677 //----------------------------------------------------------------------
1680 template <class _Tp>
1681 class indirect_array {
1682 friend class valarray<_Tp>;
1684 typedef _Tp value_type;
1686 void operator=(const valarray<value_type>& __x) const {
1687 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1688 _M_array[_M_addr[__i]] = __x[__i];
1691 void operator*=(const valarray<value_type>& __x) const {
1692 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1693 _M_array[_M_addr[__i]] *= __x[__i];
1696 void operator/=(const valarray<value_type>& __x) const {
1697 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1698 _M_array[_M_addr[__i]] /= __x[__i];
1701 void operator%=(const valarray<value_type>& __x) const {
1702 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1703 _M_array[_M_addr[__i]] %= __x[__i];
1706 void operator+=(const valarray<value_type>& __x) const {
1707 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1708 _M_array[_M_addr[__i]] += __x[__i];
1711 void operator-=(const valarray<value_type>& __x) const {
1712 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1713 _M_array[_M_addr[__i]] -= __x[__i];
1716 void operator^=(const valarray<value_type>& __x) const {
1717 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1718 _M_array[_M_addr[__i]] ^= __x[__i];
1721 void operator&=(const valarray<value_type>& __x) const {
1722 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1723 _M_array[_M_addr[__i]] &= __x[__i];
1726 void operator|=(const valarray<value_type>& __x) const {
1727 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1728 _M_array[_M_addr[__i]] |= __x[__i];
1731 void operator<<=(const valarray<value_type>& __x) const {
1732 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1733 _M_array[_M_addr[__i]] <<= __x[__i];
1736 void operator>>=(const valarray<value_type>& __x) const {
1737 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1738 _M_array[_M_addr[__i]] >>= __x[__i];
1741 void operator=(const value_type& __c) const {
1742 for (size_t __i = 0; __i < _M_addr.size(); ++__i)
1743 _M_array[_M_addr[__i]] = __c;
1746 ~indirect_array() {}
1749 indirect_array(const _Valarray_size_t& __addr, valarray<_Tp>& __array)
1750 : _M_addr(__addr), _M_array(__array)
1753 _Valarray_size_t _M_addr;
1754 valarray<_Tp>& _M_array;
1756 private: // Disable assignment
1757 void operator=(const indirect_array<_Tp>&);
1760 // valarray member functions dealing with indirect_array
1762 template <class _Tp>
1763 inline valarray<_Tp>::valarray(const indirect_array<_Tp>& __x)
1764 : _Valarray_base<_Tp>(__x._M_addr.size())
1766 typedef typename __type_traits<_Tp>::has_trivial_default_constructor
1768 _M_initialize(_Is_Trivial());
1773 template <class _Tp>
1774 inline indirect_array<_Tp>
1775 valarray<_Tp>::operator[](const _Valarray_size_t& __addr)
1777 return indirect_array<_Tp>(__addr, *this);
1782 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
1783 # include <stl/_valarray.c>
1786 #endif /* _STLP_VALARRAY */