## valarray

    Container

- Summary
- Data Type and Member Function Indexes
- Synopsis
- Description
- Interface
- Constructors
- Destructors
- Assignment Operators
- Reference Operators
- Subset Operators
- Unary Operators
- Computed Assignment Operators
- Member Functions
- Non-member Binary Operators
- Non-member Logical Operators
- Non-member Transcendental Functions
- Example

### Summary

An optimized array class for numeric operations.

### Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Member Functions
abs() acos() apply() asin() atan() atan2() cos() cosh() cshift() exp() log() log10() max() min() | operator!() operator!=() operator%() operator%=() operator&&() operator&() operator&=() operator>>() operator>>=() operator>() operator>=() operator<<() operator<<=() | operator<() operator<=() operator*() operator*=() operator+() operator+=() operator-() operator-=() operator/() operator/=() operator=() operator==() operator[]() | operator^() operator^=() operator~() pow() resize() shift() sin() sinh() size() sqrt() sum() tan() tanh()

### Synopsis

    #include <valarray>
    template <class T >
    class valarray ;

### Description

valarray<T> and associated classes (slice_array, gslice_array, mask_array, and indirect_array) represent and manipulate one dimensional arrays of values. Elements in a valarray are indexed sequentially beginning with zero.

Unlike other classes in the Standard Library, valarray<T> can only be used with a fairly narrow range of types. This restriction ensures that numeric operations on a valarray can be as efficient as possible by avoiding aliasing ambiguities and excess temporaries.

### Interface

    template <class T> class valarray {
    public:

    // types
    typedef T value_type;

    // constructors
    valarray( );
    explicit valarray(size_t);
    valarray(const T&, size_t);
    valarray(const T* , size_t);
    valarray(const valarray<T>&);
    valarray(const slice_array<T>&);
    valarray(const gslice_array<T>&);
    valarray(const mask_array<T>&);
    valarray(const indirect_array<T>&);

    // destructor
    ~valarray();

    // operator =
    valarray<T>& operator= (const valarray<T>&);
    valarray<T>& operator= (const slice_array<T>&);
    valarray<T>& operator= (const gslice_array<T>&);
    valarray<T>& operator= (const mask_array<T>&);
    valarray<T>& operator= (const indirect_array<T>&);
    valarray<T>& operator= (const T&);
    // operator[]
    T operator[] (size_t) const;
    T& operator[] (size_t);
    valarray<T> operator[](slice) const;
    inline slice_array<T> operator[](slice);
    valarray<T> operator[](const gslice&) const;
    inline gslice_array<T> operator[](const gslice&);
    valarray<T> operator[](const valarray<bool>&) const;
    inline mask_array<T> operator[](const valarray<bool>&);
    valarray<T> operator[](const valarray<size_t>&) const;
    inline indirect_array<T> operator[](const valarray<size_t>&);

    // unary operators
    valarray<T> operator+() const;
    valarray<T> operator-() const;
    valarray<T> operator~() const;
    valarray<bool> operator!() const;

    // computed assignment
    valarray<T>& operator*= (const valarray<T>&);
    valarray<T>& operator/= (const valarray<T>&);
    valarray<T>& operator+= (const valarray<T>&);
    valarray<T>& operator-= (const valarray<T>&);
    valarray<T>& operator%= (const valarray<T>&);
    valarray<T>& operator^= (const valarray<T>&);
    valarray<T>& operator&= (const valarray<T>&);
    valarray<T>& operator|= (const valarray<T>&);
    valarray<T>& operator<<= (const valarray<T>&);
    valarray<T>& operator>>= (const valarray<T>&);
    valarray<T>& operator*= (const T&);
    valarray<T>& operator/= (const T&);
    valarray<T>& operator%= (const T&);
    valarray<T>& operator+= (const T&);
    valarray<T>& operator-= (const T&);
    valarray<T>& operator^= (const T&);
    valarray<T>& operator&= (const T&);
    valarray<T>& operator|= (const T&);
    valarray<T>& operator<<= (const T&);
    valarray<T>& operator>>= (const T&);

    // others
    size_t size() const;
    T sum() const;
    T min() const;
    T max() const;

    valarray<T> shift(int) const;
    valarray<T> cshift(int) const;

    valarray<T> apply(T func(T)) const;
    valarray<T> apply(T func(const T&)) const;
    void free();
    void resize(size_t, const T& = T() );
    };

    // Non-member binary operators
    template<class T> valarray<T>
    operator* (const valarray<T>& , const valarray<T>&  );
    template<class T> valarray<T>
    operator/ (const valarray<T>& , const valarray<T>& );
    template<class T> valarray<T>
    operator% (const valarray<T>&, const valarray<T>&);
    template<class T> valarray<T>
    operator+ (const valarray<T>& , const valarray<T>& );
    template<class T> valarray<T>
    operator- (const valarray<T>& , const valarray<T>& );
    template<class T> valarray<T>
    operator^ (const valarray<T>&, const valarray<T>&);
    template<class T> valarray<T>
    operator& (const valarray<T>&, const valarray<T>&);
    template<class T> valarray<T>
    operator| (const valarray<T>&, const valarray<T>&);
    template<class T> valarray<T>
    operator<< (const valarray<T>&, const valarray<T>&);
    template<class T> valarray<T>
    operator>> (const valarray<T>&, const valarray<T>&);

    template<class T> valarray<T>
    operator* (const valarray<T>& , const T& );
    template<class T> valarray<T>
    operator/ (const valarray<T>& , const T& );
    template<class T> valarray<T>
    operator% (const valarray<T>&, const T&);
    template<class T> valarray<T>
    operator+ (const valarray<T>& , const T& );
    template<class T> valarray<T>
    operator- (const valarray<T>& , const T& );
    template<class T> valarray<T>
    operator^ (const valarray<T>&, const T&);
    template<class T> valarray<T>
    operator& (const valarray<T>&, const T&);
    template<class T> valarray<T>
    operator| (const valarray<T>&, const T&);
    template<class T> valarray<T>
    operator<< (const valarray<T>&, const T&);
    template<class T> valarray<T>
    operator>> (const valarray<T>&, const T&);

    template<class T> valarray<T>
    operator* (const T& , const valarray<T>& );
    template<class T> valarray<T>
    operator/ (const T& , const valarray<T>& );
    template<class T> valarray<T>
    operator% (const T&, const valarray<T>&);
    template<class T> valarray<T>
    operator+ (const T& , const valarray<T>& );
    template<class T> valarray<T>
    operator- (const T& , const valarray<T>& );
    template<class T> valarray<T>
    operator^ (const T&, const valarray<T>&);
    template<class T> valarray<T>
    operator& (const T&, const valarray<T>&);
    template<class T> valarray<T>
    operator| (const T&, const valarray<T>&);
    template<class T> valarray<T>
    operator<< (const T&, const valarray<T>&);
    template<class T> valarray<T>
    operator>> (const T&, const valarray<T>&);

    // Non-member logical operators

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

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

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

    // non-member transcendental functions

    template<class T> valarray<T> abs(const valarray<T>& );
    template<class T> valarray<T> acos(const valarray<T>& );
    template<class T> valarray<T> asin(const valarray<T>& );
    template<class T> valarray<T> atan(const valarray<T>& );
    template<class T> valarray<T> cos(const valarray<T>& );
    template<class T> valarray<T> cosh(const valarray<T>& );
    template<class T> valarray<T> exp(const valarray<T>& );
    template<class T> valarray<T> log(const valarray<T>& );
    template<class T> valarray<T> log10(const valarray<T>& );
    template<class T> valarray<T> sinh(const valarray<T>& );
    template<class T> valarray<T> sin(const valarray<T>& );
    template<class T> valarray<T> sqrt(const valarray<T>& );
    template<class T> valarray<T> tan(const valarray<T>& );
    template<class T> valarray<T> tanh(const valarray<T>& );

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

### Constructors

    valarray();

Creates a valarray of length zero.

    explicit valarray(size_t n);

Creates a valarray of length `n`, containing `n` values initialized with the default value for type `T`. `T` must have a default constructor.

    explicit valarray(const T& value, size_t n);

Creates a valarray of length `n`, containing `n` values initialized with `value`.

    explicit valarray(const T* value, size_t n);

Creates a valarray of length `n`, containing `n` values initialized with the first `n` elements pointed to by `value`. The array pointed to by `value` must contain at least `n` values.

    valarray(const valarray<T>& x);

Creates a copy of `x`.

    valarray(const slice_array<T>& x);

Creates a valarray from the slice_array `x`.

    valarray(const gslice_array<T>& x);

Creates a valarray from the gslice_array `x`.

    valarray(const mask_array<T>& x);

Creates a valarray from the mask_array `x`.

    valarray(const indirect_array<T>& x);

Creates a valarray from the indirect_array `x`.

### Destructors

    ~valarray();

Applies `~T()` to every element in the valarray and returns all allocated memory.

### Assignment Operators

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

Assigns to each element of self the corresponding value from `x`. If self has more or fewer elements than `x`, then self is resized to match the size of `x`. Returns a reference to self.

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

Assigns to each element of self the value of `x`. Returns a reference to self.

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

Copies elements from `x` into self by stepping through each slice consecutively. If self has more or fewer elements than `x`, then self is resized to match the size of `x`. Returns a reference to self.

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

Copies elements from `x` into self by stepping through each slice consecutively. If self has more or fewer elements than `x`, then self is resized to match the size of `x`. Returns a reference to self.

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

Copies each consecutive element from `x` into self. If self has more or fewer elements than `x`, then self is resized to match the size of `x`. Returns a reference to self.

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

Copies each consecutive element from `x` into self. If self has more or fewer elements than `x`, then self is resized to match the size of `x`. Returns a reference to self.

### Reference Operators

    T& operator[](size_type n);

Returns a reference to element `n` of self. The result can be used as an `lvalue`. This reference is valid until the resize function is called or the array is destroyed. The index `n` must be between `0` and `size` less one.

    T operator[](size_type n) const;

Returns the value at element `n` of self. The index `n` must be between `0` and `size` less one.

### Subset Operators

    valarray<T> operator[](slice s) const;

Returns a subset of the self as specified by `s`. The return value is a new valarray object. See slice for a description of a BLAS-like slice.

    slice_array<T> operator[](slice s);

Returns a subset of the self as specified by `s`. The return value is a slice_array referencing elements inside self. See slice and slice_array.

    valarray<T> operator[](const gslice& s) const;

Returns a subset of the self as specified by `s`. The return value is a new valarray object. See gslice for a description of a generalized slice.

    gslice_array<T> operator[](const gslice& s);

Returns a subset of the self as specified by `s`. The return value is a gslice_array referencing elements inside self. See gslice and gslice_array.

    valarray<T> operator[](const valarray<bool>& v) const;

Returns a subset of the self as specified by `s`. The return value is a new valarray object.

    mask_array<T> operator[](const valarray<bool>& v);

Returns a subset of the self as specified by `s`. The return value is a mask_array referencing elements inside self. See mask_array.

    valarray<T> operator[](const valarray<size_t>& v) const;

Returns a subset of the self as specified by `s`. The return value is a new valarray object.

    Indirect_array<T> operator[](const valarray<size_t>& v);

Returns a subset of the self as specified by `s`. The return value is a indirect_array referencing elements inside self. See indirect_array.

### Unary Operators

    valarray<T> operator+() const;

Returns a new valarray object of the same size as the array in self where each element has been initialized by applying `operator+` to the corresponding element in self. This operation can only be applied to a valarray instantiated on a type `T` that supports an `operator+` that returns `T` or a type convertible to `T`.

    valarray<T> operator-() const;

Returns a new valarray object of the same size as the array in self where each element has been initialized by applying `operator-` to the corresponding element in self. This operation can only be applied to a valarray instantiated on a type `T` that supports an `operator-` returning `T` or a type convertible to `T`.

    valarray<T> operator~() const;

Returns a new valarray object of the same size as the array in self where each element has been initialized by applying `operator~` to the corresponding element in self. This operation can only be applied to a valarray instantiated on a type `T` that supports an `operator~` returning `T` or a type convertible to `T`.

    valarray<bool> operator!() const;

Returns a new valarray object of the same size as the array in self where each element has been initialized by applying `operator!` to the corresponding element in self. This operation can only be applied to a valarray instantiated on a type `T` that supports an `operator!` returning `bool` or a type convertible to `bool`.

### Computed Assignment Operators

    valarray<T>& operator*=(const valarray<T>& val);
    valarray<T>& operator/=(const valarray<T>& val);
    valarray<T>& operator%=(const valarray<T>& val);
    valarray<T>& operator+=(const valarray<T>& val);
    valarray<T>& operator-=(const valarray<T>& val);
    valarray<T>& operator^=(const valarray<T>& val);
    valarray<T>& operator&=(const valarray<T>& val);
    valarray<T>& operator|=(const valarray<T>& val);
    valarray<T>& operator<<=(const valarray<T>& val);
    valarray<T>& operator>>=(const valarray<T>& val);

Applies the indicated operation to each element in self, using the corresponding element from `val` as the right hand argument (for example, for all `0 <= n < *this.size(), *this[n] += val[n]`). This operation can only be applied to a valarray instantiated on a type `T` that supports the indicated operation. The length of `val` must also equal the length of self. Returns self.

    valarray<T>& operator*=(const T& val);
    valarray<T>& operator/=(const T& val);
    valarray<T>& operator%=(const T& val);
    valarray<T>& operator+=(const T& val);
    valarray<T>& operator-=(const T& val);
    valarray<T>& operator^=(const T& val);
    valarray<T>& operator&=(const T& val);
    valarray<T>& operator|=(const T& val);
    valarray<T>& operator<<=(const T& val);
    valarray<T>& operator>>=(const T& val);

Applies the indicated operation to each element in self, using `val` as the right hand argument (for example, for all `0 <= n < *this.size(), *this[n] += val`). This operation can only be applied to a valarray instantiated on a type `T` that supports the indicated operation. Returns self.

### Member Functions

    size_t size() const;

Returns the number of elements.

    T sum() const;

This function uses `operator+=` to sum all the elements of the array. Sum can only be called for a valarray instantiated on a type that supports `operator+=`. The array must also have at least one element. Returns the sum of all elements in the array.

    T min() const;

This function uses `operator<` to find the minimum element in the array. The array must have at least one element. Returns the minimum of all elements in the array.

    T max() const;

This function uses `operator>` to find the maximum element in the array. The array must have at least one element. Returns the maximum of all elements in the array.

    valarray<T> shift(int n) const;

This function returns a new valarray object whose elements have all been shifted `n` places to left or right with respect to self. A positive value of `n` shifts the elements to the left, a negative value to the right. The default constructor for `T` is used to fill in behind the shifting elements. For example, applying `shift(2)` to an array corresponding to [3,4,5,6] results in [5,6,0,0], and applying `shift(-1)` to [3,4,5,6] results in [0,3,4,5].

    valarray<T> cshift(int n) const;

This function returns a new valarray object whose elements have all been rotated `n` places to left or right with respect to self. A positive value of `n` shifts the elements to the left, a negative value to the right. For example, applying `shift(2)` to an array corresponding to [3,4,5,6] results in [5,6,3,4], and applying `shift(-1)` to [3,4,5,6] results in [6,3,4,5].

    valarray<T> apply(T func(T)) const;

This function returns a new valarray object with the same length as the array in self but whose elements have all been initialized by applying the argument function `func` to the corresponding element in self (in other words, for all `n < *this.size()`, the `nth` element of the returned array equals `func(*this[n]))`.

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

This function returns a new valarray object with the same length as the array in self but whose elements have all been initialized by applying the argument function `func` to the corresponding element in self (in other words, for all `0 <= n < *this.size()`, the `nth` element of the returned array equals `func(*this[n]))`.

    void
    resize(size_type sz, T c = T());

Changes the length of self to `sz`, and assigns `c` to every element. This function also invalidates all outstanding references to self.

### Non-member Binary Operators

    template <class T> valarray<T>
    operator*(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator/(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator%(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator+(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator-(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator^(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator&(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator|(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator<<(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator>>(const valarray<T>& lhs, const valarray<T>& rhs);

Returns a new valarray object of the same size as the argument arrays where each element has been initialized by applying the indicated operation to the corresponding elements in the argument arrays. The operation can only be applied to a valarray instantiated on a type `T` that supports a form of the indicated operation that returns `T` or a type convertible to `T`. The argument arrays must have the same length.

    template <class T> valarray<T>
    operator*(const valarray<T>& lhs, T& rhs);
    template <class T> valarray<T>
    operator/(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<T>
    operator%(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<T>
    operator+(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<T>
    operator-(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<T>
    operator^(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<T>
    operator&(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<T>
    operator|(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<T>
    operator<<(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<T>
    operator>>(const valarray<T>& lhs, const T& rhs);

Returns a new valarray object of the same size as the valarray `lhs` where each element has been initialized by applying the indicated operation to the corresponding element in `lhs` and the value `rhs`. The operation can only be used with a type `T` that supports a form of the indicated operation that returns `T` or a type convertible to `T`.

    template <class T> valarray<T>
    operator*(const T& rhs, valarray<T>& rhs);
    template <class T> valarray<T>
    operator/(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator%(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator+(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator-(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator^(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator&(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator|(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator<<(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<T>
    operator>>(const T& lhs, const valarray<T>& rhs);

Returns a new valarray object of the same size as the valarray `rhs` where each element has been initialized by applying the indicated operation to the corresponding element in `rhs` and the value `lhs`. The operation can only be used with a type `T` that supports a form of the indicated operation that returns `T` or a type convertible to `T`.

### Non-member Logical Operators

    template <class T> valarray<bool>
    operator==(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator!=(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator<(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator>(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator<=(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator>=(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator&&(const valarray<T>& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator||(const valarray<T>& lhs, const valarray<T>& rhs);

Returns a valarray<bool> object of the same size as the argument arrays where each element has been initialized by applying the indicated operation to the corresponding elements in the argument arrays. The operation can only be applied to a valarray instantiated on a type `T` that support a form of the indicated operation that returns `bool` or a type convertible to `bool`. The argument arrays must have the same length.

    template <class T> valarray<bool>
    operator==(const valarray<T>& lhs, T& rhs);
    template <class T> valarray<bool>
    operator!=(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<bool>
    operator<(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<bool>
    operator>(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<bool>
    operator<=(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<bool>
    operator>=(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<bool>
    operator&&(const valarray<T>& lhs, const T& rhs);
    template <class T> valarray<bool>
    operator||(const valarray<T>& lhs, const T& rhs);

Returns a valarray<bool> object of the same size as the valarray `lhs` where each element has been initialized by applying the indicated operation to the corresponding element in `lhs` and the value `rhs`. The operation can only be used with a type `T` that supports a form of the indicated operation that returns `bool` or a type convertible to `bool`.

    template <class T> valarray<bool>
    operator==(const T& rhs, valarray<T>& rhs);
    template <class T> valarray<bool>
    operator!=(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator<(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator>(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator<=(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator>=(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator&&(const T& lhs, const valarray<T>& rhs);
    template <class T> valarray<bool>
    operator||(const T& lhs, const valarray<T>& rhs);

Returns a valarray<bool> object of the same size as the valarray `rhs` where each element has been initialized by applying indicated operation to the corresponding element in `rhs` and the value `lhs`. The operation can only be used with a type `T` that supports a form of the indicated operation that returns `bool` or a type convertible to `bool`.

### Non-member Transcendental Functions

    template <class T> valarray<T> abs(const valarray<T>& v);
    template <class T> valarray<T> acos(const valarray<T>& v);
    template <class T> valarray<T> asin(const valarray<T>& v);
    template <class T> valarray<T> atan(const valarray<T>& v);
    template <class T> valarray<T> cos(const valarray<T>& v);
    template <class T> valarray<T> cosh(const valarray<T>& v);
    template <class T> valarray<T> exp(const valarray<T>& v);
    template <class T> valarray<T> log(const valarray<T>& v);
    template <class T> valarray<T> log10(const valarray<T>& v);
    template <class T> valarray<T> sin(const valarray<T>& v);
    template <class T> valarray<T> sinh(const valarray<T>& v);
    template <class T> valarray<T> sqrt(const valarray<T>& v);
    template <class T> valarray<T> tan(const valarray<T>& v);
    template <class T> valarray<T> tanh(const valarray<T>& v);

Returns a new valarray object of the same size as the argument array where each element has been initialized by applying the indicated transcendental function to the corresponding elements in the argument array. The operation can only be applied to a valarray instantiated on a type `T` that supports a unique form of the indicated function that returns `T` or a type convertible to `T`.

    template <class T> valarray<T>
    atan2(const valarray<T>& v, const valarray<T>& v2);
    template <class T> valarray<T>
    pow(const valarray<T>& v, const valarray<T>& v2);

Returns a new valarray object of the same size as the argument arrays where each element has been initialized by applying the indicated transcendental function to the corresponding elements in the argument arrays. The operation can only be applied to a valarray instantiated on a type `T` that supports a unique form of the indicated function that returns `T` or a type convertible to `T`.

    template <class T> valarray<T>
    atan2(const valarray<T>& v, const T& v2);
    template <class T> valarray<T>
    pow(const valarray<T>& v, const T& v2);

Returns a new valarray object of the same size as the argument array `v` where each element has been initialized by applying the indicated transcendental function to the corresponding elements in `v` along with the value `v2`. The operation can only be applied to a valarray instantiated on a type `T` that supports a unique form of the indicated function that returns `T` or a type convertible to `T`.

    template <class T> valarray<T>
    atan2(const T& v, const valarray<T> v2);
    template <class T> valarray<T>
    pow(const T& v, const valarray<T> v2);

Returns a new valarray object of the same size as the argument array `v2` where each element has been initialized by applying the indicated transcendental function to the corresponding elements in `v2` along with the value `v`. The operation can only be applied to a valarray instantiated on a type `T` that supports a unique form of the indicated function that returns `T` or a type convertible to `T`.

### Example

    //
    // valarray.cpp
    //
    #include "valarray.h" // Contains a valarray stream inserter
    using namespace std;
    int main(void)
    {
      int ibuf[10] = {0,1,2,3,4,5,6,7,8,9};
      int ibuf2[10] = {10,11,12,13,14,15,16,17,18,19};

      // create 2 valarrays of ints
      valarray<int>         vi(ibuf,10);
      valarray<int>         vi2(ibuf2,10);

      // print them out
      cout << vi << endl << vi2 << endl;

      vi += vi2;
      vi2 *= 2;
      valarry<int> vi3 = vi2 % vi;

      // print them out again
      cout << vi << endl << vi2 << endl << vi3 << endl;

      return 0;
    }

Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998