DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

valarray(C++std)


gslice , gslice_array , indirect_array , mask_array , slice , slice_array , valarray , valarray<bool>

abs , acos , asin , atan , atan2 , cos , cosh , exp , log , log10 , operator!= , operator% , operator& , operator&& , operator> , operator>> , operator>= , operator< , operator<< , operator<= , operator* , operator+ , operator- , operator/ , operator== , operator^ , operator| , operator|| , pow , sin , sinh , sqrt , tan , tanh - defines several classes and template classes that support value-oriented arrays

Synopsis

   namespace std {
   class slice;
   class gslice;

           // TEMPLATE CLASSES
   template<class T>
       class valarray;
   template<class T>
       class slice_array;
   template<class T>
       class gslice_array;
   template<class T>
       class mask_array;
   template<class T>
       class indirect_array;

           // TEMPLATE FUNCTIONS
   template<class T>
       valarray<T> operator*(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator*(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator*(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator/(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator/(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator/(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator%(const valarray<T>& x,
           const vararray<T>& y);
   template<class T>
       valarray<T> operator%(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator%(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator+(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator+(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator+(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator-(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator-(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator-(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator^(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator^(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator^(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator&(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator&(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator&(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator|(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator|(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator|(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator<<(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator<<(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator<<(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator>>(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator>>(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator>>(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator&&(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator&&(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator&&(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator||(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator||(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator||(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator==(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator==(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator==(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator!=(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator!=(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator!=(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator<(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator<(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator<(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator>=(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator>=(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator>=(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator>(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator>(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator>(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator<=(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator<=(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator<=(const T& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> abs(const valarray<T>& x);
   template<class T>
       valarray<T> acos(const valarray<T>& x);
   template<class T>
       valarray<T> asin(const valarray<T>& x);
   template<class T>
       valarray<T> atan(const valarray<T>& x);
   template<class T>
       valarray<T> atan2(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> atan2(const valarray<T> x, const T& y);
   template<class T>
       valarray<T> atan2(const T& x, const valarray<T>& y);
   template<class T>
       valarray<T> cos(const valarray<T>& x);
   template<class T>
       valarray<T> cosh(const valarray<T>& x);
   template<class T>
       valarray<T> exp(const valarray<T>& x);
   template<class T>
       valarray<T> log(const valarray<T>& x);
   template<class T>
       valarray&tt;T> log10(const valarray<T>& x);
   template<class T>
       valarray<T> pow(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> pow(const valarray<T> x, const T& y);
   template<class T>
       valarray<T> pow(const T& x, const valarray<T>& y);
   template<class T>
       valarray<T> sin(const valarray<T>& x);
   template<class T>
       valarray<T> sinh(const valarray<T>& x);
   template<class T>
       valarray<T> sqrt(const valarray<T>& x);
   template<class T>
       valarray<T> tan(const valarray<T>& x);
   template<class T>
       valarray<T> tanh(const valarray<T>& x);
       };

Description

Include the standard header <valarray> to define the template class valarray and numerous supporting template classes and functions. These template classes and functions are permitted unusual latitude, in the interest of improved performance. Specifically, any function returning valarray<T> may return an object of some other type T'. In that case, any function that accepts one or more arguments of type valarray<T> must have overloads that accept arbitrary combinations of those arguments, each replaced with an argument of type T'. (Put simply, the only way you can detect such a substitution is to go looking for it.)

abs

   template<class T>
       valarray<T> abs(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the absolute value of x[I].

acos

   template<class T>
       valarray<T> acos(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the arccosine of x[I].

asin

   template<class T>
       valarray<T> asin(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the arcsine of x[I].

atan

   template<class T>
       valarray<T> atan(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the arctangent of x[I].

atan2

   template<class T>
       valarray<T> atan2(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> atan2(const valarray<T> x, const T& y);
   template<class T>
       valarray<T> atan2(const T& x, const valarray<T>& y);

The first template function returns an object of class valarray<T>, each of whose elements I is the arctangent of x[I] / y[I]. The second template function stores in element I the arctangent of x[I] / y. The third template function stores in element I the arctangent of x / y[I].

cos

   template<class T>
       valarray<T> cos(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the cosine of x[I].

cosh

   template<class T>
       valarray<T> cosh(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the hyperbolic cosine of x[I].

exp

   template<class T>
       valarray<T> exp(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the exponential of x[I].

gslice


gslice , start , size , stride

   class gslice {
   public:
       gslice();
       gslice(size_t st,
           const valarray<size_t> len,
           const valarray<size_t> str);
       size_t start() const;
       const valarray<size_t> size() const;
       const valarray<size_t> stride() const;
       };

The class stores the parameters that characterize a gslice_array when an object of class gslice appears as a subscript for an object of class valarray<T>. The stored values include:

The two vectors must have the same length.

gslice::gslice

   gslice();
   gslice(size_t st,
       const valarray<size_t> len,
       const valarray<size_t> str);

The default constructor stores zero for the starting index, and zero-length vectors for the length and stride vectors. The second constructor stores st for the starting index, len for the length vector, and str for the stride vector.

gslice::size

   const valarray<size_t> size() const;

The member function returns the stored length vector.

gslice::start

   size_t start() const;

The member function returns the stored starting index.

gslice::stride

   const valarray<size_t> stride() const;

The member function returns the stored stride vector.

gslice_array

   template<class T>
       class gslice_array {
   public:
       typedef T value_type;
       void operator=(const valarray<T> x) const;
       void operator=(const T& x);
       void operator*=(const valarray<T> x) const;
       void operator/=(const valarray<T> x) const;
       void operator%=(const valarray<T> x) const;
       void operator+=(const valarray<T> x) const;
       void operator-=(const valarray<T> x) const;
       void operator^=(const valarray<T> x) const;
       void operator&=(const valarray<T> x) const;
       void operator|=(const valarray<T> x) const;
       void operator<<=(const valarray<T> x) const;
       void operator>>=(const valarray<T> x) const;
   private:
       void gslice_array();  // not defined
       void gslice_array(
           const gslice_array&);  // not defined
       gslice_array& operator=(
           const gslice_array&);  // not defined
       };

The class describes an object that stores a reference to an object x of class valarray<T>, along with an object gs of class gslice which describes the sequence of elements to select from the valarray<T> object.

You construct a gslice_array<T> object only by writing an expression of the form x[gs]. The member functions of class gslice_array then behave like the corresponding function signatures defined for valarray<T>, except that only the sequence of selected elements is affected.

The sequence is determined as follows. For a length vector gs.size() of length N, construct the index vector valarray<size_t> idx(0, N). This designates the initial element of the sequence, whose index k within x is given by the mapping:

   k = start;
   for (size_t i = 0; i < gs.size()[i]; ++i)
       k += idx[i] * gs.stride()[i];

The successor to an index vector value is given by:

   for (size_t i = N; 0 < i--; )
       if (++idx[i] < gs.size()[i])
           break;
       else
           idx[i] = 0;

For example:

   const size_t lv[] = {2, 3};
   const size_t dv[] = {7, 2};
   const valarray<size_t> len(lv, 2), str(dv, 2);
   // x[gslice(3, len, str)] selects elements with
   //   indices 3, 5, 7, 10, 12, 14

indirect_array

   template<class T>
       class indirect_array {
   public:
       typedef T value_type;
       void operator=(const valarray<T> x) const;
       void operator=(const T& x);
       void operator*=(const valarray<T> x) const;
       void operator/=(const valarray<T> x) const;
       void operator%=(const valarray<T> x) const;
       void operator+=(const valarray<T> x) const;
       void operator-=(const valarray<T> x) const;
       void operator^=(const valarray<T> x) const;
       void operator&=(const valarray<T> x) const;
       void operator|=(const valarray<T> x) const;
       void operator<<=(const valarray<T> x) const;
       void operator>>=(const valarray<T> x) const;
   private:
   private:
       void indirect_array();  // not defined
       void indirect_array(
           const indirect_array&);  // not defined
       indirect_array& operator=(
           const indirect_array&);  // not defined
       };

The class describes an object that stores a reference to an object x of class valarray<T>, along with an object xa of class valarray<size_t> which describes the sequence of elements to select from the valarray<T> object.

You construct an indirect_array<T> object only by writing an expression of the form x[xa]. The member functions of class indirect_array then behave like the corresponding function signatures defined for valarray<T>, except that only the sequence of selected elements is affected.

The sequence consists of xa.size() elements, where element i becomes the index xa[i] within x. For example:

   const size_t vi[] = {7, 5, 2, 3, 8};
   // x[valarray<size_t>(vi, 5)] selects elements with
   //   indices 7, 5, 2, 3, 8

log

   template<class T>
       valarray<T> log(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the natural logarithm of x[I].

log10

   template<class T>
       valarray<T> log10(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the base-10 logarithm of x[I].

mask_array

   template<class T>
       class mask_array {
   public:
       typedef T value_type;
       void operator=(const valarray<T> x) const;
       void operator=(const T& x);
       void operator*=(const valarray<T> x) const;
       void operator/=(const valarray<T> x) const;
       void operator%=(const valarray<T> x) const;
       void operator+=(const valarray<T> x) const;
       void operator-=(const valarray<T> x) const;
       void operator^=(const valarray<T> x) const;
       void operator&=(const valarray<T> x) const;
       void operator|=(const valarray<T> x) const;
       void operator<<=(const valarray<T> x) const;
       void operator>>=(const valarray<T> x) const;
   private:
       void mask_array();  // not defined
       void mask_array(
           const mask_array&);  // not defined
       gslice_array& operator=(
           const mask_array&);  // not defined
       };

The class describes an object that stores a reference to an object x of class valarray<T>, along with an object ba of class valarray<bool> which describes the sequence of elements to select from the valarray<T> object.

You construct a mask_array<T> object only by writing an expression of the form x[xa]. The member functions of class mask_array then behave like the corresponding function signatures defined for valarray<T>, except that only the sequence of selected elements is affected.

The sequence consists of at most ba.size() elements. An element j is included only if ba[j] is true. Thus, there are as many elements in the sequence as there are true elements in ba. If i is the index of the lowest true element in ba, then x[i] is element zero in the selected sequence. For example:

   const bool vb[] = {false, false, true, true, false, true};
   // x[valarray<bool>(vb, 56] selects elements with
   //   indices 2, 3, 5

operator!=

   template<class T>
       valarray<bool> operator!=(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator!=(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator!=(const T& x,
          const valarray<T>& y);

The first template operator returns an object of class valarray<bool>, each of whose elements I is x[I] != y[I]. The second template operator stores in element I x[I] != y. The third template operator stores in element I x != y[I].

operator%

   template<class T>
       valarray<T> operator%(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator%(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator%(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] % y[I]. The second template operator stores in element I x[I] % y. The third template operator stores in element I x % y[I].

operator&

   template<class T>
       valarray<T> operator&(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator&(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator&(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] & y[I]. The second template operator stores in element I x[I] & y. The third template operator stores in element I x & y[I].

operator&&

   template<class T>
       valarray<bool> operator&&(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator&&(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator&&(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<bool>, each of whose elements I is x[I] && y[I]. The second template operator stores in element I x[I] && y. The third template operator stores in element I x && y[I].

operator>

   template<class T>
       valarray<bool> operator>(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator>(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator>(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<bool>, each of whose elements I is x[I] > y[I]. The second template operator stores in element I x[I] > y. The third template operator stores in element I x > y[I].

operator>>

   template<class T>
       valarray<T> operator>>(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator>>(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator>>(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] >> y[I]. The second template operator stores in element I x[I] >> y. The third template operator stores in element I x >> y[I].

operator>=

   template<class T>
       valarray<bool> operator>=(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator>=(const valarray<T> x, const T& y);
   template<class T>
       valarray<bool> operator>=(const T& x, const valarray<T>& y);

The first template operator returns an object of class valarray<bool>, each of whose elements I is x[I] >= y[I]. The second template operator stores in element I x[I] >= y. The third template operator stores in element I x >= y[I].

operator<

   template<class T>
       valarray<bool> operator<(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator<(const valarray<T> x, const T& y);
   template<class T>
       valarray<bool> operator<(const T& x, const valarray<T>& y);

The first template operator returns an object of class valarray<bool>, each of whose elements I is x[I] < y[I]. The second template operator stores in element I x[I] < y. The third template operator stores in element I x < y[I].

operator<<

   template<class T>
       valarray<T> operator<<(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator<<(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator<<(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] << y[I]. The second template operator stores in element I x[I] << y. The third template operator stores in element I x << y[I].

operator<=

   template<class T>
       valarray<bool> operator<=(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator<=(const valarray<T> x, const T& y);
   template<class T>
       valarray<bool> operator<=(const T& x, const valarray<T>& y);

The first template operator retrrns an object of class valarray<bool>, each of whose elements I is x[I] <= y[I]. The second template operator stores in element I x[I] <= y. The third template operator stores in element I x <= y[I].

operator*

   template<class T>
       valarray<T> operator*(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator*(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator*(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] * y[I]. The second template operator stores in element I x[I] * y. The third template operator stores in element I x * y[I].

operator+

   template<class T>
       valarray<T> operator+(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator+(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator+(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] + y[I]. The second template operator stores in element I x[I] + y. The third template operator stores in element I x + y[I].

operator-

   template<class T>
       valarray<T> operator-(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator-(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator-(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] - y[I]. The second template operator stores in element I x[I] - y. The third template operator stores in element I x - y[I].

operator/

   template<class T>
       valarray<T> operator/(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator/(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator/(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] / y[I]. The second template operator stores in element I x[I] / y. The third template operator stores in element I x / y[I].

operator==

   template<class T>
       valarray<bool> operator==(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator==(const valarray<T> x, const T& y);
   template<class T>
       valarray<bool> operator==(const T& x  const valarray<T>& y);

The first template operator returns an object of class valarray<bool>, each of whose elements I is x[I] == y[I]. The second template operator stores in element I x[I] == y. The third template operator stores in element I x == y[I].

operator^

   template<class T>
       valarray<T> operator^(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator^(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator^(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] ^ y[I]. The second template operator stores in element I x[I] ^ y. The third template operator stores in element I x ^ y[I].

operator|

   template<class T>
       valarray<T> operator|(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> operator|(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<T> operator|(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<T>, each of whose elements I is x[I] | y[I]. The second template operator stores in element I x[I] | y. The third template operator stores in element I x | y[I].

operator||

   template<class T>
       valarray<bool> operator||(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<bool> operator||(const valarray<T> x,
           const T& y);
   template<class T>
       valarray<bool> operator||(const T& x,
           const valarray<T>& y);

The first template operator returns an object of class valarray<bool>, each of whose elements I is x[I] || y[I]. The second template operator stores in element I x[I] || y. The third template operator stores in element I x || y[I].

pow

   template<class T>
       valarray<T> pow(const valarray<T>& x,
           const valarray<T>& y);
   template<class T>
       valarray<T> pow(const valarray<T> x, const T& y);
   template<class T>
       valarray<T> pow(const T& x, const valarray<T>& y);

The first template function returns an object of class valarray<T>, each of whose elements I is x[I] raised to the y[I] power. The second template function stores in element I x[I] raised to the y power. The third template function stores in element I x raised to the y[I] power.

sin

   template<class T>
       valarray<T> sin(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the sine of x[I].

sinh

   template<class T>
       valarray<T> sinh(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the hyperbolic sine of x[I].

slice


slice , start , size , stride

   class slice {
   public:
       slice();
       slice(size_t st, size_t len, size_t str);
       size_t start() const;
       size_t size() const;
       size_t stride() const;
       };

The class stores the parameters that characterize a slice_array when an object of class slice appears as a subscript for an object of class valarray<T>. The stored values include:

slice::slice

   slice();
   slice(size_t st,
           const valarray<size_t> len, const valarray<size_t> str);

The default constructor stores zeros for the starting index, total length, and stride. The second constructor stores st for the starting index, len for the total length, and str for the stride.

slice::size

   size_t size() const;

The member function returns the stored total length.

slice::start

   size_t start() const;

The member function returns the stored starting index.

slice::stride

   size_t stride() const;

The member function returns the stored stride.

slice_array

   template<class T>
       class slice_array {
   public:
       typedef T value_type;
       void operator=(const valarray<T> x) const;
       void operator=(const T& x);
       void operator*=(const valarray<T> x) const;
       void operator/=(const valarray<T> x) const;
       void operator%=(const valarray<T> x) const;
       void operator+=(const valarray<T> x) const;
       void operator-=(const valarray<T> x) const;
       void operator^=(const valarray<T> x) const;
       void operator&=(const valarray<T> x) const;
       void operator|=(const valarray<T> x) const;
       void operator<<=(const valarray<T> x) const;
       void operator>>=(const valarray<T> x) const;
   private:
       void slice_array();  // not defined
       void slice_array(
           const slice_array&);  // not defined
       slice_array& operator=(
           const slice_array&);  // not defined
       };

The class describes an object that stores a reference to an object x of class valarray<T>, along with an object sl of class slice which describes the sequence of elements to select from the valarray<T> object.

You construct a slice_array<T> object only by writing an expression of the form x[sl]. The member functions of class slice_array then behave like the corresponding function signatures defined for valarray<T>, except that only the sequence of selected elements is affected.

The sequence consists of sl.size() elements, where element i becomes the index sl.start() + i * sl.stride() within x. For example:

   // x[slice(2, 5, 3)] selects elements with
   //   indices 2, 5, 8, 11, 14

sqrt

   template<class T>
       valarray<T> sqrt(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the square root of x[I].

tan

   template<class T>
       valarray<T> tan(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the tangent of x[I].

tanh

   template<class T>
       valarray<T> tanh(const valarray<T>& x);

The template function returns an object of class valarray<T>, each of whose elements I is the hyperbolic tangent of x[I].

valarray


apply , cshift , max , min , operator T * , operator! , operator%= , operator&= , operator>>= , operator<<= , operator*= , operator+ , operator+= , operator- , operator-= , operator/= , operator= , operator[] , operator^= , operator|= , operator~ , resize , shift , size , sum , valarray , value_type

   template<class T>
       class valarray {
   public:
       typedef T value_type;
       valarray();
       explicit valarray(size_t n);
       valarray(const T& val, size_t n));
       valarray(const T *p, size_t n);
       valarray(const slice_array<T>& sa);
       valarray(const gslice_array<T>& ga);
       valarray(const mask_array<T>& ma);
       valarray(const indirect_array<T>& ia);
       valarray<T>& operator=(const valarray<T>& va);
       valarray<T>& operator=(const T& x);
       valarray<T>& operator=(const slice_array<T>& sa);
       valarray<T>& operator=(const gslice_array<T>& ga);
       valarray<T>& operator=(const mask_array<T>& ma);
       valarray<T>& operator=(const indirect_array<T>& ia);
       T operator[](size_t n) const;
       T& operator[](size_t n);
       valarray<T> operator[](slice sa) const;
       slice_array<T> operator[](slice sa);
       valarray<T> operator[](const gslice& ga) const;
       gslice_array<T> operator[](const gslice& ga);
       valarray<T>
           operator[](const valarray<bool>& ba) const;
       mask_array<T> operator[](const valarray<bool>& ba);
       valarray<T>
           operator[](const valarray<size_t>& xa) const;
       indirect_array<T>
           operator[](const valarray<size_t>& xa);
       valarray<T> operator+();
       valarray<T> operator-();
       valarray<T> operator~();
       valarray<bool> operator!();
       valarray<T>& operator*=(const valarray<T>& x);
       valarray<T>& operator*=(const T& x);
       valarray<T>& operator/=(const valarray<T>& x);
       valarray<T>& operator/=(const T& x);
       valarray<T>& operator%=(const valarray<T>& x);
       valarray<T>& operator%=(const T& x);
       valarray<T>& operator+=(const valarray<T>& x);
       valarray<T>& operator+=(const T& x);
       valarray<T>& operator-=(const valarray<T>& x);
       valarray<T>& operator-=(const T& x);
       valarray<T>& operator^=(const valarray<T>& x);
       valarray<T>& operator^=(const T& x);
       valarray<T>& operator&=(const valarray<T>& x);
       valarray<T>& operator&=(const T& x);
       valarray<T>& operator|=(const valarray<T>& x);
       valarray<T>& operator|=(const T& x);
       valarray<T>& operator<<=(const valarray<T>& x);
       valarray<T>& operator<<=(const T& x);
       valarray<T>& operator>>=(const valarray<T>& x);
       valarray<T>& operator>>=(const T& x);
       operator T *();
       operator const T *() const;
       size_t size() const;
       T sum() const;
       T max() const;
       T min() const;
       valarray<T> shift(int n) const;
       valarray<T> cshift(int n) const;
       valarray<T> apply(T fn(T)) const;
       valarray<T> apply(T fn(const T&)) const;
       void resize(size_t n);
       void resize(size_t n, const T& c);
      };

The template class describes an object that controls a varying-length sequence of elements of type T. The sequence is stored as an array of T. It differs from template class vector in two important ways:

An object of class T:

In particular, no subtle differences may exist between copy construction and default construction followed by assignment. And none of the operations on objects of class T may throw exceptions.

valarray::apply

   valarray<T> apply(T fn(T)) const;
   valarray<T> apply(T fn(const T&)) const;

The member function returns an object of class valarray<T>, of length size(), each of whose elements I is fn((*this)[I]).

valarray::cshift

   valarray<T> cshift(int n) const;

The member function returns an object of class valarray<T>, of length size(), each of whose elements I is (*this)[(I + n) % size()]. Thus, if element zero is taken as the leftmost element, a positive value of n shifts the elements circularly left n places.

valarray::max

   T max() const;

The member function returns the value of the largest element of *this, which must have nonzero length. If the length is greater than one, it compares values by applying operator< between pairs of corresponding elements of class T.

valarray::min

   T min() const;

The member function returns the value of the smallest element of *this, which must have nonzero length. If the length is greater than one, it compares values by applying operator< between pairs of elements of class T.

valarray::operator T *

   operator T *();
   operator const T *() const;

Both member functions return a pointer to the first element of the controlled array, which must have at least one element.

valarray::operator!

   valarray<bool> operator!();

The member operator returns an object of class valarray<bool>, of length size(), each of whose elements I is !(*this).

valarray::operator%=

   valarray<T>& operator%=(const valarray<T>& x);
   valarray<T>& operator%=(const T& x);

The member operator replaces each element I of *this with (*this)[I] % x[I]. It returns *this.

valarray::operator&=

   valarray<T>& operator&=(const valarray<T>& x);
   valarray<T>& operator&=(const T& x);

The member operator replaces each element I of *this with (*this)[I] & x[I]. It returns *this.

valarray::operator>>=

   valarray<T>& operator>>=(const valarray<T>& x);
   valarray<T>& operator>>=(const T& x);

The member operator replaces each element I of *this with (*this)[I] >> x[I]. It returns *this.

valarray::operator<<=

   valarray<T>& operator<<=(const valarray<T>& x);
   valarray<T>& operator<<=(const T& x);

The member operator replaces each element I of *this with (*this)[I] << x[I]. It returns *this.

valarray::operator*=

   valarray<T>& operator*=(const valarray<T>& x);
   valarray<T>& operator*=(const T& x);

The member operator replaces each element I of *this with (*this)[I] * x[I]. It returns *this.

valarray::operator+

   valarray<T> operator+();

The member operator returns an object of class valarray<T>, of length size(), each of whose elements I is (*this)[I].

valarray::operator+=

   valarray<T>& operator+=(const valarray<T>& x);
   valarray<T>& operator+=(const T& x);

The member operator replaces each element I of *this with (*this)[I] + x[I]. It returns *this.

valarray::operator-

   valarray<T> operator-();

The member operator returns an object of class valarray<T>, of length size(), each of whose elements I is -(*this)[I].

valarray::operator-=

   valarray<T>& operator-=(const valarray<T>& x);
   valarray<T>& operator-=(const T& x);

The member operator replaces each element I of *this with (*this)[I] - x[I]. It returns *this.

valarray::operator/=

   valarray<T>& operator/=(const valarray<T>& x);
   valarray<T>& operator/=(const T& x);

The member operator replaces each element I of *this with (*this)[I] / x[I]. It returns *this.

valarray::operator=

   valarray<T>& operator=(const valarray<T>& va);
       valarray<T>& operator=(const T& x);
   valarray<T>& operator=(const slice_array<T>& sa);
   valarray<T>& operator=(const gslice_array<T>& ga);
   valarray<T>& operator=(const mask_array<T>& ma);
   valarray<T>& operator=(const indirect_array<T>& ia);

The first member operator replaces the controlled sequence with a copy of the sequence controlled by va. The second member operator replaces each element of the controlled sequence with a copy of x. The remaining member operators replace those elements of the controlled sequence selected by their arguments, which are generated only by operator[]. If the value of a member in the replacement controlled sequence depends on a member in the initial controlled sequence, the result is undefined.

If the length of the controlled sequence changes, the result is generally undefined. In this

in this implementation, however, the effect is merely to invalidate any pointers or references to elements in the controlled sequence.

valarray::operator[]

   T& operator[](size_t n);
   slice_array<T> operator[](slice sa);
   gslice_array<T> operator[](const gslice& ga);
   mask_array<T> operator[](const valarray<bool>& ba);
   indirect_array<T> operator[](const valarray<size_t>& xa);

   T operator[](size_t n) const;
   valarray<T> operator[](slice sa) const;
   valarray<T> operator[](const gslice& ga) const;
   valarray<T> operator[](const valarray<bool>& ba) const;
   valarray<T> operator[](const valarray<size_t>& xa) const;

The member operator is overloaded to provide several ways to select sequences of elements from among those controlled by *this. The first group of five member operators work in conjunction with various overloads of operator= (and other assigning operators) to allow selective replacement (slicing) of the controlled sequence. The selected elements must exist.

The first member operator selects element n. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   v0[3] = 'A';
   // v0 == valarray<char>("abcAefghijklmnop", 16)

The second member operator selects those elements of the controlled sequence designated by sa. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   valarray<char> v1("ABCDE", 5);
   v0[slice(2, 5, 3)] = v1;
   // v0 == valarray<char>("abAdeBghCjkDmnEp", 16)

The third member operator selects those elements of the controlled sequence designated by ga. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   valarray<char> v1("ABCDEF", 6);
   const size_t lv[] = {2, 3};
   const size_t dv[] = {7, 2};
   const valarray<size_t> len(lv, 2), str(dv, 2);
   v0[gslice(3, len, str)] = v1;
   // v0 == valarray<char>("abcAeBgCijDlEnFp", 16)

The fourth member operator selects those elements of the controlled sequence designated by ba. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   valarray<char> v1("ABC", 3);
   const bool vb[] = {false, false, true, true, false, true};
   v0[valarray<bool>(vb, 6)] = v1;
   // v0 == valarray<char>("abABeCghijklmnop", 16)

The fifth member operator selects those elements of the controlled sequence designated by ia. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   valarray<char> v1("ABCDE", 5);
   const size_t vi[] = {7, 5, 2, 3, 8};
   v0[valarray<size_t>(vi, 5)] = v1;
   // v0 == valarray<char>("abCDeBgAEjklmnop", 16)

The second group of five member operators each construct an object that represents the value(s) selected. The selected elements must exist.

The sixth member operator returns the value of element n. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   // v0[3] returns 'd'

The seventh member operator returns an object of class valarray<T> containing those elements of the controlled sequence designated by sa. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   // v0[slice(2, 5, 3)] returns valarray<char>("cfilo", 5)

The eighth member operator selects those elements of the controlled sequence designated by ga. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   const size_t lv[] = {2, 3};
   const size_t dv[] = {7, 2};
   const valarray<size_t> len(lv, 2), str(dv, 2);
   // v0[gslice(3, len, str)] returns
   //    valarray<char>("dfhkmo", 6)

The ninth member operator selects those elements of the controlled sequence designated by ba. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   const bool vb[] = {false, false, true, true, false, true};
   // v0[valarray<bool>(vb, 6)] returns
   //    valarray<char>("cdf", 3)

The last member operator selects those elements of the controlled sequence designated by ia. For example:

   valarray<char> v0("abcdefghijklmnop", 16);
   const size_t vi[] = {7, 5, 2, 3, 8};
   // v0[valarray<size_t>(vi, 5)] returns
   //    valarray<char>("hfcdi", 5)

valarray::operator^=

   valarray<T>& operator^=(const valarray<T>& x);
   valarray<T>& operator^=(const T& x);

The member operator replaces each element I of *this with (*this)[I] ^ x[I]. It returns *this.

valarray::operator|=

   valarray<T>& operator|=(const valarray<T>& x);
   valarray<T>& operator|=(const T& x);

The member operator replaces each element I of *this with (*this)[I] | x[I]. It returns *this.

valarray::operator~

   valarray<T> operator~();

The member operator returns an object of class valarray<T>, of length size(), each of whose elements I is ~(*this)[I].

valarray::resize

   void resize(size_t n);
   void resize(size_t n, const T& c);

The member functions both ensure that size() henceforth returns n. If it must make the controlled sequence longer, the first member function appends elements with value T(), while the second member function appends elements with value c. To make the controlled sequence shorter, both member functions remove and delete elements with subscripts in the range [n, size()). Any pointers or references to elements in the controlled sequence are invalidated.

valarray::shift

   valarray<T> shift(int n) const;

The member function returns an object of class valarray<T>, of length size(), each of whose elements I is either (*this)[I + n], if I + n is a valid subscript, or T(). Thus, if element zero is taken as the leftmost element, a positive value of n shifts the elements left n places, with zero fill.

valarray::size

   size_t size() const;

The member function returns the number of elements in the array.

valarray::sum

   T sum() const;

The member function returns the sum of all elements of *this, which must have nonzero length. If the length is greater than one, it adds values to the sum by applying operator+= between pairs of elements of class T.

valarray::valarray

   valarray();
   explicit valarray(size_t n);
   valarray(const T& val, size_t n));
   valarray(const T *p, size_t n);
   valarray(const slice_array<T>& sa);
   valarray(const gslice_array<T>& ga);
   valarray(const mask_array<T>& ma);
   valarray(const indirect_array<T>& ia);

The first (default) constructor initializes the object to an empty array. The next three constructors each initialize the object to an array of n elements as follows:

Each of the remaining constructors initializes the object to a valarray<T> object determined by the argument.

valarray::value_type

   typedef T value_type;

The type is a synonym for the template parameter T.

valarray<bool>

   class valarray<bool>

The type is a specialization of template class valarray, for elements of type bool.

References

vector(C++std)
18 February 2000
© 2000 The Santa Cruz Operation, Inc. All rights reserved.

Copyright © 1992-1996 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.