[Previous] [Contents] [Next]

<valarray>


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


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 described here as returning valarray<Ty> may actually return an object of some other type Other. In that case, any other function described here that accepts one or more arguments of type valarray<Ty> must have overloads that accept arbitrary combinations of those arguments, each replaced with an argument of type Other. (Put simply, the only way you can detect such a substitution is to go looking for it.)

namespace std {
class slice;
class gslice;

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

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

abs

template<class Ty>
    valarray<Ty> abs(const valarray<Ty>& left);

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

acos

template<class Ty>
    valarray<Ty> acos(const valarray<Ty>& left);

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

asin

template<class Ty>
    valarray<Ty> asin(const valarray<Ty>& left);

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

atan

template<class Ty>
    valarray<Ty> atan(const valarray<Ty>& left);

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

atan2

template<class Ty>
    valarray<Ty> atan2(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> atan2(const valarray<Ty> left, const Ty& right);
template<class Ty>
    valarray<Ty> atan2(const Ty& left, const valarray<Ty>& right);

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

cos

template<class Ty>
    valarray<Ty> cos(const valarray<Ty>& left);

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

cosh

template<class Ty>
    valarray<Ty> cosh(const valarray<Ty>& left);

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

exp

template<class Ty>
    valarray<Ty> exp(const valarray<Ty>& left);

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

gslice

class gslice {
public:
    gslice();
    gslice(size_t off,
        const valarray<size_t> lenarr,
        const valarray<size_t> incarr);
    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<Ty>. The stored values include:

The two vectors must have the same length.

gslice::gslice

gslice();
gslice(size_t off,
    const valarray<size_t> lenarr,
    const valarray<size_t> incarr);

The default constructor stores zero for the starting index, and zero-length vectors for the length and stride vectors. The second constructor stores off for the starting index, lenarr for the length vector, and incarr 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 Ty>
    class gslice_array {
public:
    typedef Ty value_type;
    void operator=(const valarray<Ty> right) const;
    void operator=(const Ty& right) const;
    void operator*=(const valarray<Ty> right) const;
    void operator/=(const valarray<Ty> right) const;
    void operator%=(const valarray<Ty> right) const;
    void operator+=(const valarray<Ty> right) const;
    void operator-=(const valarray<Ty> right) const;
    void operator^=(const valarray<Ty> right) const;
    void operator&=(const valarray<Ty> right) const;
    void operator|=(const valarray<Ty> right) const;
    void operator<<=(const valarray<Ty> right) const;
    void operator>>=(const valarray<Ty> right) 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 va of class valarray<Ty>, along with an object gs of class gslice which describes the sequence of elements to select from the valarray<Ty> object.

You construct a gslice_array<Ty> object only by writing an expression of the form va[gs]. The member functions of class gslice_array then behave like the corresponding function signatures defined for valarray<Ty>, 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 va is given by the mapping:

K = gs.start();
for (size_t I = 0; I < N; ++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);
// va[gslice(3, len, str)] selects elements with
//   indices 3, 5, 7, 10, 12, 14

indirect_array

template<class Ty>
    class indirect_array {
public:
    typedef Ty value_type;
    void operator=(const valarray<Ty> right) const;
    void operator=(const Ty& right) const;
    void operator*=(const valarray<Ty> right) const;
    void operator/=(const valarray<Ty> right) const;
    void operator%=(const valarray<Ty> right) const;
    void operator+=(const valarray<Ty> right) const;
    void operator-=(const valarray<Ty> right) const;
    void operator^=(const valarray<Ty> right) const;
    void operator&=(const valarray<Ty> right) const;
    void operator|=(const valarray<Ty> right) const;
    void operator<<=(const valarray<Ty> right) const;
    void operator>>=(const valarray<Ty> right) 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 va of class valarray<Ty>, along with an object xa of class valarray<size_t> which describes the sequence of elements to select from the valarray<Ty> object.

You construct an indirect_array<Ty> object only by writing an expression of the form va[xa]. The member functions of class indirect_array then behave like the corresponding function signatures defined for valarray<Ty>, 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 va. For example:

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

log

template<class Ty>
    valarray<Ty> log(const valarray<Ty>& left);

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

log10

template<class Ty>
    valarray<Ty> log10(const valarray<Ty>& left);

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

mask_array

template<class Ty>
    class mask_array {
public:
    typedef Ty value_type;
    void operator=(const valarray<Ty> right) const;
    void operator=(const Ty& right) const;
    void operator*=(const valarray<Ty> right) const;
    void operator/=(const valarray<Ty> right) const;
    void operator%=(const valarray<Ty> right) const;
    void operator+=(const valarray<Ty> right) const;
    void operator-=(const valarray<Ty> right) const;
    void operator^=(const valarray<Ty> right) const;
    void operator&=(const valarray<Ty> right) const;
    void operator|=(const valarray<Ty> right) const;
    void operator<<=(const valarray<Ty> right) const;
    void operator>>=(const valarray<Ty> right) 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 va of class valarray<Ty>, along with an object ba of class valarray<bool> which describes the sequence of elements to select from the valarray<Ty> object.

You construct a mask_array<Ty> object only by writing an expression of the form va[ba]. The member functions of class mask_array then behave like the corresponding function signatures defined for valarray<Ty>, 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 va[I] is element zero in the selected sequence. For example:

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

operator!=

template<class Ty>
    valarray<bool> operator!=(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<bool> operator!=(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<bool> operator!=(const Ty& left,
       const valarray<Ty>& right);

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

operator%

template<class Ty>
    valarray<Ty> operator%(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator%(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator%(const Ty& left,
        const valarray<Ty>& right);

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

operator&

template<class Ty>
    valarray<Ty> operator&(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator&(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator&(const Ty& left,
        const valarray<Ty>& right);

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

operator&&

template<class Ty>
    valarray<bool> operator&&(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<bool> operator&&(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<bool> operator&&(const Ty& left,
        const valarray<Ty>& right);

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

operator>

template<class Ty>
    valarray<bool> operator>(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<bool> operator>(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<bool> operator>(const Ty& left,
        const valarray<Ty>& right);

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

operator>>

template<class Ty>
    valarray<Ty> operator>>(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator>>(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator>>(const Ty& left,
        const valarray<Ty>& right);

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

operator>=

template<class Ty>
    valarray<bool> operator>=(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<bool> operator>=(const valarray<Ty> left, const Ty& right);
template<class Ty>
    valarray<bool> operator>=(const Ty& left, const valarray<Ty>& right);

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

operator<

template<class Ty>
    valarray<bool> operator<(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<bool> operator<(const valarray<Ty> left, const Ty& right);
template<class Ty>
    valarray<bool> operator<(const Ty& left, const valarray<Ty>& right);

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

operator<<

template<class Ty>
    valarray<Ty> operator<<(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator<<(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator<<(const Ty& left,
        const valarray<Ty>& right);

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

operator<=

template<class Ty>
    valarray<bool> operator<=(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<bool> operator<=(const valarray<Ty> left, const Ty& right);
template<class Ty>
    valarray<bool> operator<=(const Ty& left, const valarray<Ty>& right);

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

operator*

template<class Ty>
    valarray<Ty> operator*(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator*(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator*(const Ty& left,
        const valarray<Ty>& right);

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

operator+

template<class Ty>
    valarray<Ty> operator+(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator+(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator+(const Ty& left,
        const valarray<Ty>& right);

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

operator-

template<class Ty>
    valarray<Ty> operator-(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator-(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator-(const Ty& left,
        const valarray<Ty>& right);

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

operator/

template<class Ty>
    valarray<Ty> operator/(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator/(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator/(const Ty& left,
        const valarray<Ty>& right);

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

operator==

template<class Ty>
    valarray<bool> operator==(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<bool> operator==(const valarray<Ty> left, const Ty& right);
template<class Ty>
    valarray<bool> operator==(const Ty& left  const valarray<Ty>& right);

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

operator^

template<class Ty>
    valarray<Ty> operator^(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator^(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator^(const Ty& left,
        const valarray<Ty>& right);

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

operator|

template<class Ty>
    valarray<Ty> operator|(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> operator|(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<Ty> operator|(const Ty& left,
        const valarray<Ty>& right);

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

operator||

template<class Ty>
    valarray<bool> operator||(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<bool> operator||(const valarray<Ty> left,
        const Ty& right);
template<class Ty>
    valarray<bool> operator||(const Ty& left,
        const valarray<Ty>& right);

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

pow

template<class Ty>
    valarray<Ty> pow(const valarray<Ty>& left,
        const valarray<Ty>& right);
template<class Ty>
    valarray<Ty> pow(const valarray<Ty> left, const Ty& right);
template<class Ty>
    valarray<Ty> pow(const Ty& left, const valarray<Ty>& right);

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

sin

template<class Ty>
    valarray<Ty> sin(const valarray<Ty>& left);

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

sinh

template<class Ty>
    valarray<Ty> sinh(const valarray<Ty>& left);

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

slice

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<Ty>. 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 Ty>
    class slice_array {
public:
    typedef Ty value_type;
    void operator=(const valarray<Ty> right) const;
    void operator=(const Ty& right) const;
    void operator*=(const valarray<Ty> right) const;
    void operator/=(const valarray<Ty> right) const;
    void operator%=(const valarray<Ty> right) const;
    void operator+=(const valarray<Ty> right) const;
    void operator-=(const valarray<Ty> right) const;
    void operator^=(const valarray<Ty> right) const;
    void operator&=(const valarray<Ty> right) const;
    void operator|=(const valarray<Ty> right) const;
    void operator<<=(const valarray<Ty> right) const;
    void operator>>=(const valarray<Ty> right) 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 va of class valarray<Ty>, along with an object sl of class slice which describes the sequence of elements to select from the valarray<Ty> object.

You construct a slice_array<Ty> object only by writing an expression of the form va[sl]. The member functions of class slice_array then behave like the corresponding function signatures defined for valarray<Ty>, 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 va. For example:

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

sqrt

template<class Ty>
    valarray<Ty> sqrt(const valarray<Ty>& left);

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

tan

template<class Ty>
    valarray<Ty> tan(const valarray<Ty>& left);

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

tanh

template<class Ty>
    valarray<Ty> tanh(const valarray<Ty>& left);

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

valarray


apply · cshift · max · min · 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 Ty>
    class valarray {
public:
    typedef Ty value_type;

    valarray();
    explicit valarray(size_t count);
    valarray(const Ty& val, size_t count));
    valarray(const Ty *ptr, size_t count);
    valarray(const slice_array<Ty>& slicearr);
    valarray(const gslice_array<Ty>& gslicearr);
    valarray(const mask_array<Ty>& maskarr);
    valarray(const indirect_array<Ty>& indarr);

    valarray<Ty>& operator=(const valarray<Ty>& right);
    valarray<Ty>& operator=(const Ty& val);
    valarray<Ty>& operator=(const slice_array<Ty>& slicearr);
    valarray<Ty>& operator=(const gslice_array<Ty>& gslicearr);
    valarray<Ty>& operator=(const mask_array<Ty>& maskarr);
    valarray<Ty>& operator=(const indirect_array<Ty>& indarr);

    Ty& operator[](size_t off);
    slice_array<Ty> operator[](slice slicearr);
    gslice_array<Ty> operator[](const gslice& gslicearr);
    mask_array<Ty> operator[](const valarray<bool>& boolarr);
    indirect_array<Ty>
        operator[](const valarray<size_t>& indarr);

    Ty operator[](size_t off) const;
    valarray<Ty> operator[](slice slicearr) const;
    valarray<Ty> operator[](const gslice& gslicearr) const;
    valarray<Ty>
        operator[](const valarray<bool>& boolarr) const;
    valarray<Ty>
        operator[](const valarray<size_t>& indarr) const;

    valarray<Ty> operator+() const;
    valarray<Ty> operator-() const;
    valarray<Ty> operator~() const;
    valarray<bool> operator!() const;
    valarray<Ty>& operator*=(const valarray<Ty>& right);
    valarray<Ty>& operator*=(const Ty& right);
    valarray<Ty>& operator/=(const valarray<Ty>& right);
    valarray<Ty>& operator/=(const Ty& right);
    valarray<Ty>& operator%=(const valarray<Ty>& right);
    valarray<Ty>& operator%=(const Ty& right);
    valarray<Ty>& operator+=(const valarray<Ty>& right);
    valarray<Ty>& operator+=(const Ty& right);
    valarray<Ty>& operator-=(const valarray<Ty>& right);
    valarray<Ty>& operator-=(const Ty& right);
    valarray<Ty>& operator^=(const valarray<Ty>& right);
    valarray<Ty>& operator^=(const Ty& right);
    valarray<Ty>& operator&=(const valarray<Ty>& right);
    valarray<Ty>& operator&=(const Ty& right);
    valarray<Ty>& operator|=(const valarray<Ty>& right);
    valarray<Ty>& operator|=(const Ty& right);
    valarray<Ty>& operator<<=(const valarray<Ty>& right);
    valarray<Ty>& operator<<=(const Ty& right);
    valarray<Ty>& operator>>=(const valarray<Ty>& right);
    valarray<Ty>& operator>>=(const Ty& right);

    size_t size() const;
    Ty sum() const;
    Ty max() const;
    Ty min() const;
    valarray<Ty> shift(int count) const;
    valarray<Ty> cshift(int count) const;
    valarray<Ty> apply(Ty func(Ty)) const;
    valarray<Ty> apply(Ty func(const Ty&)) const;
    void resize(size_t newsize);
    void resize(size_t newsize, const Ty& val);
   };

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

An object of class Ty:

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 Ty may throw exceptions.

valarray::apply

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

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

valarray::cshift

valarray<Ty> cshift(int count) const;

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

valarray::max

Ty 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 Ty.

valarray::min

Ty 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 Ty.

valarray::operator!

valarray<bool> operator!() const;

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

valarray::operator%=

valarray<Ty>& operator%=(const valarray<Ty>& right);
valarray<Ty>& operator%=(const Ty& right);

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

valarray::operator&=

valarray<Ty>& operator&=(const valarray<Ty>& right);
valarray<Ty>& operator&=(const Ty& right);

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

valarray::operator>>=

valarray<Ty>& operator>>=(const valarray<Ty>& right);
valarray<Ty>& operator>>=(const Ty& right);

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

valarray::operator<<=

valarray<Ty>& operator<<=(const valarray<Ty>& right);
valarray<Ty>& operator<<=(const Ty& right);

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

valarray::operator*=

valarray<Ty>& operator*=(const valarray<Ty>& right);
valarray<Ty>& operator*=(const Ty& right);

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

valarray::operator+

valarray<Ty> operator+() const;

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

valarray::operator+=

valarray<Ty>& operator+=(const valarray<Ty>& right);
valarray<Ty>& operator+=(const Ty& right);

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

valarray::operator-

valarray<Ty> operator-() const;

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

valarray::operator-=

valarray<Ty>& operator-=(const valarray<Ty>& right);
valarray<Ty>& operator-=(const Ty& right);

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

valarray::operator/=

valarray<Ty>& operator/=(const valarray<Ty>& right);
valarray<Ty>& operator/=(const Ty& right);

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

valarray::operator=

valarray<Ty>& operator=(const valarray<Ty>& right);
    valarray<Ty>& operator=(const Ty& val);
valarray<Ty>& operator=(const slice_array<Ty>& slicearr);
valarray<Ty>& operator=(const gslice_array<Ty>& gslicearr);
valarray<Ty>& operator=(const mask_array<Ty>& maskarr);
valarray<Ty>& operator=(const indirect_array<Ty>& indarr);

The first member operator replaces the controlled sequence with a copy of the sequence controlled by right. The second member operator replaces each element of the controlled sequence with a copy of val. 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 implementation, however, the effect is merely to invalidate any pointers or references to elements in the controlled sequence.

valarray::operator[]

Ty& operator[](size_t off);
slice_array<Ty> operator[](slice slicearr);
gslice_array<Ty> operator[](const gslice& gslicearr);
mask_array<Ty> operator[](const valarray<bool>& boolarr);
indirect_array<Ty> operator[](const valarray<size_t>& indarr);

Ty operator[](size_t off) const;
valarray<Ty> operator[](slice slicearr) const;
valarray<Ty> operator[](const gslice& gslicearr) const;
valarray<Ty> operator[](const valarray<bool>& boolarr) const;
valarray<Ty> operator[](const valarray<size_t>& indarr) 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 off. 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 slicearr. 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 gslicearr. 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 boolarr. 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 indarr. 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 off. For example:

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

The seventh member operator returns an object of class valarray<Ty> containing those elements of the controlled sequence designated by slicearr. 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 gslicearr. 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 boolarr. 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 indarr. 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<Ty>& operator^=(const valarray<Ty>& right);
valarray<Ty>& operator^=(const Ty& right);

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

valarray::operator|=

valarray<Ty>& operator|=(const valarray<Ty>& right);
valarray<Ty>& operator|=(const Ty& right);

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

valarray::operator~

valarray<Ty> operator~() const;

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

valarray::resize

void resize(size_t newsize);
void resize(size_t newsize, const Ty& val);

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

valarray::shift

valarray<Ty> shift(int count) const;

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

valarray::size

size_t size() const;

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

valarray::sum

Ty 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 Ty.

valarray::valarray

valarray();
explicit valarray(size_t count);
valarray(const Ty& val, size_t count));
valarray(const Ty *ptr, size_t count);
valarray(const slice_array<Ty>& slicearr);
valarray(const gslice_array<Ty>& gslicearr);
valarray(const mask_array<Ty>& maskarr);
valarray(const indirect_array<Ty>& indarr);

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

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

valarray::value_type

typedef Ty value_type;

The type is a synonym for the template parameter Ty.

valarray<bool>

class valarray<bool>

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


See also the Table of Contents and the Index.

Copyright © 1994-2002 by P.J. Plauger. All rights reserved.

[Previous] [Contents] [Next]