epoc32/include/stdapis/stlportv5/stl/_valarray.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/stlport/stl/_valarray.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /*
     2  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
     3  * Copyright (c) 1999
     4  * Silicon Graphics Computer Systems, Inc.
     5  *
     6  * Copyright (c) 1999 
     7  * Boris Fomitchev
     8  *
     9  * This material is provided "as is", with absolutely no warranty expressed
    10  * or implied. Any use is at your own risk.
    11  *
    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.
    17  *
    18  */ 
    19 
    20 #ifndef _STLP_VALARRAY_H
    21 #define _STLP_VALARRAY_H
    22 
    23 #ifndef _STLP_CMATH_H_HEADER
    24 #include <stl/_cmath.h>
    25 #endif
    26 #ifndef _STLP_INTERNAL_NEW_HEADER
    27 #include <stl/_new.h>
    28 #endif
    29 #ifndef _STLP_INTERNAL_ALGO_H
    30 #include <stl/_algo.h>
    31 #endif
    32 #ifndef _STLP_INTERNAL_NUMERIC_H
    33 #include <stl/_numeric.h>
    34 #endif
    35 #ifndef _STLP_LIMITS_H
    36 #include <limits>
    37 #endif
    38 
    39 //To resolve the unidentified identifier __THROW_BAD_ALLOC 
    40 #include <stl/_alloc.h>
    41 
    42 _STLP_BEGIN_NAMESPACE
    43 
    44 class slice;
    45 class gslice;
    46 
    47 template <class _Tp> class valarray;
    48 typedef valarray<bool>    _Valarray_bool;
    49 typedef valarray<size_t>  _Valarray_size_t;
    50 
    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;
    55 
    56 //----------------------------------------------------------------------
    57 // class valarray
    58 
    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>.
    62 
    63 template <class _Tp> 
    64 struct _Valarray_base
    65 {
    66   _Tp*   _M_first;
    67   size_t _M_size;
    68 
    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(); }
    72 
    73   void _M_allocate(size_t __n) {
    74     if (__n != 0) {
    75 #ifdef __SYMBIAN32__
    76       _M_first = ::new _Tp[__n];
    77 #else
    78       _M_first = __STATIC_CAST(_Tp*, (malloc(__n * sizeof(_Tp))));
    79 #endif
    80       _M_size  = __n;
    81       if (_M_first == 0) {
    82         _M_size = 0;
    83         __THROW_BAD_ALLOC;
    84       }
    85     }
    86     else {
    87       _M_first = 0;
    88       _M_size = 0;
    89     }
    90   }
    91 
    92   void _M_deallocate() {
    93 #ifdef __SYMBIAN32__
    94     delete [] _M_first;
    95 #else
    96     free(_M_first);
    97 #endif
    98     _M_first = 0;
    99     _M_size = 0;
   100   }
   101 };
   102 
   103 template <class _Tp> 
   104 class valarray : private _Valarray_base<_Tp>
   105 {
   106   friend class gslice;
   107 
   108 public:
   109   typedef _Tp value_type;
   110 
   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,
   120                        this->_M_first);
   121   }
   122 
   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>&);
   128 
   129   // Destructor
   130   ~valarray() { _STLP_STD::_Destroy(this->_M_first, this->_M_first + this->_M_size); }
   131 
   132   // Extension: constructor that doesn't initialize valarray elements to a
   133   // specific value.  This is faster for types such as int and double.
   134 private:
   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()); }
   138 
   139 public:
   140   struct _NoInit {};
   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());
   144   }
   145 
   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())
   150     if (this != &__x)
   151       {
   152 #ifdef __SYMBIAN32__
   153       resize(__x._M_size);
   154 #endif
   155       copy(__x._M_first, __x._M_first + __x._M_size, this->_M_first);
   156       }
   157     return *this;
   158   }
   159 
   160   // Scalar assignment
   161   valarray<_Tp>& operator=(const value_type& __x) {
   162     fill_n(this->_M_first, this->_M_size, __x);
   163     return *this;
   164   }
   165 
   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>&);
   171 
   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; }
   176 
   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&);
   186   
   187 public:                         // Unary operators.
   188   valarray<_Tp> operator+() const { return *this; }
   189 
   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];
   194     return __tmp;
   195   }
   196   
   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];
   201     return __tmp;
   202   }
   203 
   204   _Valarray_bool operator!() const;
   205 
   206 public:                         // Scalar computed assignment.
   207   valarray<_Tp>& operator*= (const value_type& __x) {
   208     for (size_t __i = 0; __i < this->size(); ++__i)
   209       (*this)[__i] *= __x;
   210     return *this;
   211   }
   212     
   213   valarray<_Tp>& operator/= (const value_type& __x) {
   214     for (size_t __i = 0; __i < this->size(); ++__i)
   215       (*this)[__i] /= __x;
   216     return *this;
   217   }
   218 
   219   valarray<_Tp>& operator%= (const value_type& __x) {
   220     for (size_t __i = 0; __i < this->size(); ++__i)
   221       (*this)[__i] %= __x;
   222     return *this;
   223   }
   224 
   225   valarray<_Tp>& operator+= (const value_type& __x) {
   226     for (size_t __i = 0; __i < this->size(); ++__i)
   227       (*this)[__i] += __x;
   228     return *this;
   229   }
   230 
   231   valarray<_Tp>& operator-= (const value_type& __x) {
   232     for (size_t __i = 0; __i < this->size(); ++__i)
   233       (*this)[__i] -= __x;
   234     return *this;
   235   }
   236 
   237   valarray<_Tp>& operator^= (const value_type& __x) {
   238     for (size_t __i = 0; __i < this->size(); ++__i)
   239       (*this)[__i] ^= __x;
   240     return *this;
   241   }
   242 
   243   valarray<_Tp>& operator&= (const value_type& __x) {
   244     for (size_t __i = 0; __i < this->size(); ++__i)
   245       (*this)[__i] &= __x;
   246     return *this;
   247   }
   248 
   249   valarray<_Tp>& operator|= (const value_type& __x) {
   250     for (size_t __i = 0; __i < this->size(); ++__i)
   251       (*this)[__i] |= __x;
   252     return *this;
   253   }
   254 
   255   valarray<_Tp>& operator<<= (const value_type& __x) {
   256     for (size_t __i = 0; __i < this->size(); ++__i)
   257       (*this)[__i] <<= __x;
   258     return *this;
   259   }
   260 
   261   valarray<_Tp>& operator>>= (const value_type& __x) {
   262     for (size_t __i = 0; __i < this->size(); ++__i)
   263       (*this)[__i] >>= __x;
   264     return *this;
   265   }
   266 
   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];
   271     return *this;
   272   }
   273     
   274   valarray<_Tp>& operator/= (const valarray<_Tp>& __x) {
   275     for (size_t __i = 0; __i < this->size(); ++__i)
   276       (*this)[__i] /= __x[__i];
   277     return *this;
   278   }
   279 
   280   valarray<_Tp>& operator%= (const valarray<_Tp>& __x) {
   281     for (size_t __i = 0; __i < this->size(); ++__i)
   282       (*this)[__i] %= __x[__i];
   283     return *this;
   284   }
   285 
   286   valarray<_Tp>& operator+= (const valarray<_Tp>& __x) {
   287     for (size_t __i = 0; __i < this->size(); ++__i)
   288       (*this)[__i] += __x[__i];
   289     return *this;
   290   }
   291 
   292   valarray<_Tp>& operator-= (const valarray<_Tp>& __x) {
   293     for (size_t __i = 0; __i < this->size(); ++__i)
   294       (*this)[__i] -= __x[__i];
   295     return *this;
   296   }
   297 
   298   valarray<_Tp>& operator^= (const valarray<_Tp>& __x) {
   299     for (size_t __i = 0; __i < this->size(); ++__i)
   300       (*this)[__i] ^= __x[__i];
   301     return *this;
   302   }
   303 
   304   valarray<_Tp>& operator&= (const valarray<_Tp>& __x) {
   305     for (size_t __i = 0; __i < this->size(); ++__i)
   306       (*this)[__i] &= __x[__i];
   307     return *this;
   308   }
   309 
   310   valarray<_Tp>& operator|= (const valarray<_Tp>& __x) {
   311     for (size_t __i = 0; __i < this->size(); ++__i)
   312       (*this)[__i] |= __x[__i];
   313     return *this;
   314   }
   315 
   316   valarray<_Tp>& operator<<= (const valarray<_Tp>& __x) {
   317     for (size_t __i = 0; __i < this->size(); ++__i)
   318       (*this)[__i] <<= __x[__i];
   319     return *this;
   320   }
   321 
   322   valarray<_Tp>& operator>>= (const valarray<_Tp>& __x) {
   323     for (size_t __i = 0; __i < this->size(); ++__i)
   324       (*this)[__i] >>= __x[__i];
   325     return *this;
   326   }
   327 
   328 public:                         // Other member functions.
   329 
   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,
   333                       (*this)[0]);
   334   }
   335 
   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);
   339   }
   340 
   341   value_type (max) () const {
   342     return *max_element(this->_M_first + 0, this->_M_first + this->_M_size);
   343   }
   344 
   345   valarray<_Tp> shift(int __n) const;
   346   valarray<_Tp> cshift(int __n) const;
   347 
   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,
   351               __f);
   352     return __tmp;
   353   }
   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,
   357               __f);
   358     return __tmp;
   359   }
   360   
   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);
   366   }
   367 };
   368 
   369 //----------------------------------------------------------------------
   370 // valarray non-member functions.
   371 
   372 // Binary arithmetic operations between two arrays.  Behavior is
   373 // undefined if the two arrays do not have the same length.
   374 
   375 template <class _Tp> 
   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];
   382   return __tmp;
   383 }
   384 
   385 template <class _Tp> 
   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];
   392   return __tmp;
   393 }
   394 
   395 template <class _Tp> 
   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];
   402   return __tmp;
   403 }
   404 
   405 template <class _Tp> 
   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];
   412   return __tmp;
   413 }
   414 
   415 template <class _Tp> 
   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];
   422   return __tmp;
   423 }
   424 
   425 template <class _Tp> 
   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];
   432   return __tmp;
   433 }
   434 
   435 template <class _Tp> 
   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];
   442   return __tmp;
   443 }
   444 
   445 template <class _Tp> 
   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];
   452   return __tmp;
   453 }
   454 
   455 template <class _Tp> 
   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];
   462   return __tmp;
   463 }
   464 
   465 template <class _Tp> 
   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];
   472   return __tmp;
   473 }
   474 
   475 // Binary arithmetic operations between an array and a scalar.
   476 
   477 template <class _Tp> 
   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;
   483   return __tmp;
   484 }
   485 
   486 template <class _Tp> 
   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];
   492   return __tmp;
   493 }
   494 
   495 template <class _Tp> 
   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;
   501   return __tmp;
   502 }
   503 
   504 template <class _Tp> 
   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];
   510   return __tmp;
   511 }
   512 
   513 template <class _Tp> 
   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;
   519   return __tmp;
   520 }
   521 
   522 template <class _Tp> 
   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];
   528   return __tmp;
   529 }
   530 
   531 template <class _Tp> 
   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;
   537   return __tmp;
   538 }
   539 
   540 template <class _Tp> 
   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];
   546   return __tmp;
   547 }
   548 
   549 template <class _Tp> 
   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;
   555   return __tmp;
   556 }
   557 
   558 template <class _Tp> 
   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];
   564   return __tmp;
   565 }
   566 
   567 template <class _Tp> 
   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;
   573   return __tmp;
   574 }
   575 
   576 template <class _Tp> 
   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];
   582   return __tmp;
   583 }
   584 
   585 template <class _Tp> 
   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;
   591   return __tmp;
   592 }
   593 
   594 template <class _Tp> 
   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];
   600   return __tmp;
   601 }
   602 
   603 template <class _Tp> 
   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;
   609   return __tmp;
   610 }
   611 
   612 template <class _Tp> 
   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];
   618   return __tmp;
   619 }
   620 
   621 template <class _Tp> 
   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;
   627   return __tmp;
   628 }
   629 
   630 template <class _Tp> 
   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];
   636   return __tmp;
   637 }
   638 
   639 template <class _Tp> 
   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;
   645   return __tmp;
   646 }
   647 
   648 template <class _Tp> 
   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];
   654   return __tmp;
   655 }
   656 
   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.
   660 
   661 template <class _Tp> 
   662 inline _Valarray_bool _STLP_CALL operator==(const valarray<_Tp>& __x,
   663                                  const valarray<_Tp>& __y)
   664 {
   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];
   668   return __tmp;  
   669 }
   670 
   671 template <class _Tp> 
   672 inline _Valarray_bool _STLP_CALL operator<(const valarray<_Tp>& __x,
   673                                 const valarray<_Tp>& __y)
   674 {
   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];
   678   return __tmp;  
   679 }
   680 
   681 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
   682 
   683 template <class _Tp> 
   684 inline _Valarray_bool _STLP_CALL operator!=(const valarray<_Tp>& __x,
   685                                  const valarray<_Tp>& __y)
   686 {
   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];
   690   return __tmp;  
   691 }
   692 
   693 template <class _Tp> 
   694 inline _Valarray_bool _STLP_CALL operator>(const valarray<_Tp>& __x,
   695                                 const valarray<_Tp>& __y)
   696 {
   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];
   700   return __tmp;  
   701 }
   702 
   703 template <class _Tp> 
   704 inline _Valarray_bool _STLP_CALL operator<=(const valarray<_Tp>& __x,
   705                                  const valarray<_Tp>& __y)
   706 {
   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];
   710   return __tmp;  
   711 }
   712 
   713 template <class _Tp> 
   714 inline _Valarray_bool _STLP_CALL operator>=(const valarray<_Tp>& __x,
   715                                  const valarray<_Tp>& __y)
   716 {
   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];
   720   return __tmp;  
   721 }
   722 
   723 #endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
   724 // fbp : swap ?
   725 
   726 template <class _Tp> 
   727 inline _Valarray_bool _STLP_CALL operator&&(const valarray<_Tp>& __x,
   728                                  const valarray<_Tp>& __y)
   729 {
   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];
   733   return __tmp;  
   734 }
   735 
   736 template <class _Tp> 
   737 inline _Valarray_bool _STLP_CALL operator||(const valarray<_Tp>& __x,
   738                                  const valarray<_Tp>& __y)
   739 {
   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];
   743   return __tmp;  
   744 }
   745 
   746 // Logical operations between an array and a scalar.
   747 
   748 template <class _Tp>
   749 inline _Valarray_bool _STLP_CALL operator==(const valarray<_Tp>& __x, const _Tp& __c)
   750 {
   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;
   754   return __tmp;  
   755 }
   756 
   757 template <class _Tp>
   758 inline _Valarray_bool _STLP_CALL operator==(const _Tp& __c, const valarray<_Tp>& __x)
   759 {
   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];
   763   return __tmp;  
   764 }
   765 
   766 template <class _Tp>
   767 inline _Valarray_bool _STLP_CALL operator!=(const valarray<_Tp>& __x, const _Tp& __c)
   768 {
   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;
   772   return __tmp;  
   773 }
   774 
   775 template <class _Tp>
   776 inline _Valarray_bool _STLP_CALL operator!=(const _Tp& __c, const valarray<_Tp>& __x)
   777 {
   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];
   781   return __tmp;  
   782 }
   783 
   784 template <class _Tp>
   785 inline _Valarray_bool _STLP_CALL operator<(const valarray<_Tp>& __x, const _Tp& __c)
   786 {
   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;
   790   return __tmp;  
   791 }
   792 
   793 template <class _Tp>
   794 inline _Valarray_bool _STLP_CALL operator<(const _Tp& __c, const valarray<_Tp>& __x)
   795 {
   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];
   799   return __tmp;  
   800 }
   801 
   802 template <class _Tp>
   803 inline _Valarray_bool _STLP_CALL operator>(const valarray<_Tp>& __x, const _Tp& __c)
   804 {
   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;
   808   return __tmp;  
   809 }
   810 
   811 template <class _Tp>
   812 inline _Valarray_bool _STLP_CALL operator>(const _Tp& __c, const valarray<_Tp>& __x)
   813 {
   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];
   817   return __tmp;  
   818 }
   819 
   820 template <class _Tp>
   821 inline _Valarray_bool _STLP_CALL operator<=(const valarray<_Tp>& __x, const _Tp& __c)
   822 {
   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;
   826   return __tmp;  
   827 }
   828 
   829 template <class _Tp>
   830 inline _Valarray_bool _STLP_CALL operator<=(const _Tp& __c, const valarray<_Tp>& __x)
   831 {
   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];
   835   return __tmp;  
   836 }
   837 
   838 template <class _Tp>
   839 inline _Valarray_bool _STLP_CALL operator>=(const valarray<_Tp>& __x, const _Tp& __c)
   840 {
   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;
   844   return __tmp;  
   845 }
   846 
   847 template <class _Tp>
   848 inline _Valarray_bool _STLP_CALL operator>=(const _Tp& __c, const valarray<_Tp>& __x)
   849 {
   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];
   853   return __tmp;  
   854 }
   855 
   856 template <class _Tp>
   857 inline _Valarray_bool _STLP_CALL operator&&(const valarray<_Tp>& __x, const _Tp& __c)
   858 {
   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;
   862   return __tmp;  
   863 }
   864 
   865 template <class _Tp>
   866 inline _Valarray_bool _STLP_CALL operator&&(const _Tp& __c, const valarray<_Tp>& __x)
   867 {
   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];
   871   return __tmp;  
   872 }
   873 
   874 template <class _Tp>
   875 inline _Valarray_bool _STLP_CALL operator||(const valarray<_Tp>& __x, const _Tp& __c)
   876 {
   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;
   880   return __tmp;  
   881 }
   882 
   883 template <class _Tp>
   884 inline _Valarray_bool _STLP_CALL operator||(const _Tp& __c, const valarray<_Tp>& __x)
   885 {
   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];
   889   return __tmp;  
   890 }
   891 
   892 // valarray "transcendentals" (the list includes abs and sqrt, which,
   893 // of course, are not transcendental).
   894 
   895 template <class _Tp>
   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]);
   901   return __tmp;
   902 }
   903 
   904 template <class _Tp>
   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]);
   910   return __tmp;
   911 }
   912 
   913 template <class _Tp>
   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]);
   919   return __tmp;
   920 }
   921 
   922 template <class _Tp>
   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]);
   928   return __tmp;
   929 }
   930 
   931 template <class _Tp>
   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]);
   938   return __tmp;
   939 }
   940 
   941 template <class _Tp>
   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);
   947   return __tmp;
   948 }
   949 
   950 template <class _Tp>
   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]);
   956   return __tmp;
   957 }
   958 
   959 template <class _Tp>
   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]);
   965   return __tmp;
   966 }
   967 
   968 template <class _Tp>
   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]);
   974   return __tmp;
   975 }
   976 
   977 template <class _Tp>
   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]);
   983   return __tmp;
   984 }
   985 
   986 template <class _Tp>
   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]);
   992   return __tmp;
   993 }
   994 
   995 template <class _Tp>
   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]);
  1001   return __tmp;
  1002 }
  1003 
  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]);
  1011   return __tmp;
  1012 }
  1013 
  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);
  1020   return __tmp;
  1021 }
  1022 
  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]);
  1029   return __tmp;
  1030 }
  1031 
  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]);
  1038   return __tmp;
  1039 }
  1040 
  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]);
  1047   return __tmp;
  1048 }
  1049 
  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]);
  1056   return __tmp;
  1057 }
  1058 
  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]);
  1065   return __tmp;
  1066 }
  1067 
  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]);
  1074   return __tmp;
  1075 }
  1076 
  1077 //----------------------------------------------------------------------
  1078 // slice and slice_array
  1079 
  1080 class slice {
  1081 public:
  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)
  1085     {}
  1086   __TRIVIAL_DESTRUCTOR(slice)
  1087 
  1088   size_t start()  const { return _M_start; }
  1089   size_t size()   const { return _M_length; }
  1090   size_t stride() const { return _M_stride; }
  1091 
  1092    
  1093 private:
  1094   size_t _M_start;
  1095   size_t _M_length;
  1096   size_t _M_stride;
  1097 };
  1098 
  1099 template <class _Tp>
  1100 class slice_array {
  1101   friend class valarray<_Tp>;
  1102 public:
  1103   typedef _Tp value_type;
  1104 
  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];
  1112 #else
  1113       _M_array[__index] = __x[__i];
  1114 #endif
  1115   }
  1116 
  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];
  1124 #else
  1125         _M_array[__index] *= __x[__i];
  1126 #endif
  1127   }
  1128 
  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];
  1136 #else
  1137       _M_array[__index] /= __x[__i];
  1138 #endif
  1139   }
  1140 
  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];
  1148 #else
  1149       _M_array[__index] %= __x[__i];
  1150 #endif
  1151   }
  1152 
  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];
  1160 #else
  1161       _M_array[__index] += __x[__i];
  1162 #endif
  1163   }
  1164 
  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];
  1172 #else
  1173       _M_array[__index] -= __x[__i];
  1174 #endif
  1175   }
  1176 
  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];
  1184 #else
  1185       _M_array[__index] ^= __x[__i];
  1186 #endif
  1187   }
  1188 
  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];
  1196 #else
  1197       _M_array[__index] &= __x[__i];
  1198 #endif
  1199   }
  1200 
  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];
  1208 #else
  1209       _M_array[__index] |= __x[__i];
  1210 #endif
  1211   }
  1212 
  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];
  1220 #else
  1221       _M_array[__index] <<= __x[__i];
  1222 #endif
  1223   }
  1224 
  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];
  1232 #else
  1233       _M_array[__index] >>= __x[__i];
  1234 #endif
  1235   }
  1236 
  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;
  1244 #else
  1245       _M_array[__index] = __c;
  1246 #endif
  1247   }
  1248   
  1249   slice_array<_Tp>&
  1250     operator=(const slice_array<_Tp>& __a)
  1251     {
  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];
  1257     return *this;
  1258     }
  1259 
  1260     slice_array(const slice_array<_Tp>& a)
  1261       : _M_slice(a._M_slice), _M_array(a._M_array){}
  1262 
  1263   ~slice_array() {}
  1264 
  1265 private:
  1266   slice_array(const slice& __slice, valarray<_Tp>* __array)
  1267     : _M_slice(__slice), _M_array(__array)
  1268     {}
  1269 
  1270   slice          _M_slice;
  1271   valarray<_Tp>* _M_array;
  1272 
  1273 private:                        // Disable assignment and default constructor
  1274   slice_array();
  1275 };
  1276 
  1277 // valarray member functions dealing with slice and slice_array
  1278 
  1279 template <class _Tp>
  1280 inline valarray<_Tp>::valarray(const slice_array<_Tp>& __x)
  1281   : _Valarray_base<_Tp>(__x._M_slice.size())
  1282 {
  1283   typedef typename __type_traits<_Tp>::has_trivial_default_constructor
  1284           _Is_Trivial;
  1285   _M_initialize(_Is_Trivial());  
  1286   *this = __x;
  1287 }
  1288 
  1289 
  1290 template <class _Tp>
  1291 inline slice_array<_Tp> valarray<_Tp>::operator[](slice __slice) {
  1292   return slice_array<_Tp>(__slice, this);
  1293 }
  1294 
  1295 //----------------------------------------------------------------------
  1296 // gslice and gslice_array
  1297 
  1298 template <class _Size>
  1299 struct _Gslice_Iter_tmpl;
  1300 
  1301 class gslice {
  1302   friend struct _Gslice_Iter_tmpl<size_t>;
  1303 public:
  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)
  1308     {}
  1309   __TRIVIAL_DESTRUCTOR(gslice)
  1310 
  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; }
  1314 
  1315   // Extension: check for an empty gslice.
  1316   bool _M_empty() const { return _M_lengths.size() == 0; }
  1317 
  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,
  1324                    _M_lengths[0],
  1325                    multiplies<size_t>())
  1326       : 0;
  1327   }
  1328 
  1329 # ifndef __HP_aCC
  1330 private:
  1331 # endif
  1332 
  1333   size_t _M_start;
  1334   _Valarray_size_t _M_lengths;
  1335   _Valarray_size_t _M_strides;
  1336 };
  1337 
  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.
  1343 
  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()),
  1349       _M_gslice(__gslice)
  1350     {}
  1351     
  1352   bool _M_done() const { return _M_indices[0] == _M_gslice._M_lengths[0]; }
  1353 
  1354   bool _M_incr();
  1355 
  1356   _Size _M_step;
  1357   _Size _M_1d_idx;
  1358 
  1359   valarray<_Size> _M_indices;
  1360   const gslice& _M_gslice;
  1361 };
  1362 
  1363 typedef _Gslice_Iter_tmpl<size_t> _Gslice_Iter;
  1364 
  1365 template <class _Tp>
  1366 class gslice_array {
  1367   friend class valarray<_Tp>;
  1368 public:
  1369   typedef _Tp value_type;
  1370 
  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());
  1375     }
  1376   }
  1377 
  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());
  1382     }
  1383   }
  1384 
  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());
  1389     }
  1390   }
  1391 
  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());
  1396     }
  1397   }
  1398 
  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());
  1403     }
  1404   }
  1405 
  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());
  1410     }
  1411   }
  1412 
  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());
  1417     }
  1418   }
  1419 
  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());
  1424     }
  1425   }
  1426 
  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());
  1431     }
  1432   }
  1433 
  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());
  1438     }
  1439   }
  1440 
  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());
  1445     }
  1446   }
  1447 
  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());
  1452     }
  1453   }
  1454 
  1455   ~gslice_array() {}
  1456 
  1457 private:                        
  1458   gslice_array(gslice __gslice, valarray<_Tp>& __array)
  1459     : _M_gslice(__gslice), _M_array(__array)
  1460     {}
  1461 
  1462   gslice                _M_gslice;
  1463   valarray<value_type>& _M_array;
  1464 
  1465 private:                        // Disable assignment
  1466   void operator=(const gslice_array<_Tp>&);
  1467 };
  1468 
  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.
  1472 
  1473 template <class _Tp>
  1474 inline valarray<_Tp>::valarray(const gslice_array<_Tp>& __x)
  1475   : _Valarray_base<_Tp>(__x._M_gslice._M_size())
  1476 {
  1477   typedef typename __type_traits<_Tp>::has_trivial_default_constructor
  1478           _Is_Trivial;
  1479   _M_initialize(_Is_Trivial());  
  1480   *this = __x;
  1481 }
  1482 
  1483 template <class _Tp>
  1484 inline gslice_array<_Tp> valarray<_Tp>::operator[](const gslice& __slice) {
  1485   return gslice_array<_Tp>(__slice, *this);
  1486 }
  1487 
  1488 
  1489 //----------------------------------------------------------------------
  1490 // mask_array
  1491 
  1492 template <class _Tp>
  1493 class mask_array {
  1494   friend class valarray<_Tp>;
  1495 public:
  1496   typedef _Tp value_type;
  1497 
  1498   void operator=(const valarray<value_type>& __x) const {
  1499     size_t __idx = 0;
  1500 #ifdef __SYMBIAN32__    
  1501     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1502 #else    
  1503     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1504 #endif // __SYMBIAN32__    
  1505       if (_M_mask[__i]) _M_array[__i] = __x[__idx++];
  1506   }
  1507 
  1508   void operator*=(const valarray<value_type>& __x) const {
  1509     size_t __idx = 0;
  1510 #ifdef __SYMBIAN32__    
  1511     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1512 #else    
  1513     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1514 #endif // __SYMBIAN32__    
  1515       if (_M_mask[__i]) _M_array[__i] *= __x[__idx++];
  1516   }
  1517 
  1518   void operator/=(const valarray<value_type>& __x) const {
  1519     size_t __idx = 0;
  1520 #ifdef __SYMBIAN32__    
  1521     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1522 #else    
  1523     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1524 #endif //__SYMBIAN32__    
  1525       if (_M_mask[__i]) _M_array[__i] /= __x[__idx++];
  1526   }
  1527 
  1528   void operator%=(const valarray<value_type>& __x) const {
  1529     size_t __idx = 0;
  1530 #ifdef __SYMBIAN32__    
  1531     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1532 #else        
  1533     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1534 #endif    
  1535       if (_M_mask[__i]) _M_array[__i] %= __x[__idx++];
  1536   }
  1537 
  1538   void operator+=(const valarray<value_type>& __x) const {
  1539     size_t __idx = 0;
  1540 #ifdef __SYMBIAN32__    
  1541     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1542 #else            
  1543     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1544 #endif    
  1545       if (_M_mask[__i]) _M_array[__i] += __x[__idx++];
  1546   }
  1547 
  1548   void operator-=(const valarray<value_type>& __x) const {
  1549     size_t __idx = 0;
  1550 #ifdef __SYMBIAN32__    
  1551     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1552 #else            
  1553     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1554 #endif //__SYMBIAN32__    
  1555       if (_M_mask[__i]) _M_array[__i] -= __x[__idx++];
  1556   }
  1557   
  1558   void operator^=(const valarray<value_type>& __x) const {
  1559     size_t __idx = 0;
  1560 #ifdef __SYMBIAN32__    
  1561     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1562 #else            
  1563     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1564 #endif // __SYMBIAN32__    
  1565       if (_M_mask[__i]) _M_array[__i] ^= __x[__idx++];
  1566   }
  1567 
  1568   void operator&=(const valarray<value_type>& __x) const {
  1569     size_t __idx = 0;
  1570 #ifdef __SYMBIAN32__    
  1571     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1572 #else            
  1573     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1574 #endif // __SYMBIAN32__    
  1575       if (_M_mask[__i]) _M_array[__i] &= __x[__idx++];
  1576   }
  1577 
  1578   void operator|=(const valarray<value_type>& __x) const {
  1579     size_t __idx = 0;
  1580 #ifdef __SYMBIAN32__    
  1581     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1582 #else            
  1583     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1584 #endif // __SYMBIAN32__    
  1585       if (_M_mask[__i]) _M_array[__i] |= __x[__idx++];
  1586   }
  1587 
  1588   void operator<<=(const valarray<value_type>& __x) const {
  1589     size_t __idx = 0;
  1590 #ifdef __SYMBIAN32__    
  1591     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1592 #else            
  1593     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1594 #endif // __SYMBIAN32__    
  1595       if (_M_mask[__i]) _M_array[__i] <<= __x[__idx++];
  1596   }
  1597 
  1598   void operator>>=(const valarray<value_type>& __x) const {
  1599     size_t __idx = 0;
  1600 #ifdef __SYMBIAN32__    
  1601     for (size_t __i = 0; __i < _M_array.size() && __i < _M_mask.size(); ++__i)
  1602 #else            
  1603     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1604 #endif // __SYMBIAN32__    
  1605       if (_M_mask[__i]) _M_array[__i] >>= __x[__idx++];
  1606   }
  1607 
  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)
  1611 #else          
  1612     for (size_t __i = 0; __i < _M_array.size(); ++__i)
  1613 #endif // __SYMBIAN32__    
  1614       if (_M_mask[__i]) _M_array[__i] = __c;
  1615   }
  1616 
  1617   ~mask_array() {}
  1618 
  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;
  1624     return __result;
  1625   }
  1626 
  1627 private:
  1628   mask_array(const _Valarray_bool& __mask, valarray<_Tp>& __array)
  1629     : _M_mask(__mask), _M_array(__array)
  1630     {}
  1631 
  1632   _Valarray_bool _M_mask;
  1633   valarray<_Tp>& _M_array;
  1634 
  1635 private:                        // Disable assignment
  1636   void operator=(const mask_array<_Tp>&);
  1637 };
  1638 
  1639 // valarray member functions dealing with mask_array
  1640 
  1641 template <class _Tp>
  1642 inline valarray<_Tp>::valarray(const mask_array<_Tp>& __x)
  1643   : _Valarray_base<_Tp>(__x._M_num_true())
  1644 {
  1645   typedef typename __type_traits<_Tp>::has_trivial_default_constructor
  1646           _Is_Trivial;
  1647   _M_initialize(_Is_Trivial());  
  1648   *this = __x;
  1649 }
  1650 
  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) {
  1654   size_t __idx = 0;
  1655   for (size_t __i = 0; __i < __x._M_array.size(); ++__i)
  1656     if (__x._M_mask[__i]) 
  1657     {
  1658 #ifdef __SYMBIAN32__
  1659     if(__idx < this->_M_size)
  1660         (*this)[__idx++] = __x._M_array[__i];
  1661     else
  1662         break;
  1663 #else
  1664    (*this)[__idx++] = __x._M_array[__i];
  1665 #endif
  1666     }
  1667   return *this;
  1668 }
  1669 
  1670 template <class _Tp>
  1671 inline mask_array<_Tp> valarray<_Tp>::operator[](const _Valarray_bool& __mask)
  1672 {
  1673   return mask_array<_Tp>(__mask, *this);
  1674 }
  1675 
  1676 
  1677 //----------------------------------------------------------------------
  1678 // indirect_array
  1679 
  1680 template <class _Tp>
  1681 class indirect_array {
  1682   friend class valarray<_Tp>;
  1683 public:
  1684   typedef _Tp value_type;
  1685 
  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];
  1689   }
  1690 
  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];
  1694   }
  1695 
  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];
  1699   }
  1700 
  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];
  1704   }
  1705 
  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];
  1709   }
  1710 
  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];
  1714   }
  1715 
  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];
  1719   }
  1720 
  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];
  1724   }
  1725 
  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];
  1729   }
  1730 
  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];
  1734   }
  1735 
  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];
  1739   }
  1740 
  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;
  1744   }
  1745 
  1746   ~indirect_array() {}
  1747 
  1748 private:
  1749   indirect_array(const _Valarray_size_t& __addr, valarray<_Tp>& __array)
  1750     : _M_addr(__addr), _M_array(__array)
  1751     {}
  1752 
  1753   _Valarray_size_t _M_addr;
  1754   valarray<_Tp>&   _M_array;
  1755 
  1756 private:                        // Disable assignment
  1757   void operator=(const indirect_array<_Tp>&);
  1758 };
  1759 
  1760 // valarray member functions dealing with indirect_array
  1761 
  1762 template <class _Tp>
  1763 inline valarray<_Tp>::valarray(const indirect_array<_Tp>& __x)
  1764   : _Valarray_base<_Tp>(__x._M_addr.size())
  1765 {
  1766   typedef typename __type_traits<_Tp>::has_trivial_default_constructor
  1767           _Is_Trivial;
  1768   _M_initialize(_Is_Trivial());  
  1769   *this = __x;
  1770 }
  1771 
  1772 
  1773 template <class _Tp>
  1774 inline indirect_array<_Tp>
  1775 valarray<_Tp>::operator[](const _Valarray_size_t& __addr)
  1776 {
  1777   return indirect_array<_Tp>(__addr, *this);
  1778 }
  1779 
  1780 _STLP_END_NAMESPACE
  1781 
  1782 # if !defined (_STLP_LINK_TIME_INSTANTIATION)
  1783 #  include <stl/_valarray.c>
  1784 # endif
  1785 
  1786 #endif /* _STLP_VALARRAY */
  1787 
  1788 
  1789 // Local Variables:
  1790 // mode:C++
  1791 // End: